blob: 1abde0be76cdf55898b4c0c72d64aaf7ab0868a8 (
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
ifeq ($(BINDIR),)
BINDIR := /sbin
endif
# Compiler
CXX = g++
# Compiler flags
CXXFLAGS = -Wall -Wextra -Werror
CXXFLAGS += -Isrc -std=c++20 -Wno-unused-function
# Release flags
RELEASE_CXXFLAGS = -O3
RELEASE_LDFLAGS = -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
CMD = wg2sd
# Build rules
all: CXXFLAGS += $(RELEASE_CXXFLAGS)
all: LDFLAGS += $(RELEASE_LDFLAGS)
all: targets
targets: $(CMD)
tests: $(TEST_TARGETS)
debug: CXXFLAGS += $(DEBUGFLAGS)
debug: OBJ_DIR = $(DEBUG_OBJ_DIR)
debug: tests targets
$(CMD): $(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 $@
install:
mkdir -p $(DESTDIR)$(PREFIX)$(BINDIR)/
install -m 755 $(CMD) $(DESTDIR)$(PREFIX)$(BINDIR)/
uninstall:
rm -rf $(DESTDIR)$(PREFIX)$(BINDIR)/$(CMD)
# Clean rule
clean:
rm -rf $(OBJ_DIR) $(DEBUG_OBJ_DIR) $(TARGET) $(TEST_TARGETS)
.PHONY: install uninstall all clean targets tests
# Help rule
help:
@echo "Available targets:"
@echo " all (default) : Build the project"
@echo " tests : Build the tests"
@echo " debug : Build the project and tests with debug flags"
@echo " clean : Remove all build artifacts"
@echo " install : install build executables"
@echo " uninstall : uninstall build executables"
@echo " help : Display this help message"
|