4 LIBS = sdl2 SDL2_image SDL2_ttf glew openal freealut zlib
6 PKGFLAGS := $(shell pkg-config --cflags $(LIBS))
7 PKGLIBS := $(shell pkg-config --libs $(LIBS))
8 TESTFLAGS := $(shell pkg-config --cflags cppunit)
9 TESTLIBS := $(shell pkg-config --libs cppunit)
12 CPPFLAGS += $(PKGFLAGS)
16 LDXXFLAGS += $(PKGLIBS)
19 PROFILE_FLAGS = -DNDEBUG -O1 -g3
20 RELEASE_FLAGS = -DNDEBUG -O2
21 TEST_FLAGS = -g -O2 -I./src $(TESTFLAGS)
25 DEBUG_DIR := build/debug
26 PROFILE_DIR := build/profile
27 RELEASE_DIR := build/release
28 TEST_DIR := build/test
29 DIR := $(RELEASE_DIR) $(DEBUG_DIR) $(PROFILE_DIR) $(TEST_DIR) build
32 ASSET_DEP := $(ASSET_DIR)/.git
34 LIB_SRC := $(wildcard $(SOURCE_DIR)/*/*.cpp)
35 BIN_SRC := $(wildcard $(SOURCE_DIR)/*.cpp)
36 SRC := $(LIB_SRC) $(BIN_SRC)
37 TEST_SRC := $(wildcard $(TEST_SRC_DIR)/*.cpp) $(wildcard $(TEST_SRC_DIR)/*/*.cpp)
38 RELEASE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(SRC))
39 DEBUG_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(SRC))
40 PROFILE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(SRC))
41 TEST_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cpp, $(TEST_DIR)/%.o, $(TEST_SRC)) $(patsubst $(SOURCE_DIR)/%.cpp, $(TEST_DIR)/src/%.o, $(LIB_SRC))
42 RELEASE_DEP := $(RELEASE_OBJ:.o=.d)
43 DEBUG_DEP := $(DEBUG_OBJ:.o=.d)
44 PROFILE_DEP := $(PROFILE_OBJ:.o=.d)
45 TEST_DEP := $(TEST_OBJ:.o=.d)
47 DEBUG_BIN := blank.debug
48 PROFILE_BIN := blank.profile
49 TEST_BIN := blank.test
50 OBJ := $(RELEASE_OBJ) $(DEBUG_OBJ) $(PROFILE_OBJ) $(TEST_OBJ)
51 DEP := $(RELEASE_DEP) $(DEBUG_DEP) $(PROFILE_DEP) $(TEST_DEP)
52 BIN := $(RELEASE_BIN) $(DEBUG_BIN) $(PROFILE_BIN) $(TEST_BIN)
54 release: $(RELEASE_BIN)
60 profile: $(PROFILE_BIN)
64 run: $(ASSET_DEP) blank
65 ./blank --save-path saves/
67 gdb: $(ASSET_DEP) blank.debug
70 cachegrind: $(ASSET_DEP) blank.profile
71 valgrind ./blank.profile --save-path saves/
73 callgrind: $(ASSET_DEP) blank.profile
74 valgrind --tool=callgrind \
75 --branch-sim=yes --cacheuse=yes --cache-sim=yes \
76 --collect-bus=yes --collect-systime=yes --collect-jumps=yes \
77 --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \
78 ./blank.profile -n 128 -t 16 --no-keyboard --no-mouse -d --no-vsync --save-path saves/
84 rm -df $(OBJ) $(DEP) $(DIR)
87 rm -f $(BIN) cachegrind.out.* callgrind.out.*
90 .PHONY: all release debug profile tests run gdb cachegrind callgrind test clean distclean
94 $(RELEASE_BIN): $(RELEASE_OBJ)
96 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(RELEASE_FLAGS) $^
98 $(DEBUG_BIN): $(DEBUG_OBJ)
100 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(DEBUG_FLAGS) $^
102 $(PROFILE_BIN): $(PROFILE_OBJ)
104 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(PROFILE_FLAGS) $^
106 $(TEST_BIN): $(TEST_OBJ)
108 @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(TESTLIBS) $(TEST_FLAGS) $^
110 $(ASSET_DEP): .git/$(shell git symbolic-ref HEAD)
111 @git submodule update --init >/dev/null
114 $(RELEASE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(RELEASE_DIR)
117 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
119 $(DEBUG_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(DEBUG_DIR)
122 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(DEBUG_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
124 $(PROFILE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(PROFILE_DIR)
127 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(PROFILE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
129 $(TEST_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(TEST_DIR)
132 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<
134 $(TEST_DIR)/src/%.o: $(SOURCE_DIR)/%.cpp | $(TEST_DIR)
137 @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $<