From: Daniel Karbach Date: Mon, 28 Jan 2019 15:49:52 +0000 (+0100) Subject: added Makefile X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;ds=inline;p=sdl-test8.git added Makefile --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc7d8bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.swp +/build/ +/sdl-test8 +/sdl-test8.debug +/sdl-test8.profile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..319cf7c --- /dev/null +++ b/Makefile @@ -0,0 +1,102 @@ +CXX = g++ --std=c++11 +LDXX = g++ + +LIBS = sdl SDL_gfx SDL_image SDL_ttf + +PKGFLAGS := $(shell pkg-config --cflags $(LIBS)) +PKGLIBS := $(shell pkg-config --libs $(LIBS)) + +CPPFLAGS ?= +CPPFLAGS += $(PKGFLAGS) +CXXFLAGS ?= +CXXFLAGS += -Wall +LDXXFLAGS ?= +LDXXFLAGS += $(PKGLIBS) + +DEBUG_FLAGS = -g3 -O0 +PROFILE_FLAGS = -DNDEBUG -O1 -g3 +RELEASE_FLAGS = -DNDEBUG -O2 + +SOURCE_DIR := src +DEBUG_DIR := build/debug +PROFILE_DIR := build/profile +RELEASE_DIR := build/release +DIR := $(RELEASE_DIR) $(DEBUG_DIR) $(PROFILE_DIR) build + +SRC := $(wildcard $(SOURCE_DIR)/*.cpp) $(wildcard $(SOURCE_DIR)/*/*.cpp) +RELEASE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(SRC)) +DEBUG_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(SRC)) +PROFILE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(SRC)) +RELEASE_DEP := $(RELEASE_OBJ:.o=.d) +DEBUG_DEP := $(DEBUG_OBJ:.o=.d) +PROFILE_DEP := $(PROFILE_OBJ:.o=.d) +RELEASE_BIN := sdl-test8 +DEBUG_BIN := sdl-test8.debug +PROFILE_BIN := sdl-test8.profile +OBJ := $(RELEASE_OBJ) $(DEBUG_OBJ) $(PROFILE_OBJ) +DEP := $(RELEASE_DEP) $(DEBUG_DEP) $(PROFILE_DEP) +BIN := $(RELEASE_BIN) $(DEBUG_BIN) $(PROFILE_BIN) + +release: $(RELEASE_BIN) + +all: $(BIN) + +debug: $(DEBUG_BIN) + +profile: $(PROFILE_BIN) + +run: sdl-test8 + ./sdl-test8 + +gdb: sdl-test8.debug + gdb ./sdl-test8.debug + +cachegrind: sdl-test8.profile + valgrind ./sdl-test8.profile + +callgrind: sdl-test8.profile + valgrind --tool=callgrind \ + --branch-sim=yes --cacheuse=yes --cache-sim=yes \ + --collect-bus=yes --collect-systime=yes --collect-jumps=yes \ + --dump-instr=yes --simulate-hwpref=yes --simulate-wb=yes \ + ./sdl-test8.profile + +clean: + rm -df $(OBJ) $(DEP) $(DIR) + +distclean: clean + rm -f $(BIN) cachegrind.out.* callgrind.out.* + +.PHONY: all release debug profile run gdb cachegrind callgrind clean distclean + +-include $(DEP) + +$(RELEASE_BIN): $(RELEASE_OBJ) + @echo link: $@ + @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(RELEASE_FLAGS) $^ + +$(DEBUG_BIN): $(DEBUG_OBJ) + @echo link: $@ + @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(DEBUG_FLAGS) $^ + +$(PROFILE_BIN): $(PROFILE_OBJ) + @echo link: $@ + @$(LDXX) -o $@ $(CXXFLAGS) $(LDXXFLAGS) $(PROFILE_FLAGS) $^ + +$(RELEASE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(RELEASE_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + +$(DEBUG_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(DEBUG_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(DEBUG_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + +$(PROFILE_DIR)/%.o: $(SOURCE_DIR)/%.cpp | $(PROFILE_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(PROFILE_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + +$(DIR): + @mkdir -p "$@"