|
1 | | -NAME = webserv |
| 1 | +# Compiler settings |
| 2 | +CXX = clang++ |
| 3 | +CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -g3 |
| 4 | +CPPFLAGS = -MMD -MP |
| 5 | + |
| 6 | +# Executable name |
| 7 | +NAME = webserv |
| 8 | + |
| 9 | +# Directories |
| 10 | +SRC_DIR = src |
| 11 | +BUILD_DIR = build |
| 12 | +OBJ_DIR = $(BUILD_DIR)/obj |
| 13 | +BIN_DIR = $(BUILD_DIR)/bin |
| 14 | + |
| 15 | +# Main target |
| 16 | +TARGET = $(BIN_DIR)/$(NAME) |
| 17 | + |
| 18 | +# 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 |
| 28 | + |
| 29 | +# Separate .cpp and .hpp files |
| 30 | +CPPS = $(filter %.cpp,$(SRCS)) |
| 31 | +HPPS = $(filter %.hpp,$(SRCS)) |
| 32 | + |
| 33 | +# Objects and dependencies |
| 34 | +OBJS = $(patsubst src/%,build/obj/%,$(CPPS:.cpp=.o)) |
| 35 | +DEPS = $(OBJS:.o=.d) |
2 | 36 |
|
3 | | -CXX = clang++ |
4 | | -CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -g3 |
5 | | -# CPPFLAGS are for C pre-processor flags (different from CXXFLAGS) |
6 | | -CPPFLAGS = -MMD -MP |
| 37 | +.PHONY: all run val |
| 38 | +all: $(TARGET) |
7 | 39 |
|
8 | | -SRCS = main.cpp Server.cpp Client.cpp HttpResponse.cpp SyscallError.cpp |
9 | | -HDRS = Server.hpp Client.hpp HttpResponse.hpp SyscallError.hpp structs_dev.hpp |
| 40 | +run: all |
| 41 | + ./$(TARGET) |
10 | 42 |
|
11 | | -OBJS = $(SRCS:.cpp=.o) |
12 | | -DEPS = $(OBJS:.o=.d) |
| 43 | +val: all |
| 44 | + valgrind ./$(TARGET) |
13 | 45 |
|
14 | | -.PHONY: all clean fclean re val db format format-fix lint lint-fix check fix |
| 46 | +$(TARGET): $(OBJS) |
| 47 | + @mkdir -p $(dir $@) |
| 48 | + $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJS) -o $@ |
15 | 49 |
|
16 | | -all: $(NAME) |
| 50 | +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp |
| 51 | + @mkdir -p $(dir $@) |
| 52 | + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< |
17 | 53 |
|
18 | | -$(NAME): $(OBJS) |
19 | | - $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJS) -o $(NAME) |
| 54 | +-include $(DEPS) |
20 | 55 |
|
21 | | -%.o: %.cpp |
22 | | - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $< |
| 56 | +# Regular cleaning targets |
23 | 57 |
|
| 58 | +.PHONY: clean fclean re |
24 | 59 | clean: |
25 | | - rm -f *.o *.d |
| 60 | + rm -rf $(OBJ_DIR) |
26 | 61 |
|
27 | 62 | fclean: clean |
28 | | - rm -f $(NAME) |
| 63 | + rm -rf $(BIN_DIR) |
29 | 64 |
|
30 | 65 | re: fclean all |
31 | 66 |
|
32 | | -val: |
33 | | - valgrind ./webserv |
34 | | - |
35 | 67 | # Formatting and linting section |
36 | 68 |
|
37 | 69 | # If compiledb is not installed do `pipx install compiledb`. |
38 | 70 | # compiledb is used to generate the compilation database (compile_commands.json) |
39 | 71 | # used by clang-tidy. |
40 | 72 |
|
| 73 | +.PHONY: db format lint check |
41 | 74 | db: |
42 | 75 | compiledb -n $(MAKE) |
43 | 76 |
|
44 | | -run: |
45 | | - make |
46 | | - ./webserv |
47 | | - |
48 | 77 | format: |
49 | | - clang-format -style=file -dry-run *.cpp *.hpp |
50 | | - |
51 | | -format-fix: |
52 | | - clang-format -style=file -i *.cpp *.hpp |
| 78 | + clang-format -style=file --dry-run -Werror $(CPPS) $(HPPS) |
53 | 79 |
|
54 | 80 | lint: db |
55 | | - clang-tidy -p=. -header-filter=.* *.cpp |
56 | | - |
57 | | -lint-fix: db |
58 | | - clang-tidy -p=. -header-filter=.* -fix *.cpp |
| 81 | + clang-tidy -p=. --header-filter=.* --warnings-as-errors=* $(CPPS) |
59 | 82 |
|
60 | 83 | check: format lint |
61 | 84 |
|
62 | | -# Careful, these rules will overwrite files. |
| 85 | +# Careful, these targets will overwrite files. |
63 | 86 | # Make sure to use `make check` before committing irreversible changes. |
64 | 87 |
|
65 | | -fix: format-fix lint-fix |
| 88 | +.PHONY: format-fix lint-fix fix |
| 89 | +format-fix: |
| 90 | + clang-format -style=file -i $(CPPS) $(HPPS) |
66 | 91 |
|
67 | | --include $(DEPS) |
| 92 | +lint-fix: db |
| 93 | + clang-tidy -p=. --header-filter=.* -fix $(CPPS) |
| 94 | + |
| 95 | +fix: format-fix lint-fix |
0 commit comments