-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
135 lines (107 loc) · 2.92 KB
/
Makefile
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Les avertissements ne sont pas inclus car normalement ils ont été vérifiés
# pendant le développement.
COMMON_CFLAGS = \
-pthread \
$(NULL)
PROD_CFLAGS = \
-O3 \
$(COMMON_CFLAGS) \
$(JSON_CFLAGS) \
$(NULL)
DEV_CFLAGS = \
-Wall \
-Wextra \
-std=c99 \
-pedantic \
-Werror \
-fsanitize=address,bounds,null,integer,undefined \
-g \
$(COMMON_CFLAGS) \
$(JSON_CFLAGS) \
$(NULL)
PROD_LDFLAGS = \
$(JSON_LDLAGS) \
$(NULL)
DEV_LDFLAGS = \
$(JSON_LDLAGS) \
$(NULL)
SRC = \
src/convert_name.c \
src/errors.c \
src/main.c \
src/parsing/dns_reader.c \
src/parsing/hashmap.c \
src/parsing/node.c \
src/parsing/parse_json.c \
src/serialization/dns_message.c \
src/server/ip_tools.c \
src/server/server.c \
$(NULL)
OBJS = $(SRC:src/%.c=build/$(MODE)/%.o)
DEPS = $(OBJS:.o=.d)
DIRS = $(dir $(OBJS))
MODE ?= PROD
BINARY = build/$(MODE)/dnsd
reverse = $(shell printf "%s\n" $(strip $1) | tac)
.PHONY: all
all: $(BINARY)
$(BINARY): $(OBJS) | build/$(MODE)
$(CC) $($(MODE)_CFLAGS) $($(MODE)_CPPFLAGS) $($(MODE)_LDFLAGS) $(TARGET_ARCH) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
build/:
mkdir "$@"
.PHONY: test
test: $(BINARY)
python3 tests/run_tests.py
.PHONY: clean
clean:
$(RM) $(OBJS) $(BINARY) MakefileConfig iwyu format tidy
ifeq ($(MODE),DEV)
$(RM) $(DEPS)
endif
rmdir $(call reverse, $(DIRS)) build/ 2>/dev/null || true
MakefileConfig: configure
./configure > "$@"
# Ignore the file as it serve of marker so find can skip old files.
# This script avoid us to generate a marker for each file and derivate a special
# marker
.PHONY: format
format:
@echo '===== Begin fomatting ====='
@if [ -e "$@" ]; \
then \
find src -newer "$@" \( -name '*.c' -o -name '*.h' \) \
-exec clang-format -i -style=file \{\} \+ -print; \
else \
find src \( -name '*.c' -o -name '*.h' \) \
-exec clang-format -i -style=file \{\} \+ -print; \
fi
@echo '===== End fomatting ====='
@touch "$@"
.PHONY: tidy
tidy: $(SRC)
clang-tidy --format-style=file --fix -header-filter=.* --quiet $?
touch tidy
iwyu: $(SRC)
for file in src/*/*.h $?; do include-what-you-use -Xiwyu \
--no_fwd_decls $($(MODE)_CPPFLAGS) $($(MODE)_CFLAGS) $$file; done > iwyu
.PHONY: install
install: all
sudo install -m 700 build/$(MODE)/dnsd /usr/bin/dnsd
sudo install -m 700 dnsd.service /usr/lib/systemd/system/dnsd.service
include MakefileConfig
-include $(DEPS)
.SECONDARY: $(DIRS)
.SECONDEXPANSION:
# here $$ $(VARIABLE) $(function) get expanded first
# then %
# then $$ $(VARIABLE) $(function) get expanded again thanks to SECONDEXPANSION
# this only apply in prerequisite lists defined after SECONDEXPANSION
# so please add rule before unless needed
build/DEV/%.o: DEV_CPPFLAGS += -MD -MT "$@" -MF "$(@:.o=.d)"
build/$(MODE)/%.o: src/%.c | $$(dir build/$(MODE)/%)
$(CC) $($(MODE)_CFLAGS) $($(MODE)_CPPFLAGS) $(TARGET_ARCH) -c $(OUTPUT_OPTION) $<
build/%.d:
# Spécial hack to support GNU Make 3.81
@:
build/%/: | $$(dir build/%)
mkdir "$@"