2023-10-20 17:15:15 +02:00
|
|
|
BUILDDIR := ./build
|
2023-11-10 22:24:14 +01:00
|
|
|
TEST_SRCDIR := ./test
|
2023-10-20 17:15:15 +02:00
|
|
|
SRCDIR := ./src
|
|
|
|
CXX := g++
|
|
|
|
|
2023-11-10 22:24:14 +01:00
|
|
|
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-%)
|
|
|
|
|
|
|
|
|
2023-10-20 17:15:15 +02:00
|
|
|
# Linker flag
|
|
|
|
LD_CXXFLAGS =
|
|
|
|
|
|
|
|
# Compilation flag
|
2023-11-15 14:31:11 +01:00
|
|
|
CXXFLAGS = -Wall -Wextra -g -O0 -std=c++2a
|
2023-10-20 17:15:15 +02:00
|
|
|
# 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
|
|
|
|
|
2023-11-10 22:24:14 +01:00
|
|
|
$(BUILDDIR)/main: $(SRCDIR)/main.cpp $(OBJ)
|
2023-10-27 17:54:10 +02:00
|
|
|
$(CXX) $^ -o $@ $(CXXFLAGS) $(LD_CXXFLAGS)
|
2023-10-20 17:15:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp $(SRCDIR)/include/%.h
|
2023-10-27 17:54:10 +02:00
|
|
|
$(CXX) -c $< -o $@ $(CXXFLAGS)
|
2023-10-20 17:15:15 +02:00
|
|
|
|
|
|
|
|
2023-11-10 22:24:14 +01:00
|
|
|
#
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-20 17:15:15 +02:00
|
|
|
clean:
|
|
|
|
rm -rf $(BUILDDIR)/*
|