-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
192 lines (134 loc) · 4.1 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: 개포동블루벨벳 +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/06/12 18:05:34 by 개포동블루벨벳 #+# #+# #
# Updated: 2023/06/12 19:42:55 by 개포동블루벨벳 ### ########.fr #
# #
# **************************************************************************** #
# ---- NAME ---- #
NAME = webserv
CC = c++
STD = -std=c++98
CFLAGS = -Wall -Wextra -Werror $(STD) $(INCLUDE)
DBGS = -fsanitize=address -g3
RM = rm -rf
OBJ_DIR = ./objects
SRCS_DIR = ./srcs
# ---- INCLUDE ---- #
INCLUDE_DIRS = $(shell find $(SRCS_DIR) -type d -name "include")
INCLUDE = $(patsubst %, -I %, $(INCLUDE_DIRS))
# ---- TEST ---- #
EXEC = webserv
TEST = test
# ---- escape ---- #
DELINE = \033[K
CURSUP = \033[A
RESET = \033[0m
RESTINT = \033[22m
BOLD = \033[1m
MAGENTA = \033[35m
GREEN = \033[32m
RED = \033[31m
# ---- Mandatory ---- #
sources1 := main.cpp
# ---- Utils ---- #
sources1 += FileChecker.cpp \
Reader.cpp \
Utils.cpp \
Status.cpp \
Logger.cpp
# ---- Network ---- #
sources1 += Client.cpp
sources1 += ServerManager.cpp \
Server.cpp \
Kqueue.cpp \
EventHandler.cpp
# ---- HTTP ---- #
sources1 += Request.cpp \
RequestParser.cpp \
Response.cpp \
CandidateFields.cpp
# ---- Method ---- #
sources1 += GET.cpp \
POST.cpp \
DELETE.cpp \
PUT.cpp \
HEAD.cpp \
OPTIONS.cpp
# ---- CGI ---- #
sources1 += CGI.cpp
# ---- Config ---- #
sources1 += Config.cpp \
ConfigParser.cpp \
RootConfig.cpp \
ProxyConfig.cpp \
MimeTypesConfig.cpp \
ServerConfig.cpp \
LocationConfig.cpp
# ---- Exception ---- #
sources1 += ExceptionThrower.cpp
# ---- Bonus ---- #
sources1 += Session.cpp \
SessionData.cpp
# ---- SRC ---- #
SRCS = $(shell for name in $(sources1); do find $(SRCS_DIR) -name $$name; done)
SRCSS = $(patsubst ./%,%,$(SRCS))
SRCS_BONUS = $(shell for name in $(sources2); do find $(SRCS_DIR) -name $$name; done)
SRCS_BONUS := $(patsubst ./%,%,$(SRCS_BONUS))
# ---- Elements ---- #
all_sources = $(sources1) $(sources2)
objects1 = $(SRCSS:.cpp=.o)
objects2 = $(SRCS_BONUS:.cpp=.o)
all_objects = $(objects1) $(objects2)
define objects_goal
$(addprefix $(OBJ_DIR)/, $(call $(if $(filter bonus, $(MAKECMDGOALS)), objects2, objects1)))
endef
define react
$(if $(filter bonus, $(MAKECMDGOALS)), bonus, all)
endef
# ---- Command ---- #
.PHONY : all bonus clean fclean re test
all : $(NAME)
$(NAME) : $(objects_goal)
@$(CC) $(CFLAGS) -o $(NAME) $(objects_goal)
@echo "$(DELINE) $(MAGENTA)$@ $(RESET) is compiled $(GREEN)$(BOLD) OK ✅ $(RESET)"
bonus : $(NAME)
$(OBJ_DIR)/%.o : %.cpp
@mkdir -p $(OBJ_DIR)/$(dir $^)
@$(CC) $(CFLAGS) -c $^ -o $@
@echo " $(MAGENTA)$(NAME) $(RESET)objects file compiling... $(DELINE)$(GREEN) $^ $(RESET)$(CURSUP)"
clean :
@$(RM) $(all_objects)
@rm -rf $(OBJ_DIR)
@echo "$(RED) Delete$(BOLD) objects $(RESTINT)file $(RESET)"
fclean : clean
@$(RM) $(NAME)
@$(RM) $(TEST)
@echo "$(RED) Delete$(BOLD) $(NAME) $(RESTINT)file $(RESET)"
re : fclean
@make $(react)
# ---- Test ---- #
leaks: export MallocStackLogging=1
leaks: CFLAGS += -D LEAKS -g3
leaks: fclean all
./$(EXEC)
leaks: export MallocStackLogging=0
dbg: CFLAGS += -fsanitize=address -g3 -D DEBUG_MSG
dbg: fclean all
./$(EXEC)
dbg!: CFLAGS += -fsanitize=address -g3 -D DEBUG_MSG
dbg!: all
./$(EXEC)
# test: CFLAGS += -D PORT=8080
test: all
./$(EXEC)
# test1: CFLAGS += -D PORT=8081
test1: fclean all
./$(EXEC)
# test2: CFLAGS += -D PORT=8082
test2: fclean all
./$(EXEC)