BUILDDIR := ./build TEST_SRCDIR := ./test SRCDIR := ./src CXX := g++ SRC := $(wildcard $(SRCDIR)/*.cpp) OBJ = $(filter-out $(BUILDDIR)/main.o, $(SRC:$(SRCDIR)/%.cpp=$(BUILDDIR)/%.o)) TESTS_SRC = $(wildcard $(TEST_SRCDIR)/*.cpp) TESTS_OBJ = $(TESTS_SRC:$(TEST_SRCDIR)/%.cpp=$(BUILDDIR)/test-%) # Linker flag LD_CXXFLAGS = # Compilation flag CXXFLAGS = -Wall -Wextra -g -O3 -std=c++2a # Remove warnings about unused variables, functions, ... # -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable # Compile with debug # -g # See memory leaks and Incorrect Read/Write # -fsanitize=address -lasan $(BUILDDIR)/main: $(SRCDIR)/main.cpp $(OBJ) $(CXX) $^ -o $@ $(CXXFLAGS) $(LD_CXXFLAGS) $(BUILDDIR)/%.o: $(SRCDIR)/%.cpp $(SRCDIR)/include/%.hpp $(CXX) -c $< -o $@ $(CXXFLAGS) # # Tests # # 1. Compile every test/*.cpp file # 2. Run every test/*.sh file # 3. Run every file compiled in (1.) run-tests: build-tests $(foreach file, $(wildcard $(TEST_SRCDIR)/*.sh), $(file);) @echo "$$(for file in build/test-*; do $$file || exit 1; done)" # Preparing tests is basically deleting every compiled file because maybe we "just changed a header" build-tests: prepare-tests $(TESTS_OBJ) prepare-tests: @rm -f $(BUILDDIR)/test-* $(BUILDDIR)/test-%: $(TEST_SRCDIR)/%.cpp $(OBJ) $(CXX) $^ -o $@ $(CXXFLAGS) $(LD_CXXFLAGS) clean: rm -rf $(BUILDDIR)/*