From: Daniel Karbach Date: Tue, 27 Nov 2018 16:39:26 +0000 (+0100) Subject: basic build system X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=9486c646a8fbf4b3a5d51286821b69544888f3a8;p=diana.git basic build system --- diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..71012b2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "assets"] + path = assets + url = https://git.localhorst.tv/repo/diana-assets.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..77acc64 --- /dev/null +++ b/Makefile @@ -0,0 +1,242 @@ +CXX = g++ --std=c++14 +LDXX = g++ +CPPCHECK = cppcheck -q --std=c++14 \ + --enable=warning,style,performance,portability,unusedFunction,missingInclude \ + --error-exitcode=1 + +LIBS = sdl2 SDL2_image SDL2_net SDL2_ttf glew openal freealut zlib + +PKGFLAGS := $(shell pkg-config --cflags $(LIBS)) +PKGLIBS := $(shell pkg-config --libs $(LIBS)) +TESTFLAGS := $(shell pkg-config --cflags gtest gtest_main) +TESTLIBS := $(shell pkg-config --libs gtest gtest_main) + +CPPFLAGS ?= +CPPFLAGS += $(PKGFLAGS) +CXXFLAGS ?= +CXXFLAGS += -Wall +#CXXFLAGS += -march=native +LDXXFLAGS ?= +LDXXFLAGS += $(PKGLIBS) + +# source +SOURCE_DIR := src +TEST_SRC_DIR := tst + +# build configurations +# cover: +# coverage reporting +# for use with gcov +# debug: +# unoptimized and maximally annotated +# for use with gdb +# profile: +# somewhat optimized and maximally annotated +# for use with valgrind +# release: +# optimized, without debugging instructions and minimally +# annotated (mainly for stack traces) +# for use with people +# tests: +# same flags as release, but with main replaced by cppunit +# test runner and tests (from tst dir) built in + +COVER_FLAGS = -g -O0 --coverage -I$(SOURCE_DIR) $(TESTFLAGS) +DEBUG_FLAGS = -g3 -O0 +PROFILE_FLAGS = -DNDEBUG -O1 -g3 -DDIANA_PROFILING +RELEASE_FLAGS = -DNDEBUG -O2 -g1 +TEST_FLAGS = -g -O2 -I$(SOURCE_DIR) $(TESTFLAGS) + +# destination +COVER_DIR := build/cover +DEBUG_DIR := build/debug +PROFILE_DIR := build/profile +RELEASE_DIR := build/release +TEST_DIR := build/test + +DIR := $(RELEASE_DIR) $(COVER_DIR) $(DEBUG_DIR) $(PROFILE_DIR) $(TEST_DIR) build + +ASSET_DIR := assets +ASSET_DEP := $(ASSET_DIR)/.git + +LIB_SRC := $(wildcard $(SOURCE_DIR)/*/*.cpp) +BIN_SRC := $(wildcard $(SOURCE_DIR)/*.cpp) +SRC := $(LIB_SRC) $(BIN_SRC) +TEST_SRC := $(wildcard $(TEST_SRC_DIR)/*.cpp) $(wildcard $(TEST_SRC_DIR)/*/*.cpp) + +COVER_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cpp, $(COVER_DIR)/%.o, $(TEST_SRC)) $(patsubst $(SOURCE_DIR)/%.cpp, $(COVER_DIR)/src/%.o, $(LIB_SRC)) +COVER_DEP := $(COVER_OBJ:.o=.d) +COVER_BIN := diana.cover + +DEBUG_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(SRC)) +DEBUG_LIB_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(DEBUG_DIR)/%.o, $(LIB_SRC)) +DEBUG_DEP := $(DEBUG_OBJ:.o=.d) +DEBUG_BIN := diana.debug + +PROFILE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(SRC)) +PROFILE_LIB_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(PROFILE_DIR)/%.o, $(LIB_SRC)) +PROFILE_DEP := $(PROFILE_OBJ:.o=.d) +PROFILE_BIN := diana.profile + +RELEASE_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(SRC)) +RELEASE_LIB_OBJ := $(patsubst $(SOURCE_DIR)/%.cpp, $(RELEASE_DIR)/%.o, $(LIB_SRC)) +RELEASE_DEP := $(RELEASE_OBJ:.o=.d) +RELEASE_BIN := diana + +TEST_OBJ := $(patsubst $(TEST_SRC_DIR)/%.cpp, $(TEST_DIR)/%.o, $(TEST_SRC)) $(patsubst $(SOURCE_DIR)/%.cpp, $(TEST_DIR)/src/%.o, $(LIB_SRC)) +TEST_DEP := $(TEST_OBJ:.o=.d) +TEST_BIN := diana.test + +OBJ := $(COVER_OBJ) $(DEBUG_OBJ) $(PROFILE_OBJ) $(RELEASE_OBJ) $(TEST_OBJ) +DEP := $(COVER_DEP) $(DEBUG_DEP) $(PROFILE_DEP) $(RELEASE_DEP) $(TEST_DEP) +BIN := $(COVER_BIN) $(DEBUG_BIN) $(PROFILE_BIN) $(RELEASE_BIN) $(TEST_BIN) + +release: $(RELEASE_BIN) + +info: + @echo "CXX: $(CXX)" + @echo "LDXX: $(LDXX)" + @echo + @echo "LIBS: $(LIBS)" + @echo + @echo "CPPFLAGS: $(CPPFLAGS)" + @echo "CXXFLAGS: $(CXXFLAGS)" + @echo "LDXXFLAGS: $(LDXXFLAGS)" + @echo "TESTFLAGS: $(TESTFLAGS)" + @echo "TESTLIBS: $(TESTLIBS)" + @echo + @-lsb_release -a + @git --version + @g++ --version + +all: $(BIN) + +cover: $(COVER_BIN) + +debug: $(DEBUG_BIN) + +profile: $(PROFILE_BIN) + +tests: $(TEST_BIN) + +run: $(ASSET_DEP) diana + ./diana + +gdb: $(ASSET_DEP) diana.debug + gdb ./diana.debug + +cachegrind: $(ASSET_DEP) diana.profile + valgrind ./diana.profile + +callgrind: $(ASSET_DEP) diana.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 \ + ./diana.profile + +test: diana.test $(ASSET_DEP) + @echo run: diana.test + @./diana.test + +headless-test: diana.test + @echo run: diana.test --headless + @./diana.test --headless + +coverage: diana.cover + @echo run: diana.cover + @./diana.cover + @echo run: diana.cover --headless + @./diana.cover --headless + +codecov: coverage + @echo run: codecov.io + @bash -c 'bash <(curl -s https://codecov.io/bash) -Z' + +lint: + @echo lint: source + @$(CPPCHECK) $(SOURCE_DIR) + @echo lint: tests + @$(CPPCHECK) -I $(SOURCE_DIR) $(TEST_SRC_DIR) + +clean: + rm -f $(OBJ) + rm -f $(DEP) + find build -type d -empty -delete + +distclean: clean + rm -f $(BIN) cachegrind.out.* callgrind.out.* + rm -Rf build client-saves saves + +.PHONY: all release cover debug profile tests run gdb cachegrind callgrind test headless-test coverage codecov lint clean distclean + +-include $(DEP) + + +$(COVER_BIN): $(COVER_OBJ) + @echo link: $@ + @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(TESTLIBS) $(COVER_FLAGS) + +$(COVER_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(COVER_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(COVER_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + +$(COVER_DIR)/src/%.o: $(SOURCE_DIR)/%.cpp | $(COVER_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(COVER_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + + +$(DEBUG_BIN): %.debug: $(DEBUG_DIR)/%.o $(DEBUG_LIB_OBJ) + @echo link: $@ + @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(DEBUG_FLAGS) + +$(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_BIN): %.profile: $(PROFILE_DIR)/%.o $(PROFILE_LIB_OBJ) + @echo link: $@ + @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(PROFILE_FLAGS) + +$(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"$@" $< + + +$(RELEASE_BIN): %: $(RELEASE_DIR)/%.o $(RELEASE_LIB_OBJ) + @echo link: $@ + @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(RELEASE_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"$@" $< + + +$(TEST_BIN): $(TEST_OBJ) + @echo link: $@ + @$(LDXX) $(CXXFLAGS) $^ -o $@ $(LDXXFLAGS) $(TESTLIBS) $(TEST_FLAGS) + +$(TEST_DIR)/%.o: $(TEST_SRC_DIR)/%.cpp | $(TEST_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + +$(TEST_DIR)/src/%.o: $(SOURCE_DIR)/%.cpp | $(TEST_DIR) + @mkdir -p "$(@D)" + @echo compile: $@ + @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(TEST_FLAGS) -o $@ -MMD -MP -MF"$(@:.o=.d)" -MT"$@" $< + + +$(ASSET_DEP): .git/$(shell git symbolic-ref HEAD 2>/dev/null || echo HEAD) + @echo fetch: assets + @git submodule update --init >/dev/null + @touch $@ + +$(DIR): + @mkdir -p "$@" diff --git a/assets b/assets new file mode 160000 index 0000000..d28da4d --- /dev/null +++ b/assets @@ -0,0 +1 @@ +Subproject commit d28da4da25b4dd414d579695292d0a9a84467e5c diff --git a/src/diana.cpp b/src/diana.cpp new file mode 100644 index 0000000..a553b51 --- /dev/null +++ b/src/diana.cpp @@ -0,0 +1,3 @@ +int main(int argc, char *argv[]) { + return 0; +}