-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (148 loc) · 4.37 KB
/
Copy pathMakefile
File metadata and controls
177 lines (148 loc) · 4.37 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Use `make CONFIG=release` or `make CONFIG=debug` to switch between build
# configurations
CONFIG ?= debug
# Compiler settings
CXX = clang++
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
CPPFLAGS = -Isrc -Ithird_party/utest -MMD -MP
# Build specific options
ifeq ($(CONFIG),debug)
CXXFLAGS += -g3 -fsanitize=address,undefined
CPPFLAGS += -DDEBUG
else ifeq ($(CONFIG),release)
CXXFLAGS += -O2
CPPFLAGS += -DNDEBUG
endif
# Targets
target = build/$(CONFIG)/bin/webserv
test_target = build/$(CONFIG)/bin/run_tests
# Main sources (keep in alphabetical order)
srcs = \
src/config/config_builder.cpp \
src/config/config_builder.hpp \
src/config/config_parser.cpp \
src/config/config_parser.hpp \
src/config/config_tokenizer.cpp \
src/config/config_tokenizer.hpp \
src/config/server_config.cpp \
src/config/server_config.hpp \
src/core/client.cpp \
src/core/client.hpp \
src/core/server.cpp \
src/core/server.hpp \
src/core/server_defaults.hpp \
src/core/signals.cpp \
src/core/signals.hpp \
src/core/virtual_server.cpp \
src/core/virtual_server.hpp \
src/handler/cgi_handler.cpp \
src/handler/cgi_handler.hpp \
src/handler/delete_handler.cpp \
src/handler/delete_handler.hpp \
src/handler/error_handler.cpp \
src/handler/error_handler.hpp \
src/handler/handler.cpp \
src/handler/handler.hpp \
src/handler/redirect_handler.cpp \
src/handler/redirect_handler.hpp \
src/handler/static_file_handler.cpp \
src/handler/static_file_handler.hpp \
src/handler/upload_handler.cpp \
src/handler/upload_handler.hpp \
src/http/http_parser.cpp \
src/http/http_parser.hpp \
src/http/http_request.cpp \
src/http/http_request.hpp \
src/http/http_response.cpp \
src/http/http_response.hpp \
src/http/http_version.cpp \
src/http/http_version.hpp \
src/main.cpp \
src/router/router.cpp \
src/router/router.hpp \
src/util/itoa.cpp \
src/util/log_message.cpp \
src/util/log_message.hpp \
src/util/str_split.cpp \
src/util/str_trim.cpp \
src/util/string.hpp \
src/util/syscall_error.cpp \
src/util/syscall_error.hpp \
src/util/to_string.cpp \
src/util/to_string.hpp \
cpps = $(filter %.cpp,$(srcs))
hpps = $(filter %.hpp,$(srcs))
objs = $(patsubst src/%.cpp,build/$(CONFIG)/obj/%.o,$(cpps))
deps = $(objs:.o=.d)
# Test sources (keep in alphabetical order)
test_srcs = \
tests/config_tokenizer_unittest.cpp \
tests/config_parser_unittest.cpp \
tests/cgi_handler_unittest.cpp \
tests/delete_handler_unittest.cpp \
tests/upload_handler_unittest.cpp \
tests/error_handler_unittest.cpp \
tests/http_parser_unittest.cpp \
tests/http_response_unittest.cpp \
tests/router_unittest.cpp \
tests/server_config_unittest.cpp \
tests/static_file_handler_unittest.cpp \
tests/redirect_handler_unittest.cpp \
tests/str_split_unittest.cpp \
tests/main.cpp \
test_cpps = $(filter %.cpp,$(test_srcs))
test_objs = $(patsubst tests/%.cpp,build/$(CONFIG)/obj_tests/%.o,$(test_cpps))
test_deps = $(test_objs:.o=.d)
all_cpps = $(cpps) $(test_cpps)
all_hpps = $(hpps)
all_deps = $(deps) $(test_deps)
# Build main target
PHONY += all run
all: $(target)
run: all
./$(target)
$(target): $(objs)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(objs) -o $@
build/$(CONFIG)/obj/%.o: src/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
# Build test target
PHONY += test
test: $(test_target)
@echo "Running unit tests..."
./$(test_target)
test_cgi: $(test_target)
@echo "Running unit tests..."
./$(test_target) --filter=CgiHandler*
$(test_target): $(test_objs) $(filter-out build/$(CONFIG)/obj/main.o,$(objs))
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $^ -o $@
build/$(CONFIG)/obj_tests/%.o: tests/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
# Cleanup rules
PHONY += clean fclean re
clean:
rm -rf build/$(CONFIG)
fclean: clean
rm -rf build
re: fclean all
# Formatting and linting rules
PHONY += db format lint check
db:
compiledb -n $(MAKE)
format:
clang-format --style=file --dry-run --Werror $(all_cpps) $(all_hpps)
format-fix:
clang-format --style=file -i $(all_cpps) $(all_hpps)
lint: db
clang-tidy -p=. --header-filter=src/ --warnings-as-errors=* $(all_cpps)
# Rule used by GitHub CI
check: format lint test
# Header hygiene
PHONY += headers-check
headers-check: db
clang-tidy -p=. --header-filter=src/ --checks=misc-include-cleaner $(all_cpps)
-include $(all_deps)
.PHONY: $(PHONY)