From dbc858465c2777febfb3dd51d1e30a69d3c4b926 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 31 Mar 2015 19:30:48 +0200 Subject: [PATCH 1/1] added makefile --- .gitignore | 4 +++ Makefile | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2f9378 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.swp +*.swo +build +sdl-test7* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2a37b3b --- /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-test7 +DEBUG_BIN := sdl-test7.debug +PROFILE_BIN := sdl-test7.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-test7 + ./sdl-test7 + +gdb: sdl-test7.debug + gdb ./sdl-test7.debug + +cachegrind: sdl-test7.profile + valgrind ./sdl-test7.profile + +callgrind: sdl-test7.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-test7.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 "$@" -- 2.39.2