aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: c08daf54e6beefa7a80ae6ac8e9d8054eb3c72e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Compiler
CXX = g++

# Compiler flags
CXXFLAGS = -Wall -Wextra -Werror
CXXFLAGS += -Isrc -std=c++20 -Wno-unused-function

# Release flags
RELEASE_FLAGS = -O3 -lrt

# Debug flags
DEBUGFLAGS = -ggdb -O0

# Linking flags
LDFLAGS = -largon2

# Object files
OBJECTS := wg2sd.o
OBJECTS += main.o

# Source directory
SRC_DIR = src
TEST_DIR = test

TEST_FILES := $(wildcard $(TEST_DIR)/*.cpp)
TEST_TARGETS := $(patsubst $(TEST_DIR)/%.cpp, $(TEST_DIR)/%, $(TEST_FILES))

SRC_FILES := $(patsubst %.o,$(SRC_DIR)/%.cpp,$(OBJECTS))

# Object directory
OBJ_DIR = obj
DEBUG_OBJ_DIR = obj/debug

# Target executable
TARGET = wg2sd

# Build rules
all: CXXFLAGS += $(RELEASE_FLAGS)
all: targets

targets: $(TARGET)

tests: $(TEST_TARGETS)

debug: CXXFLAGS += $(DEBUGFLAGS)
debug: OBJ_DIR = $(DEBUG_OBJ_DIR)
debug: tests targets

$(TARGET): $(addprefix $(OBJ_DIR)/, $(OBJECTS))
	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
	$(CXX) $(CXXFLAGS) -c $< -o $@

$(TEST_DIR)/%: $(TEST_DIR)/%.cpp $(addprefix $(OBJ_DIR)/, wg2sd.o) | $(OBJ_DIR)
	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@

$(OBJ_DIR) $(DEBUG_OBJ_DIR):
	mkdir -p $@

# Clean rule
clean:
	rm -rf $(OBJ_DIR) $(DEBUG_OBJ_DIR) $(TARGET) $(TEST_TARGETS)

# Help rule
help:
	@echo "Available targets:"
	@echo "  all (default)   : Build the project"
	@echo "  release         : Build the project with release flags"
	@echo "  tests           : Build the tests"
	@echo "  debug           : Build the project and tests with debug flags"
	@echo "  clean           : Remove all build artifacts"
	@echo "  help            : Display this help message"