TARGET=debug CFLAGS= LFLAGS= COMPILE=g++ -c LINK=g++ ########################## # # makes debug by default # To specify release, for example, try # make TARGET=release # # ########################## # generic flags generic_CFLAGS=-Wall generic_LFLAGS=-Wall # debug build debug_CFLAGS=-g -D_DEBUG debug_LFLAGS=-g # release build release_CFLAGS=-DNDEBUG release_LFLAGS= # figure out build-specific flags target_CFLAGS=$($(TARGET)_CFLAGS) $(generic_CFLAGS) target_LFLAGS=$($(TARGET)_LFLAGS) $(generic_LFLAGS) # all .cpp files (or .C files) CPPFILES=bitstreams.cpp HuffmanHeap.cpp StaticHuffman.cpp StaticHuffman_Levels.cpp StaticHuffman_StoreWeights.cpp StaticHuffmanMain.cpp # include files that pretty much everything includes. # FOR LAZINESS, just put every include file, so we don't have to worry about the dependencies too much COMMON_INCLUDE_FILES=bitstreams.h HuffmanHeap.h StaticHuffman.h StaticHuffman_Levels.h StaticHuffman_StoreWeights.h # extra dependencies (too lazy for this) # StaticHuffman_StoreWeights.cpp : StaticHuffman_StoreWeights.h # automatically inferred stuff CPP_O_FILES=$(CPPFILES:%.cpp=$(TARGET)/%.o) OBJS=$(CPP_O_FILES) EXE=$(TARGET)/huffman TARGET_DIR_CREATED_FLAG=$(TARGET)/directory_created_dummy_file all : $(EXE) $(CPP_O_FILES) : $(COMMON_INCLUDE_FILES) $(EXE) : $(OBJS) $(LINK) -o $(EXE) $(target_LFLAGS) $(LFLAGS) $(OBJS) $(TARGET)/%.o : %.cpp $(TARGET_DIR_CREATED_FLAG) $(COMPILE) $(target_CFLAGS) $(CFLAGS) -o $@ $< $(TARGET_DIR_CREATED_FLAG) : mkdir $(TARGET) echo "Do not delete this file" >$(TARGET_DIR_CREATED_FLAG) clean: rm -r $(TARGET) dump_vars : echo "CPPFILES" echo $(CPPFILES) echo "COMMON_INCLUDE_FILES" echo $(COMMON_INCLUDE_FILES) echo "CPP_O_FILES" echo $(CPP_O_FILES) echo "EXE" echo $(EXE)