-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
210 lines (182 loc) · 6.93 KB
/
Copy pathMakefile
File metadata and controls
210 lines (182 loc) · 6.93 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
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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: irychkov <irychkov@student.hive.fi> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/08/09 20:53:27 by nlouis #+# #+# #
# Updated: 2025/08/19 15:24:47 by irychkov ### ########.fr #
# #
# **************************************************************************** #
# Compiler settings
CXX := c++
CXXFLAGS := -Wall -Wextra -Werror -I include -std=c++20 \
-O3 -DNDEBUG -flto -march=native
# We use -flto (link time optimization) for better performance.
# -O3 is for optimization, -DNDEBUG disables debug assertions.
# Executable output
NAME := webserv
BINDIR := bin
TARGET := $(BINDIR)/$(NAME)
# Object dir (deps live next to objects: .o + .d)
OBJDIR := objs
# Colors
GREEN := \033[0;32m
CYAN := \033[0;36m
YELLOW := \033[1;33m
RED := \033[0;31m
RESET := \033[0m
.DEFAULT_GOAL := all
SRCS_CONFIG := \
src/config/Config.cpp \
src/config/normalizeConfig.cpp \
src/config/validateConfig.cpp
SRCS_CONFIG_PARSER := \
src/config/parser/ConfigParseError.cpp \
src/config/parser/ConfigParser.cpp \
src/config/parser/directive_handler_table.cpp
SRCS_CONFIG_TOKENIZER := \
src/config/tokenizer/Tokenizer.cpp \
src/config/tokenizer/token.cpp
SRCS_CORE := \
src/core/Location.cpp \
src/core/Server.cpp \
src/core/main.cpp \
src/core/server_utils.cpp \
src/core/runWebserv.cpp
SRCS_HTTP := \
src/http/HttpRequest.cpp \
src/http/HttpRequestParser.cpp \
src/http/HttpResponse.cpp \
src/http/handleCgi.cpp \
src/http/methodsHandler/handleDelete.cpp \
src/http/methodsHandler/handleGet/generateAutoindex.cpp \
src/http/methodsHandler/handleGet/handleGet.cpp \
src/http/methodsHandler/handlePost/handleMultipartForm.cpp \
src/http/methodsHandler/handlePost/handlePost.cpp \
src/http/requestRouter.cpp \
src/http/responseBuilder.cpp
SRCS_NETWORK := \
src/network/SocketManager.cpp \
src/network/SocketManagerRequest.cpp \
src/network/SocketManagerResponse.cpp \
src/network/SocketManagerTimeouts.cpp \
src/network/SocketManagerUtils.cpp
SRCS_UTILS := \
src/utils/Logger.cpp \
src/utils/errorUtils.cpp \
src/utils/filesystemUtils.cpp \
src/utils/htmlUtils.cpp \
src/utils/printInfo.cpp \
src/utils/stringUtils.cpp \
src/utils/urlUtils.cpp
SRCS := \
$(SRCS_CONFIG) \
$(SRCS_CONFIG_PARSER) \
$(SRCS_CONFIG_TOKENIZER) \
$(SRCS_CORE) \
$(SRCS_HTTP) \
$(SRCS_NETWORK) \
$(SRCS_UTILS)
HEADERS := \
include/config/Config.hpp \
include/config/normalizeConfig.hpp \
include/config/parser/ConfigParseError.hpp \
include/config/parser/ConfigParser.hpp \
include/config/parser/directive_handler_table.hpp \
include/config/tokenizer/Tokenizer.hpp \
include/config/tokenizer/token.hpp \
include/config/validateConfig.hpp \
include/core/Location.hpp \
include/core/Server.hpp \
include/core/server_utils.hpp \
include/core/webserv.hpp \
include/http/HttpRequest.hpp \
include/http/HttpRequestParser.hpp \
include/http/HttpResponse.hpp \
include/http/Url.hpp \
include/http/handleCgi.hpp \
include/http/methodsHandler.hpp \
include/http/requestRouter.hpp \
include/http/responseBuilder.hpp \
include/network/SocketManager.hpp \
include/utils/Logger.hpp \
include/utils/errorUtils.hpp \
include/utils/filesystemUtils.hpp \
include/utils/htmlUtils.hpp \
include/utils/printInfo.hpp \
include/utils/stringUtils.hpp \
include/utils/urlUtils.hpp
# ---- Derived files -----------------------------------------------------------
# Map each .cpp in $(SRCS) to its corresponding .o in $(OBJDIR).
# Note: patsubst here does NOT perform any filesystem wildcard expansion
# it just does a string substitution on the fixed list in $(SRCS).
# This is safe and deterministic, unlike $(wildcard) or $(shell find ...).
OBJS := $(patsubst src/%.cpp,$(OBJDIR)/%.o,$(SRCS))
DEPS := $(OBJS:.o=.d)
# ---- Rules ------------------------------------------------------------------
all: $(TARGET)
$(TARGET): $(OBJS)
@mkdir -p $(BINDIR)
@$(CXX) $(CXXFLAGS) $^ -o $@
@echo "$(CYAN)🚀 Built executable:$(RESET) $(TARGET)"
$(OBJDIR)/%.o: src/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
@echo "$(GREEN)🛠️ Compiled:$(RESET) $<"
# Cleaning
clean:
@rm -rf $(OBJDIR)
@echo "$(YELLOW)🧹 Cleaned object and dependency files.$(RESET)"
fclean: clean
@rm -rf $(TARGET) $(BINDIR) build
@echo "$(YELLOW)🗑️ Completely removed executables, binaries, build/.$(RESET)"
re: fclean all
# Python test dependencies
install_test_deps:
@echo "$(CYAN)📦 Installing Python test dependencies...$(RESET)"
@python3 -m pip install --user --upgrade virtualenv
@python3 -m virtualenv .venv
@.venv/bin/pip install --upgrade pip
@.venv/bin/pip install -r requirements-test.txt
# Tests
test: all install_test_deps
@echo "$(CYAN)🧪 Launching web server in background...$(RESET)"
@./$(TARGET) ./test_webserv/tester/config/tester.conf & echo $$! > .webserv_test.pid
@sleep 1
@echo "$(CYAN)🧪 Running Python test suite...$(RESET)"
@.venv/bin/python run_test.py || { \
echo "$(RED)❌ Tests failed.$(RESET)"; \
kill `cat .webserv_test.pid` >/dev/null 2>&1 || true; \
rm -f .webserv_test.pid; \
exit 1; \
}
@echo "$(CYAN)🧹 Shutting down test server...$(RESET)"
@kill `cat .webserv_test.pid` >/dev/null 2>&1 || true
@rm -f .webserv_test.pid
@echo "$(GREEN)🏆 All tests passed successfully!$(RESET)"
# Formatting (explicit file lists; no find/globs)
format:
@echo "$(CYAN)🎨 Formatting source files...$(RESET)"
@clang-format -i $(SRCS) $(HEADERS)
# Help
help:
@echo "$(CYAN)📦 Build Targets:$(RESET)"
@echo " $(GREEN)make$(RESET) → Build the project 🚀"
@echo " $(GREEN)make re$(RESET) → Clean and rebuild everything 🔁"
@echo ""
@echo "$(CYAN)🧪 Test Targets:$(RESET)"
@echo " $(GREEN)make test$(RESET) → Build, install Python deps, run server + Python tests 🧪"
@echo ""
@echo "$(CYAN)🧹 Cleaning Targets:$(RESET)"
@echo " $(GREEN)make clean$(RESET) → Remove object and dependency files 🧹"
@echo " $(GREEN)make fclean$(RESET)→ Remove everything including binaries and build dirs 🗑️"
@echo ""
@echo "$(CYAN)🧹 Code Quality Targets:$(RESET)"
@echo " $(GREEN)make format$(RESET)→ Format all source files 🎨"
@echo ""
@echo "$(CYAN)📚 Other:$(RESET)"
@echo " $(GREEN)make help$(RESET) → Show this help message 📚"
.PHONY: all clean fclean re test format help install_test_deps
-include $(DEPS)