-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
112 lines (86 loc) · 3.64 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
101
102
103
104
105
106
107
108
109
110
111
112
.PHONY: clean fclean re all libjson makedir comp
NAME = webserv
###################################################################################
# Compiler & Flags #
###################################################################################
CXX = clang++
CPPFLAGS = -Wall -Wextra -Werror -std=c++98
LDFLAGS = -lpthread
COMP_CONST = -D LOGS_DIR=\"${LOGS_DIR}\"
ifeq ($(shell uname), Linux)
LDFLAGS += -lcrypt
ifeq ($(DEBUG), 1)
CPPFLAGS += -fstandalone-debug -g
endif
else
ifeq ($(DEBUG), 1)
CPPFLAGS += -g
endif
endif
ifeq ($(USE_DAEMON), 1)
COMP_CONST += -D WS_DAEMON_MODE
endif
###################################################################################
# Directories & Files #
###################################################################################
SRCS_DIR = src
OBJS_DIR = .obj
DEPS_DIR = .deps
TMP_DIR = .tmp
INCLUDE_DIR = include
LOGS_DIR = logs
DFLT_DIR = default
SRCS = ARequest.cpp IO.cpp SHA1.cpp \
Auth.cpp Location.cpp Server.cpp \
Base64.cpp Logger.cpp ServerBlock.cpp \
CGI.cpp Proxy.cpp Settings.cpp \
CRC.cpp Range.cpp StatusLines.cpp \
Client.cpp Redirect.cpp Time.cpp \
Config.cpp Request.cpp URI.cpp \
Cookie.cpp RequestHeader.cpp Utils.cpp \
ErrorResponses.cpp Response.cpp Worker.cpp \
Header.cpp ResponseContType.cpp main.cpp \
HeaderNames.cpp ResponseHeader.cpp ETag.cpp \
CmdArgs.cpp
OBJS = $(addprefix $(OBJS_DIR)/, $(SRCS:.cpp=.o))
DEPS = $(addprefix $(DEPS_DIR)/, $(SRCS:.cpp=.d))
###################################################################################
# Libjson #
###################################################################################
LIBJSONDIR = json-parser
LIBJSONINCLUDE = ./${LIBJSONDIR}/src
LIBJSONFLAGS = -ljson -L ./${LIBJSONDIR} -I ${LIBJSONINCLUDE}
###################################################################################
# Commands #
###################################################################################
comp: libjson makedir $(NAME)
all:
$(MAKE) comp DEBUG=1
daemon:
$(MAKE) all USE_DAEMON=1
libjson:
@if ! [ "$(ls $(LIBJSONDIR))" ] ; then git submodule update --init; fi
$(MAKE) -C $(LIBJSONDIR) all
makedir:
@if ! [ -d ${OBJS_DIR} ] ; then mkdir ${OBJS_DIR} ; fi
@if ! [ -d ${DEPS_DIR} ] ; then mkdir ${DEPS_DIR} ; fi
@if ! [ -d ${LOGS_DIR} ] ; then mkdir ${LOGS_DIR} ; fi
@if ! [ -d ${TMP_DIR} ] ; then mkdir ${TMP_DIR} ; fi
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@ $(LIBJSONFLAGS) $(LDFLAGS)
-include $(DEPS)
$(OBJS_DIR)/%.o: $(SRCS_DIR)/%.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@ \
-I $(INCLUDE_DIR) -I $(LIBJSONINCLUDE) \
${COMP_CONST} \
-MMD -MF $(patsubst ${OBJS_DIR}/%.o,${DEPS_DIR}/%.d,$@)
clean:
rm -rf ${DEPS_DIR} ${OBJS_DIR} ${LOGS_DIR} ${TMP_DIR}
fclean: clean
rm -rf $(NAME)
re: fclean all
###################################################################################
# Tests #
###################################################################################
cgi:
gcc ./pages/site/cgi/printenv.c -o ./pages/site/cgi/cgi-bin/printenv.cgi