CXX := g++ CXXFLAGS := -Wall -Wextra -std=c++11 -O2 -isystem /usr/local/include -I. LIBS := -lfltk -L/usr/local/lib BIN := game object_src := $(wildcard src/objects/*.cpp) object_obj := $(patsubst src/objects/%.cpp,build/objects/%.o,$(object_src)) object_head := $(patsubst src/objects/%.cpp,build/objects/%.h,$(object_src)) object_xlist := $(shell echo $$(for f in $(object_src); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/X(&)/'; done)) base_src := $(wildcard *_base.cpp) base_src += library.cpp main.cpp base_obj := $(patsubst %.cpp,build/%.o,$(base_src)) .PHONY: all clean remake #keep all intermediate files! .SECONDARY: all: $(BIN) clean: rm -rf build $(BIN) remake: clean all $(BIN): $(base_obj) $(object_obj) $(CXX) $(CXXFLAGS) $(LIBS) -o $(BIN) $^ build/main.o: main.cpp build/objects.h @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c -o "$@" "$<" "-DOBJECT_CLASSES_XLIST=$(object_xlist)" "-DGAME_NAME=\"$(BIN)\"" build/objects/%.o: build/objects/%.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c -o "$@" $^ build/objects/%.cpp: src/objects/%.cpp @mkdir -p $(dir $@) $(CXX) -E object_wrapper.cpp "-D__OBJECT_FNAME__=\"$<\"" "-D__OBJECT_NAME__=$(basename $(notdir $<))" | sed 's/^# [0-9]\+ ".*//' >"$@" build/objects/%.h: src/objects/%.cpp @mkdir -p $(dir $@) $(CXX) -E object_header_maker.cpp "-D__OBJECT_NAME__=$(basename $(notdir $<))" "-DEVENT_XLIST=$$($(CXX) -E object_header_extractor.cpp "-D__OBJECT_FNAME__=\"$<\"" | sed 's/__________EVENT_NEWLINE__________/\n/g' | grep -oe '__________EVENT_COUNTER_TAG_[^_]*__________' | sed 's/[^G]*G_\(.*\)__________.*/X(\1)/g' | xargs)" | sed 's/^# [0-9]\+ ".*//' >"$@" build/objects.h: $(object_head) echo $(object_head) | xargs -n 1 basename | sed 's,.*,#include "objects/&",' >"$@" build/%.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -c -o "$@" $^