# Compiler Options
CXX           = %{cc}
LIB_OPT       = %{lib_opt}
CHECK_OPT     = %{check_opt}
MACH_OPT      = %{mach_opt}
LANG_FLAGS    = %{lang_flags}
WARN_FLAGS    = %{warn_flags}
SO_OBJ_FLAGS  = %{shared_flags}
LIB_LINK_CMD  = %{so_link}
LINK_TO       = %{link_to}

# Version Numbers
VERSION       = %{version}

# Installation Settings
DESTDIR       = %{prefix}

# Aliases for Common Programs
AR            = %{ar_command}
CD            = @cd
ECHO          = @echo
INSTALL       = %{install_cmd_exec}
INSTALL_CMD   = %{install_cmd_exec}
MKDIR         = @md
MKDIR_INSTALL = @md
RM            = @del /Q
RMDIR         = @rmdir

# File Lists
CHECK         = check

DOCS          = %{doc_files}

HEADERS       = %{include_files}

LIBOBJS       = %{lib_objs}

CHECKOBJS     = %{check_objs}

LIB_FLAGS     = $(LIB_OPT) $(MACH_OPT) $(LANG_FLAGS) $(WARN_FLAGS) $(SO_OBJ_FLAGS)
CHECK_FLAGS   = $(CHECK_OPT) $(LANG_FLAGS) $(WARN_FLAGS)

LIBRARIES     = $(STATIC_LIB)

LIBNAME       = botan
STATIC_LIB    = $(LIBNAME).%{static_suffix}

all: $(LIBRARIES)

# Build Commands
%{lib_build_cmds}

%{check_build_cmds}

# Link Commands

# Link for Borland?
#ilink32 -L$(BCB)\lib -w -c -x -Gn -ap -Tpe c0x32.obj \
#    $(CHECKOBJS),check.exe,,$(LINK_TO) $(STATIC_LIB)

$(CHECK): $(LIBRARIES) $(CHECKOBJS)
	$(CXX) /Fe$@ $(CHECKOBJS) $(STATIC_LIB) $(LINK_TO)

$(STATIC_LIB): $(LIBOBJS)
!If "$(SO_OBJ_FLAGS)" == ""
        $(AR) /OUT:$(LIBNAME).lib $(LIBOBJS)
!Else
        $(LIB_LINK_CMD) /Fe$(LIBNAME) $(LIBOBJS) $(LINK_TO)
!Endif

# Misc Targets
static: $(STATIC_LIB)

# Fake Targets
clean:
	$(RM) %{build_dir}\lib\* %{build_dir}\checks\*
	$(RM) $(LIBRARIES) $(CHECK).exe

distclean: clean
	$(RM) %{build_dir}\build.h
	$(RM) %{build_dir}\botan.doxy
	$(RM) %{build_dir}\botan.iss
	$(RM) %{build_dir}\include\botan\*
	$(RMDIR) %{build_dir}\include\botan %{build_dir}\include
	$(RMDIR) %{build_dir}\lib %{build_dir}\checks
	$(RMDIR) %{build_dir}
	$(RM) Makefile

# Install Commands
install: $(LIBRARIES)
	-$(MKDIR) $(DESTDIR)\include\botan
	$(INSTALL_CMD) botan.* $(DESTDIR)
	$(INSTALL_CMD) build\include\botan\*.h $(DESTDIR)\include\botan
