# The MagicMakefile by Jeff Koftinoff <jeffk@jdkoftinoff.com>
#
# this Makefile compiles everything (c++) in $(LIB_SRC_DIR) and puts it in the library in $(OUTPUT_LIB), using header dependancies
#
# test programs are everything in $(LIB_TESTS_DIR)/*.cpp and they are single file .cpp test programs that are compiled and linked
# with the library into this build directory.
#
# the source files are  scanned dynamically with the magic of $(wildcard )
#
# You must set the following make vars:
#   TOP
#   PROJECT
#   CXXFLAGS
#   LDLIBS
#   OUTPUT_LIB
#   LIB_SRC_DIR
#   LIB_TESTS_DIR


# Some cygwin installations like using .exe explicitly
#EXE=.exe 
EXE=

# some systems need ranlib
RANLIB=ranlib

# tell gnumake where to find out sources
VPATH=$(TOP)/src:$(TOP)/tests

# tell gnumake how to use g++ to output header dependency information

CXXFLAGS += -MMD 


# get the list of library source files from the ../src directory
LIB_CPP_FILES=$(notdir $(wildcard $(LIB_SRC_DIR)/*.cpp))

# get the list of test program source files from the ../tests directory
LIB_TEST_CPP_FILES=$(notdir $(wildcard $(LIB_TESTS_DIR)/*.cpp))

# manipulate these file lists to create our desired output files in the proper place
LIB_O_FILES=$(LIB_CPP_FILES:.cpp=.o)
LIB_TEST_O_FILES=$(LIB_TEST_CPP_FILES:.cpp=.o)
LIB_TEST_EXE_FILES=$(LIB_TEST_CPP_FILES:.cpp=$(EXE))


all : $(OUTPUT_LIB)


clean :
	-$(RM) *.o
	-$(RM) $(LIB_TEST_EXE_FILES)
	-$(RM) *.d


distclean : clean
	-$(RM) $(OUTPUT_LIB)
	-$(RM) $(TOP)/docs/html/*
	find .. -name "*~" -print0 | xargs -0 rm

$(OUTPUT_LIB) : $(OUTPUT_LIB)( $(LIB_O_FILES) )
	$(RANLIB) $(OUTPUT_LIB)

tests: $(LIB_TEST_EXE_FILES)

$(LIB_TEST_EXE_FILES) : $(OUTPUT_LIB)

docs :
	( cd $(TOP)/docs && doxygen $(PROJECT).doxy )

# include any dependencies created during the last make.
-include *.d







