1- # Compiler settings
2- CXX = clang++
3- CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -g3
4- CPPFLAGS = -MMD -MP
5-
61# Executable name
72NAME = webserv
83
@@ -16,25 +11,33 @@ BIN_DIR = $(BUILD_DIR)/bin
1611TARGET = $(BIN_DIR ) /$(NAME )
1712
1813# Source tree (keep in alphabetical order)
19- SRCS = src/Client.cpp \
20- src/Client.hpp \
21- src/HttpResponse.cpp \
22- src/HttpResponse.hpp \
23- src/main.cpp \
24- src/Server.cpp \
25- src/Server.hpp \
26- src/SyscallError.cpp \
27- src/SyscallError.hpp
14+ SRCS = $(addprefix $(SRC_DIR ) /, \
15+ core/Client.cpp \
16+ core/Client.hpp \
17+ core/Server.cpp \
18+ core/Server.hpp \
19+ http/HttpResponse.cpp \
20+ http/HttpResponse.hpp \
21+ util/SyscallError.cpp \
22+ util/SyscallError.hpp \
23+ main.cpp \
24+ )
2825
2926# Separate .cpp and .hpp files
30- CPPS = $(filter % .cpp,$(SRCS ) )
31- HPPS = $(filter % .hpp,$(SRCS ) )
27+ CPPS = $(filter % .cpp,$(SRCS ) )
28+ HPPS = $(filter % .hpp,$(SRCS ) )
3229
3330# Objects and dependencies
34- OBJS = $(patsubst src/% ,build/obj/% ,$(CPPS:.cpp=.o ) )
35- DEPS = $(OBJS:.o=.d )
31+ OBJS = $(patsubst $(SRC_DIR ) /% ,$(OBJ_DIR ) /% ,$(CPPS:.cpp=.o ) )
32+ DEPS = $(OBJS:.o=.d )
33+
34+ # Compiler settings
35+ CXX = clang++
36+ CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -g3
37+ CPPFLAGS = -I$(SRC_DIR ) -MMD -MP
3638
37- .PHONY : all run val
39+ # Default target
40+ PHONY += all run val
3841all : $(TARGET )
3942
4043run : all
@@ -51,11 +54,8 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
5154 @mkdir -p $(dir $@ )
5255 $(CXX ) $(CXXFLAGS ) $(CPPFLAGS ) -c -o $@ $<
5356
54- -include $(DEPS )
55-
5657# Regular cleaning targets
57-
58- .PHONY : clean fclean re
58+ PHONY += clean fclean re
5959clean :
6060 rm -rf $(OBJ_DIR )
6161
@@ -69,8 +69,7 @@ re: fclean all
6969# If compiledb is not installed do `pipx install compiledb`.
7070# compiledb is used to generate the compilation database (compile_commands.json)
7171# used by clang-tidy.
72-
73- .PHONY : db format lint check
72+ PHONY += db format lint check
7473db :
7574 compiledb -n $(MAKE )
7675
@@ -84,12 +83,16 @@ check: format lint
8483
8584# Careful, these targets will overwrite files.
8685# Make sure to use `make check` before committing irreversible changes.
87-
88- .PHONY : format-fix lint-fix fix
86+ PHONY += format-fix lint-fix fix
8987format-fix :
9088 clang-format -style=file -i $(CPPS ) $(HPPS )
9189
9290lint-fix : db
9391 clang-tidy -p=. --header-filter=.* -fix $(CPPS )
9492
9593fix : format-fix lint-fix
94+
95+ # Include dependencies
96+ -include $(DEPS )
97+
98+ .PHONY : $(PHONY )
0 commit comments