-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
168 lines (142 loc) · 5.29 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
################################################################################
## COLORS ##
################################################################################
DEFAULT := \033[0;39m
GRAY := \033[0;90m
RED := \033[0;91m
GREEN := \033[0;92m
YELLOW := \033[0;93m
BLUE := \033[0;94m
MAGENTA := \033[0;95m
CYAN := \033[0;96m
WHITE := \033[0;97m
################################################################################
## WEBSERV ##
################################################################################
NAME := webserv
CXX := c++
RM := rm -rf
################################################################################
## DIRECTORIES ##
################################################################################
OBJ_DIR := obj
SRC_DIR := srcs
INC_DIR := include
vpath %.cpp $(SRC_DIR) $(SRC_DIR)/request_parser $(SRC_DIR)/configuration \
$(SRC_DIR)/utils $(SRC_DIR)/signals
vpath %.hpp $(INC_DIR) $(INC_DIR)/request_parser $(INC_DIR)/configuration \
$(INC_DIR)/utils $(INC_DIR)/signals
vpath %.o $(OBJ_DIR)
HEADERS := colors.hpp \
ServerInput.hpp \
utils.hpp \
ServerException.hpp \
ServerConfig.hpp \
ConfigValue.hpp \
ConfigParser.hpp \
utils.hpp \
Server.hpp \
HttpRequest.hpp \
Logger.hpp \
HttpException.hpp \
ServerEngine.hpp \
HttpResponse.hpp \
signals.hpp \
request_parser/RequestParser.hpp \
request_parser/FirstLineParser.hpp \
request_parser/HeaderParser.hpp \
request_parser/HttpHeaders.hpp \
request_parser/BodyParser.hpp \
request_parser/TokenValidator.hpp \
HttpMethodHandler.hpp \
HttpErrorHandler.hpp \
Client.hpp
SOURCE := main.cpp \
utils/Logger.cpp \
utils/ServerException.cpp \
utils/utils.cpp \
signals/signals.cpp \
signals/globals.cpp \
configuration/ServerInput.cpp \
configuration/ConfigParser.cpp \
configuration/ServerConfig.cpp \
configuration/ConfigValue.cpp \
Server.cpp \
HttpRequest.cpp \
request_parser/RequestParser.cpp \
request_parser/FirstLineParser.cpp \
request_parser/HeaderParser.cpp \
request_parser/HttpHeaders.cpp \
request_parser/BodyParser.cpp \
request_parser/TokenValidator.cpp \
HttpException.cpp \
ServerEngine.cpp \
HttpResponse.cpp \
HttpMethodHandler.cpp \
HttpErrorHandler.cpp \
Client.cpp
OBJECTS := $(addprefix $(OBJ_DIR)/, $(notdir $(SOURCE:.cpp=.o)))
################################################################################
## FLAGS ##
################################################################################
ifdef DEV
CXXFLAGS :=
else ifdef DEBUG
CXXFLAGS := -g3
else
CXXFLAGS := -Wall -Wextra -Werror -std=c++98 -Ofast
endif
ifeq ($(shell uname), Linux)
CXXFLAGS += -D LINUX
endif
INCLUDE := -I $(INC_DIR)
################################################################################
## PROGRESS_BAR ##
################################################################################
NUM_SRC_FILES := $(words $(SOURCE))
NUM_OBJ_FILES := $(words $(OBJECTS))
NUM_TO_COMPILE = $(shell expr $(NUM_SRC_FILES) - $(NUM_OBJ_FILES))
ifeq ($(shell test $(NUM_TO_COMPILE) -le 0; echo $$?), 0)
NUM_TO_COMPILE = $(NUM_SRC_FILES)
endif
COMPILED_FILES = 0
COMPILATION_PCT = $(shell expr 100 \* $(COMPILED_FILES) / $(NUM_TO_COMPILE))
################################################################################
## COMPILATION ##
################################################################################
all: $(NAME)
test: $(NAME)
@make $(T) -C tests -s
@make fclean -C tests -s
$(NAME): $(OBJECTS)
@printf "\n$(MAGENTA)[$(NAME)] $(DEFAULT)Linking "
@printf "($(BLUE)$(NAME)$(DEFAULT))..."
@$(CXX) $(CXXFLAGS) $^ -o $@
@printf "\r%100s\r$(MAGENTA)[$(NAME)] $(GREEN)Compilation OK "
@printf "🎉!$(DEFAULT)\n"
$(OBJ_DIR)/%.o: %.cpp $(HEADERS) | $(OBJ_DIR)
@$(eval COMPILED_FILES = $(shell expr $(COMPILED_FILES) + 1))
@printf "$(MAGENTA)\r%100s\r[$(NAME)] $(GREEN)[ %d/%d (%d%%) ]" \
"" $(COMPILED_FILES) $(NUM_TO_COMPILE) $(COMPILATION_PCT)
@printf " $(DEFAULT)Compiling ($(BLUE)$<$(DEFAULT))..."
@$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
$(OBJ_DIR):
@printf "$(MAGENTA)[$(NAME)] $(DEFAULT)Creating objects directory "
@printf "($(BLUE)$(OBJ_DIR)$(DEFAULT))..."
@mkdir -p $(OBJ_DIR)
@printf "\r%100s\r$(MAGENTA)[$(NAME)] $(DEFAULT)($(BLUE)$(OBJ_DIR)/$(DEFAULT)) "
@printf "Created successfully!\n"
clean:
@printf "$(MAGENTA)[$(NAME)] $(DEFAULT)Cleaning object files in "
@printf "($(RED)$(OBJ_DIR)$(DEFAULT))..."
@$(RM) $(OBJ_DIR)
@printf "\r%100s\r$(MAGENTA)[$(NAME)] $(YELLOW)Object files cleaning OK "
@printf "🧹🧹$(DEFAULT)\n"
fclean: clean
@printf "$(MAGENTA)[$(NAME)] $(DEFAULT)Cleaning up "
@printf "($(RED)$(NAME)$(DEFAULT))..."
@$(RM) $(NAME)
@printf "\r%100s\r$(MAGENTA)[$(NAME)] $(YELLOW)Full clean OK "
@printf "🧹🧹$(DEFAULT)\n"
re: fclean all
.PHONY: all clean fclean re