forked from mrjvs/42-webserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
289 lines (264 loc) · 7.49 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
# Constants
NAME = not-apache
NAME := $(addprefix ./build/,$(NAME))
# Compiler
CC = clang
CXX = clang++
CC_FLAGS = -Wall -Werror -Wextra -std=c99 -pedantic-errors
CXX_FLAGS = -Wall -Werror -Wextra -std=c++98 -pedantic-errors
DEBUG_FLAGS =
BUILD_FLAGS = -O3 -pthread
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
ifeq ($(CC),gcc)
CC_FLAGS += -fPIE
endif
ifeq ($(CXX),g++)
CXX_FLAGS += -fPIE
endif
CC_FLAGS += -DBUILD_LINUX=1
CXX_FLAGS += -DBUILD_LINUX=1
else ifeq ($(UNAME_S),Darwin)
CC_FLAGS += -DBUILD_APPLE=1
CXX_FLAGS += -DBUILD_APPLE=1
endif
ifdef BUILD_DEBUG
DEBUG_FLAGS = -g -fsanitize=address -DDEBUG_THROW=1
BUILD_FLAGS = -pthread
endif
ifdef BUILD_LEAK
DEBUG_FLAGS = -g -fsanitize=leak -DDEBUG_THROW=1
BUILD_FLAGS = -pthread
endif
# Files
SRC_DIR = src
BUILD_DIR = build
OUT_DIR = build/out
INC_DIR = src/_includes
SRC =\
main.cpp\
log/Loggable.cpp\
log/Logger.cpp\
log/LogItem.cpp\
plugins/PageGenerator.cpp\
plugins/JsonStatAPI.cpp\
plugins/JsExecutor.cpp\
plugins/BrainfuckExecutor.cpp\
plugins/Plugin.cpp\
plugins/ReplaceText.cpp\
regex/Regex.cpp\
config/ConfigValidatorBuilder.cpp\
config/ConfigParser.cpp\
config/ConfigLine.cpp\
config/ConfigException.cpp\
config/AConfigValidator.cpp\
config/AConfigBlock.cpp\
config/blocks/RootBlock.cpp\
config/blocks/RouteBlock.cpp\
config/blocks/ServerBlock.cpp\
config/validators/ArgumentLength.cpp\
config/validators/RegexCompiler.cpp\
config/validators/FileNameValidator.cpp\
config/validators/StartsWithValidator.cpp\
config/validators/PluginValidator.cpp\
config/validators/UrlValidator.cpp\
config/validators/UploadValidator.cpp\
config/validators/DomainNameValidator.cpp\
config/validators/ErrorCodeValidator.cpp\
config/validators/RequiredKey.cpp\
config/validators/IntValidator.cpp\
config/validators/IsDirectory.cpp\
config/validators/IsFile.cpp\
config/validators/HTTPMethodValidator.cpp\
config/validators/IpValidator.cpp\
config/validators/MutuallyExclusive.cpp\
config/validators/BooleanValidator.cpp\
config/validators/Unique.cpp\
env/env.cpp\
env/ENVBuilder.cpp\
utils/AThread.cpp\
utils/intToString.cpp\
utils/size_tToString.cpp\
utils/isSpace.cpp\
utils/mutex.cpp\
utils/split.cpp\
utils/atoi.cpp\
utils/stoi.cpp\
utils/toUpper.cpp\
utils/stoh.cpp\
utils/isDigit.cpp\
utils/stringIsDouble.cpp\
utils/countSpaces.cpp\
utils/strdup.cpp\
utils/DataList.cpp\
utils/Uri.cpp\
utils/ArgParser.cpp\
utils/base64.cpp\
libs/duktape/duktape.c\
server/handlers/AHandler.cpp\
server/handlers/StandardHandler.cpp\
server/handlers/HandlerHolder.cpp\
server/handlers/ThreadHandler.cpp\
server/communication/TCPListener.cpp\
server/communication/ServerEventBus.cpp\
server/http/HTTPClient.cpp\
server/http/HTTPClientData.cpp\
server/http/HTTPParser.cpp\
server/http/HTTPParseData.cpp\
server/http/HTTPResponder.cpp\
server/http/Proxy.cpp\
server/http/CGIClass.cpp\
server/http/HTTPMimeTypes.cpp\
server/http/RequestBuilder.cpp\
server/http/ResponseBuilder.cpp\
server/http/JsonBuilder.cpp\
server/responder/associatedFds.cpp\
server/responder/cgi.cpp\
server/responder/embeddedJS.cpp\
server/responder/embeddedBrainfuck.cpp\
server/responder/handleError.cpp\
server/responder/proxy.cpp\
server/responder/serving.cpp\
server/responder/unlink.cpp\
server/responder/upload.cpp\
server/terminal/TerminalClient.cpp\
server/terminal/TerminalResponder.cpp\
server/globals.cpp\
server/Server.cpp
HEADERS =\
log/Loggable.hpp\
log/Logger.hpp\
log/LogItem.hpp\
plugins/PageGenerator.hpp\
plugins/JsonStatAPI.hpp\
plugins/JsExecutor.hpp\
plugins/BrainfuckExecutor.hpp\
plugins/Plugin.hpp\
plugins/ReplaceText.hpp\
regex/Regex.hpp\
config/ConfigValidatorBuilder.hpp\
config/ConfigParser.hpp\
config/ConfigLine.hpp\
config/ConfigException.hpp\
config/AConfigValidator.hpp\
config/AConfigBlock.hpp\
config/blocks/RootBlock.hpp\
config/blocks/RouteBlock.hpp\
config/blocks/ServerBlock.hpp\
config/validators/ArgumentLength.hpp\
config/validators/RegexCompiler.hpp\
config/validators/FileNameValidator.hpp\
config/validators/StartsWithValidator.hpp\
config/validators/PluginValidator.hpp\
config/validators/UrlValidator.hpp\
config/validators/UploadValidator.hpp\
config/validators/DomainNameValidator.hpp\
config/validators/ErrorCodeValidator.hpp\
config/validators/RequiredKey.hpp\
config/validators/IntValidator.hpp\
config/validators/MutuallyExclusive.hpp\
config/validators/BooleanValidator.hpp\
config/validators/IsDirectory.hpp\
config/validators/IsFile.hpp\
config/validators/HTTPMethodValidator.hpp\
config/validators/IpValidator.hpp\
config/validators/Unique.hpp\
config/ParseExceptions.hpp\
env/env.hpp\
env/ENVBuilder.hpp\
utils/AThread.hpp\
utils/split.hpp\
utils/atoi.hpp\
utils/toUpper.hpp\
utils/stoi.hpp\
utils/stoh.hpp\
utils/isDigit.hpp\
utils/stringIsDouble.hpp\
utils/countSpaces.hpp\
utils/CreateMap.hpp\
utils/CreateVector.hpp\
utils/ErrorThrow.hpp\
utils/intToString.hpp\
utils/size_tToString.hpp\
utils/isSpace.hpp\
utils/localTime.hpp\
utils/mutex.hpp\
utils/strdup.hpp\
utils/DataList.hpp\
utils/Uri.hpp\
utils/ArgParser.hpp\
utils/base64.hpp\
../libs/duktape/duktape.h\
server/handlers/AHandler.hpp\
server/handlers/StandardHandler.hpp\
server/handlers/HandlerHolder.hpp\
server/handlers/ThreadHandler.hpp\
server/communication/TCPListener.hpp\
server/communication/ServerEventBus.hpp\
server/http/HTTPClient.hpp\
server/http/HTTPClientData.hpp\
server/http/HTTPParser.hpp\
server/http/HTTPParseData.hpp\
server/http/HTTPResponder.hpp\
server/http/Proxy.hpp\
server/http/CGIClass.hpp\
server/http/HTTPMimeTypes.hpp\
server/http/RequestBuilder.hpp\
server/http/ResponseBuilder.hpp\
server/http/JsonBuilder.hpp\
server/terminal/TerminalClient.hpp\
server/terminal/TerminalResponder.hpp\
server/global/GlobalConfig.hpp\
server/global/GlobalLogger.hpp\
server/global/GlobalPlugins.hpp\
server/ServerTypes.hpp\
server/Server.hpp
# Fix sources and headers
OBJ = $(patsubst %,%.o,$(SRC))
HEADERS := $(addprefix $(INC_DIR)/,$(HEADERS))
# Colours
DARK_GREEN = \033[0;32m
GREEN = \033[0;92m
END = \033[0;0m
PREFIX = $(DARK_GREEN)$(notdir $(NAME)) $(END)>>
# Rules
.PHONY: all clean fclean re exec valgrind debug rdebug leak rleak
all: $(NAME)
deps:
@echo "$(SRC)"
$(NAME): $(addprefix $(OUT_DIR)/,$(OBJ))
@echo "$(PREFIX)$(GREEN) Bundling objects...$(END)"
@echo "BUILD $(NAME) $(CXX_FLAGS) $(DEBUG_FLAGS) $(BUILD_FLAGS)"
@$(CXX) $(CXX_FLAGS) $(DEBUG_FLAGS) $(BUILD_FLAGS) -I$(INC_DIR) -o $@ $(addprefix $(OUT_DIR)/,$(OBJ))
$(OUT_DIR)/%.c.o: $(SRC_DIR)/%.c $(HEADERS)
@echo "$(PREFIX)$(GREEN) Compiling file $(END)$(notdir $<) $(GREEN)to $(END)$(notdir $@)"
@mkdir -p $(dir $@)
@$(CC) $(CC_FLAGS) $(DEBUG_FLAGS) -I$(INC_DIR) -o $@ -c $<
$(OUT_DIR)/%.cpp.o: $(SRC_DIR)/%.cpp $(HEADERS)
@echo "$(PREFIX)$(GREEN) Compiling file $(END)$(notdir $<) $(GREEN)to $(END)$(notdir $@)"
@mkdir -p $(dir $@)
@$(CXX) $(CXX_FLAGS) $(DEBUG_FLAGS) -I$(SRC_DIR) -I$(INC_DIR) -o $@ -c $<
clean:
@echo "$(PREFIX)$(GREEN) Removing directory $(END)$(OUT_DIR)"
@rm -rf $(OUT_DIR)
fclean: clean
@echo "$(PREFIX)$(GREEN) Removing file $(END)$(NAME)"
@rm -f $(NAME)
re:
$(MAKE) fclean
$(MAKE) all
exec:
$(MAKE) all
cd build && ./not-apache -f ../tests/provided/test.conf -c
valgrind:
cd build && valgrind --undef-value-errors=no --leak-check=full ./not-apache -f ../tests/provided/test.conf -c
debug:
$(MAKE) BUILD_DEBUG=1 all
rdebug:
$(MAKE) fclean
$(MAKE) debug
leak:
$(MAKE) BUILD_LEAK=1 all
rleak:
$(MAKE) fclean
$(MAKE) leak