# # Makefile.inc # (C) Copyright 2017 # John Ryland # # Description: # Simple boilerplate of a makefile where what # you need to provide is TARGET, SOURCES and FLAGS # Header file dependancies are automatically calculated # I have a more complex version of this which handles # sub-directories and sub-projects, but this is the very # simple version which is reasonably self-explainetary. # # Example usage: # TARGET = MyApp # SOURCE = myapp.cpp classA.cpp classB.cpp # FLAGS = -I. # -include Makefile.inc # OBJECTS = $(patsubst %.cpp, build/.objs/%.o, $(SOURCES)) DEPENDS = $(patsubst build/.objs/%.o, build/.deps/%.cpp.d, $(OBJECTS)) all: build/$(TARGET) $(ADDITIONAL_DEPS) clean: rm -rf build build/.deps/%.cpp.d: %.cpp @mkdir -p build/.deps c++ $(CFLAGS) -MT $(patsubst %.cpp, build/.objs/%.o, $<) -MD -E $< -MF $@ > /dev/null build/.objs/%.o: %.cpp build/.deps/%.cpp.d @mkdir -p build/.objs c++ $(CFLAGS) -c $< -o $@ build/$(TARGET): $(OBJECTS) $(DEPENDS) c++ $(LFLAGS) $(OBJECTS) -o $@ strip -S $@ .PHONY: all clean -include $(DEPENDS)