Skip to content

Commit 3ffa26d

Browse files
iboukhssStokesAsselborn
authored andcommitted
build: improve organization
1 parent 891796b commit 3ffa26d

File tree

13 files changed

+65
-43
lines changed

13 files changed

+65
-43
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,5 @@ jobs:
1414
- name: Install dependencies
1515
run: pipx install compiledb
1616

17-
- name: Run clang-format
18-
run: clang-format --dry-run --Werror *.cpp *.hpp
19-
20-
- name: Build and generate compilation database
21-
run: compiledb make
22-
23-
- name: Run clang-tidy
24-
run: clang-tidy --header-filter=.* --warnings-as-errors=* *.cpp
17+
- name: Build and run checks
18+
run: make all check

Makefile

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,95 @@
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)
236

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)
739

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)
1042

11-
OBJS = $(SRCS:.cpp=.o)
12-
DEPS = $(OBJS:.o=.d)
43+
val: all
44+
valgrind ./$(TARGET)
1345

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 $@
1549

16-
all: $(NAME)
50+
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
51+
@mkdir -p $(dir $@)
52+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
1753

18-
$(NAME): $(OBJS)
19-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OBJS) -o $(NAME)
54+
-include $(DEPS)
2055

21-
%.o: %.cpp
22-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
56+
# Regular cleaning targets
2357

58+
.PHONY: clean fclean re
2459
clean:
25-
rm -f *.o *.d
60+
rm -rf $(OBJ_DIR)
2661

2762
fclean: clean
28-
rm -f $(NAME)
63+
rm -rf $(BIN_DIR)
2964

3065
re: fclean all
3166

32-
val:
33-
valgrind ./webserv
34-
3567
# Formatting and linting section
3668

3769
# If compiledb is not installed do `pipx install compiledb`.
3870
# compiledb is used to generate the compilation database (compile_commands.json)
3971
# used by clang-tidy.
4072

73+
.PHONY: db format lint check
4174
db:
4275
compiledb -n $(MAKE)
4376

44-
run:
45-
make
46-
./webserv
47-
4877
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)
5379

5480
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)
5982

6083
check: format lint
6184

62-
# Careful, these rules will overwrite files.
85+
# Careful, these targets will overwrite files.
6386
# Make sure to use `make check` before committing irreversible changes.
6487

65-
fix: format-fix lint-fix
88+
.PHONY: format-fix lint-fix fix
89+
format-fix:
90+
clang-format -style=file -i $(CPPS) $(HPPS)
6691

67-
-include $(DEPS)
92+
lint-fix: db
93+
clang-tidy -p=. --header-filter=.* -fix $(CPPS)
94+
95+
fix: format-fix lint-fix
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)