-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (83 loc) · 2.67 KB
/
Makefile
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
CXX = c++
CXXFLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RM = rm -rf
AR = ar rcs
NAME = webserv
UNAME_OS = $(shell uname -s)
INC = -I inc/
SRC_DIR = src/
CONF_DIR = conf/
UTILS_DIR = utils/
SOCK_DIR = sockets/
OBJ_DIR = objs/
LOOP_DIR = loop/
REQU_DIR = request/
RESP_DIR = response/
MAIN_NAME = main.cpp
CONF_NAME = Config.cpp Server.cpp AConfigurable.cpp Location.cpp
SOCK_NAME = ServerSocket.cpp ClientSocket.cpp
UTILS_NAME = utils.cpp CaseInsensitiveCompare.cpp
LOOP_NAME = loop.cpp
REQU_NAME = Request.cpp
RESP_NAME = Response.cpp CGIHandler.cpp
OBJ_NAME = $(MAIN_NAME:.cpp=.o)
OBJ_NAME += $(addprefix $(CONF_DIR), $(CONF_NAME:.cpp=.o))
OBJ_NAME += $(addprefix $(UTILS_DIR), $(UTILS_NAME:.cpp=.o))
OBJ_NAME += $(addprefix $(LOOP_DIR), $(LOOP_NAME:.cpp=.o))
OBJ_NAME += $(addprefix $(SOCK_DIR), $(SOCK_NAME:.cpp=.o))
OBJ_NAME += $(addprefix $(REQU_DIR), $(REQU_NAME:.cpp=.o))
OBJ_NAME += $(addprefix $(RESP_DIR), $(RESP_NAME:.cpp=.o))
OBJ = $(addprefix $(OBJ_DIR), $(OBJ_NAME))
DEPS = $(OBJ:.o=.d)
ifeq ($(UNAME_OS), Linux)
CXXFLAGS += -D_LINUX
else ifeq ($(UNAME_OS), Darwin)
CXXFLAGS += -D_DARWIN
endif
ifeq ($(MAKECMDGOALS), debug)
CXXFLAGS += -D_DEBUG
CXXFLAGS += -fsanitize=address
CXXFLAGS += -g
endif
all: mkdir $(NAME)
$(NAME): $(OBJ)
@$(CXX) $(CXXFLAGS) -o $@ $^
@echo "##### $@ compiling finished! #####"
$(OBJ_DIR)%.o: $(SRC_DIR)%.cpp
@$(CXX) $(CXXFLAGS) $(INC) -o $@ -c $<
@echo "##### Creating" [ $@ ] " #####"
mkdir:
@if [ ! -d "$(OBJ_DIR)$(CONF_DIR)" ]; then \
mkdir -p $(OBJ_DIR)$(CONF_DIR) && \
echo "##### Creating $(OBJ_DIR)$(CONF_DIR) directory #####"; \
fi
@if [ ! -d "$(OBJ_DIR)$(UTILS_DIR)" ]; then \
mkdir -p $(OBJ_DIR)$(UTILS_DIR) && \
echo "##### Creating $(OBJ_DIR)$(UTILS_DIR) directory #####"; \
fi
@if [ ! -d "$(OBJ_DIR)$(SOCK_DIR)" ]; then \
mkdir -p $(OBJ_DIR)$(SOCK_DIR) && \
echo "##### Creating $(OBJ_DIR)$(SOCK_DIR) directory #####"; \
fi
@if [ ! -d "$(OBJ_DIR)$(LOOP_DIR)" ]; then \
mkdir -p $(OBJ_DIR)$(LOOP_DIR) && \
echo "##### Creating $(OBJ_DIR)$(LOOP_DIR) directory #####"; \
fi
@if [ ! -d "$(OBJ_DIR)$(REQU_DIR)" ]; then \
mkdir -p $(OBJ_DIR)$(REQU_DIR) && \
echo "##### Creating $(OBJ_DIR)$(REQU_DIR) directory #####"; \
fi
@if [ ! -d "$(OBJ_DIR)$(RESP_DIR)" ]; then \
mkdir -p $(OBJ_DIR)$(RESP_DIR) && \
echo "##### Creating $(OBJ_DIR)$(RESP_DIR) directory #####"; \
fi
-include $(DEPS)
clean:
@$(RM) $(OBJ_DIR)
@echo "##### Removed object files #####"
fclean: clean
@$(RM) $(NAME)
@echo "##### Removed binary files #####"
re: fclean all
debug: all
.PHONY: all mkdir clean fclean re