-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
311 lines (258 loc) · 8.52 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# **************************************************************************** #
# VARS #
# **************************************************************************** #
# COLORS
NOCOL = \033[0m
RED = \033[31m
GRN = \033[32m
YEL = \033[33m
BLU = \033[34m
MAG = \033[35m
CYN = \033[36m
LBLU = \033[36m
LGRN = \033[0;90m
# OS
UNAME_S := $(shell uname -s)
# **************************************************************************** #
# PROGRAM #
# **************************************************************************** #
NAME = webserv
BIN_DIR ?= /usr/local/bin
RM = rm -rf
MKDIR = mkdir -p
# **************************************************************************** #
# COMPILER #
# **************************************************************************** #
MAKE = make
CXX = g++
CXXFLAGS += -std=c++98 -Wno-c++0x-compat
CXXFLAGS += -MMD
# warning flags
WFLAGS := -Wall -Wextra -Werror -Wpedantic -Wshadow
CXXFLAGS += $(WFLAGS)
# extended warning flags
# some of this warnings are enabled in -Wall or -Wextra
# but I like to explicitly put the ones that are related either way
LINUX_EWFLAGS := -Wuninitialized -Wmaybe-uninitialized \
-Wdouble-promotion \
-Wformat -Wformat-overflow -Wformat-truncation -Wformat-security \
-Wnull-dereference \
-Winit-self \
-Wmissing-include-dirs \
-Wunused \
-Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wmissing-noreturn -Wsuggest-attribute=malloc \
-Wsuggest-attribute=format -Wmissing-format-attribute -Wsuggest-attribute=cold \
-Walloc-zero \
-Warray-bounds \
-Wbool-compare -Wbool-operation \
-Wduplicated-branches -Wduplicated-cond \
-Wcast-qual -Wcast-align \
-Wparentheses -Wdangling-else \
-Wconversion -Wfloat-conversion -Wsign-conversion -Wsign-compare \
-Waddress \
-Wlogical-op -Wlogical-not-parentheses \
-Wmissing-field-initializers \
-Wredundant-decls \
-Winline \
-Wvla
OSX_EWFLAGS := -Wuninitialized \
-Wdouble-promotion \
-Wformat -Wformat-security \
-Wnull-dereference \
-Winit-self \
-Wmissing-include-dirs \
-Wunused \
-Warray-bounds \
-Wcast-qual -Wcast-align \
-Wparentheses -Wdangling-else \
-Wconversion -Wfloat-conversion -Wsign-conversion -Wsign-compare \
-Waddress \
-Wlogical-not-parentheses \
-Wmissing-field-initializers \
-Wredundant-decls \
-Winline \
-Wvla
LINUX_SFLAGS := -fsanitize=address \
-fsanitize=pointer-compare \
-fsanitize=pointer-subtract \
-fsanitize=leak \
-fsanitize=undefined \
-fsanitize=shift \
-fsanitize=shift-exponent \
-fsanitize=shift-base \
-fsanitize=integer-divide-by-zero \
-fsanitize=vla-bound \
-fsanitize=null \
-fsanitize=return \
-fsanitize=signed-integer-overflow \
-fsanitize=bounds \
-fsanitize=bounds-strict \
-fsanitize=alignment \
-fsanitize=object-size \
-fsanitize=float-divide-by-zero \
-fsanitize=float-cast-overflow \
-fsanitize=nonnull-attribute \
-fsanitize=returns-nonnull-attribute \
-fsanitize=bool \
-fsanitize=enum \
-fsanitize=vptr \
-fsanitize=pointer-overflow \
-fsanitize=builtin
OSX_SFLAGS := -fsanitize=address \
-fsanitize=pointer-compare \
-fsanitize=pointer-subtract \
-fsanitize=undefined \
-fsanitize=shift \
-fsanitize=shift-exponent \
-fsanitize=shift-base \
-fsanitize=integer-divide-by-zero \
-fsanitize=vla-bound \
-fsanitize=null \
-fsanitize=return \
-fsanitize=signed-integer-overflow \
-fsanitize=bounds \
-fsanitize=alignment \
-fsanitize=float-divide-by-zero \
-fsanitize=float-cast-overflow \
-fsanitize=nonnull-attribute \
-fsanitize=returns-nonnull-attribute \
-fsanitize=bool \
-fsanitize=enum \
-fsanitize=vptr \
-fsanitize=pointer-overflow \
-fsanitize=builtin
# **************************************************************************** #
# PATHS #
# **************************************************************************** #
SRC_PATH = src
OBJ_PATH = obj
INC_PATH = include
LIB_PATH = lib
# **************************************************************************** #
# FLAGS #
# **************************************************************************** #
CXXFLAGS += -I ./$(INC_PATH)
CXXFLAGS += -I ./$(SRC_PATH)
# **************************************************************************** #
# LIBS #
# **************************************************************************** #
CXXFLAGS += -I ./$(LIB_PATH)/nstd/include
# **************************************************************************** #
# OS #
# **************************************************************************** #
ifeq ($(UNAME_S),Linux)
CXXFLAGS += -D LINUX
endif
ifeq ($(UNAME_S),Darwin)
CXXFLAGS += -D OSX
endif
# **************************************************************************** #
# SOURCES #
# **************************************************************************** #
SRC_DIR_CONFIG = config
SRC_DIR_SERVER = server
SRC_DIR_REQUEST = request
SRC_DIR_RESPONSE = response
SRC_DIR_CGI = cgi
SRC_DIR_UTILS = utils
OBJ_DIRS_NAME = $(SRC_DIR_CONFIG) $(SRC_DIR_SERVER) $(SRC_DIR_REQUEST) \
$(SRC_DIR_RESPONSE) $(SRC_DIR_CGI) $(SRC_DIR_UTILS)
OBJ_DIRS = $(addprefix $(OBJ_PATH)/, $(OBJ_DIRS_NAME))
SRC_ROOT = main.cc
SRC_CONFIG = constants.cc config.cc server_config.cc
SRC_SERVER = server.cc client.cc
SRC_REQUEST = request.cc request_data.cc
SRC_RESPONSE = response.cc response_data.cc
SRC_CGI = cgi.cc
SRC_UTILS = utils.cc signals.cc
SRC_NAME = $(SRC_ROOT) \
$(addprefix $(SRC_DIR_CONFIG)/, $(SRC_CONFIG)) \
$(addprefix $(SRC_DIR_SERVER)/, $(SRC_SERVER)) \
$(addprefix $(SRC_DIR_REQUEST)/, $(SRC_REQUEST)) \
$(addprefix $(SRC_DIR_RESPONSE)/, $(SRC_RESPONSE)) \
$(addprefix $(SRC_DIR_CGI)/, $(SRC_CGI)) \
$(addprefix $(SRC_DIR_UTILS)/, $(SRC_UTILS))
OBJ_NAME = $(SRC_NAME:%.cc=%.o)
DEP_NAME = $(SRC_NAME:%.cc=%.d)
SRC = $(addprefix $(SRC_PATH)/, $(SRC_NAME))
OBJ = $(addprefix $(OBJ_PATH)/, $(OBJ_NAME))
DEP = $(addprefix $(OBJ_PATH)/, $(DEP_NAME))
# **************************************************************************** #
# RULES #
# **************************************************************************** #
PHONY := all
all: $(NAME)
$(NAME): $(OBJ)
@printf "\n${YEL}LINKING:${NOCOL}\n"
@printf "${BLU}"
$(CXX) $(LDFLAGS) $^ -o $@
@printf "${NOCOL}"
@printf "\n${GRN}SUCCESS!${NOCOL}\n"
@printf "${CYN}type \"./${NAME}\" to start!${NOCOL}\n"
PHONY += debug
ifeq ($(UNAME_S),Linux)
debug: CXXFLAGS += $(LINUX_EWFLAGS)
endif
ifeq ($(UNAME_S),Darwin)
debug: CXXFLAGS += $(OSX_EWFLAGS)
endif
debug: $(NAME)
PHONY += install
install: $(NAME)
install $(NAME) $(BIN_DIR)
PHONY += sanitize
sanitize: CXXFLAGS += -g3
ifeq ($(UNAME_S),Linux)
sanitize: CXXFLAGS += $(LINUX_SFLAGS)
sanitize: LDFLAGS += $(LINUX_SFLAGS)
endif
ifeq ($(UNAME_S),Darwin)
sanitize: CXXFLAGS += $(OSX_SFLAGS)
sanitize: LDFLAGS += $(OSX_SFLAGS)
endif
sanitize: debug
PHONY += valgrind
valgrind: CXXFLAGS += -ggdb3
valgrind: debug
PHONY += thread
thread: CXXFLAGS += -g3
thread: LDFLAGS += -fsanitize=thread
thread: debug
# OBJ
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.cc | $(OBJ_PATH) $(OBJ_DIRS)
@printf "${BLU}"
$(CXX) $(CXXFLAGS) -c $< -o $@
@printf "${NOCOL}"
# OBJ DIRS
$(OBJ_DIRS): | $(OBJ_PATH)
@printf "${MAG}"
$(MKDIR) $(OBJ_DIRS)
@printf "${NOCOL}"
$(OBJ_PATH):
@printf "${MAG}"
$(MKDIR) $(OBJ_PATH)
@printf "${NOCOL}"
PHONY += clean
clean:
@printf "${RED}"
$(RM) $(OBJ_PATH)
@printf "${NOCOL}"
PHONY += fclean
fclean: clean
@printf "${RED}"
$(RM) $(NAME)
@printf "${NOCOL}"
PHONY += re
re: fclean all
# RUN
PHONY += run
ifeq ($(UNAME_S),Darwin)
export ASAN_OPTIONS = detect_leaks=1
endif
run: CONF ?= ./conf/all.conf
run: $(NAME)
@printf "\n${YEL}RUNNING...${NOCOL}\n"
./$(NAME) $(CONF)
@printf "\n${GRN}SUCCESS!${NOCOL}\n"
-include $(DEP)
.PHONY: $(PHONY)