Skip to content

Commit 95d29d3

Browse files
committed
build: update folder structure
1 parent 3ffa26d commit 95d29d3

File tree

14 files changed

+61
-58
lines changed

14 files changed

+61
-58
lines changed

Makefile

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Compiler settings
2-
CXX = clang++
3-
CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -g3
4-
CPPFLAGS = -MMD -MP
5-
61
# Executable name
72
NAME = webserv
83

@@ -16,25 +11,33 @@ BIN_DIR = $(BUILD_DIR)/bin
1611
TARGET = $(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
3841
all: $(TARGET)
3942

4043
run: 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
5959
clean:
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
7473
db:
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
8987
format-fix:
9088
clang-format -style=file -i $(CPPS) $(HPPS)
9189

9290
lint-fix: db
9391
clang-tidy -p=. --header-filter=.* -fix $(CPPS)
9492

9593
fix: format-fix lint-fix
94+
95+
# Include dependencies
96+
-include $(DEPS)
97+
98+
.PHONY: $(PHONY)

src/cgi/.gitkeep

Whitespace-only changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ What should the task do ?
99
1010
*/
1111

12-
#ifndef CONFIGPARSER_HPP_
13-
#define CONFIGPARSER_HPP_
12+
#ifndef CONFIG_CONFIG_PARSER_HPP_
13+
#define CONFIG_CONFIG_PARSER_HPP_
1414

1515
#include <string>
1616
#include <vector>
@@ -31,4 +31,4 @@ class ConfigParser {
3131
ConfigParser();
3232
};
3333

34-
#endif
34+
#endif // CONFIG_CONFIG_PARSER_HPP_

src/Client.cpp renamed to src/core/Client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "Client.hpp"
1+
#include "core/Client.hpp"
22

3-
#include "SyscallError.hpp"
3+
#include "util/SyscallError.hpp"
44

55
#include <fcntl.h>
66
#include <unistd.h>

src/Client.hpp renamed to src/core/Client.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CLIENT_HPP_
2-
#define CLIENT_HPP_
1+
#ifndef CORE_CLIENT_HPP_
2+
#define CORE_CLIENT_HPP_
33

44
#include <netinet/in.h>
55

@@ -33,4 +33,4 @@ class Client {
3333
Client* next_;
3434
};
3535

36-
#endif // CLIENT_HPP_
36+
#endif // CORE_CLIENT_HPP_

src/Server.cpp renamed to src/core/Server.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "Server.hpp"
1+
#include "core/Server.hpp"
22

3-
#include "HttpResponse.hpp"
4-
#include "SyscallError.hpp"
5-
#include "structs_dev.hpp"
3+
#include "http/HttpResponse.hpp"
4+
#include "util/SyscallError.hpp"
5+
#include "util/structs_dev.hpp"
66

77
#include <errno.h>
88
#include <fcntl.h>

src/Server.hpp renamed to src/core/Server.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#ifndef SERVER_H_
2-
#define SERVER_H_
1+
#ifndef CORE_SERVER_H_
2+
#define CORE_SERVER_H_
33

4-
#include "Client.hpp"
5-
#include "structs_dev.hpp"
4+
#include "core/Client.hpp"
5+
#include "util/structs_dev.hpp"
66

77
#include <netinet/in.h>
88
#include <sys/epoll.h>
@@ -49,4 +49,4 @@ class Server {
4949
const struct ServerConfig* config_;
5050
};
5151

52-
#endif
52+
#endif // CORE_SERVER_HPP_
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "HttpResponse.hpp"
1+
#include "http/HttpResponse.hpp"
22

33
#include <sstream>
44

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef HTTPRESPONSE_HPP_
2-
#define HTTPRESPONSE_HPP_
1+
#ifndef HTTP_HTTP_RESPONSE_HPP_
2+
#define HTTP_HTTP_RESPONSE_HPP_
33

44
#include <string>
55

@@ -10,4 +10,4 @@ struct HttpResponse {
1010
std::string to_string() const;
1111
};
1212

13-
#endif // HTTPRESPONSE_HPP_
13+
#endif // HTTP_HTTP_RESPONSE_HPP_

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

33
// #include "ConfigParser.hpp"
4-
#include "Server.hpp"
5-
#include "SyscallError.hpp"
6-
#include "structs_dev.hpp" //to be removed
4+
#include "core/Server.hpp"
5+
#include "util/SyscallError.hpp"
6+
#include "util/structs_dev.hpp" //to be removed
77

88
#include <iostream>
99

0 commit comments

Comments
 (0)