-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
134 lines (103 loc) · 2.84 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Name of the final executable
NAME = webserv
# Paths configurations
SRCDIR := src
OBJDIR := obj
# Create the list of directories
DIRS = $(shell find $(SRCDIR) -type d | sed 's/$(SRCDIR)\///g' | sed -n '1!p')
SRCDIRS = $(foreach dir, $(DIRS), $(addprefix $(SRCDIR)/, $(dir)))
OBJDIRS = $(foreach dir, $(DIRS), $(addprefix $(OBJDIR)/, $(dir)))
# Create a list of *.c sources in DIRS
SRCS = $(wildcard $(SRCDIR)/*.cpp)
SRCS += $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.cpp))
SRC_TEST = $(wildcard test/*.cpp)
SRC_TEST += $(SRCS)
SRC_TEST := $(filter-out $(SRCDIR)/main.cpp, $(SRC_TEST))
# Define objects for all sources
OBJS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRCS))
TESTER_DIRS = YoupiBanane \
YoupiBanane/nop \
YoupiBanane/Yeah
TESTER_FILES = YoupiBanane/youpi.bad_extension \
YoupiBanane/youpi.bla \
YoupiBanane/nop/other.pouic \
YoupiBanane/nop/youpi.bad_extension \
YoupiBanane/Yeah/not_happy.bad_extension
TESTER_TOOLS = tester \
cgi_tester
# Name the compiler & flags
CC = c++
#TODO PUT BACK FLAG WITH C++98
#CFLAGS = -Wall -Wextra -Werror -std=c++98
CFLAGS = -Wall -Wextra -Werror
CFLAGS += -I. -MMD
# rules for compile
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(HIDE)$(CC) $(CFLAGS) -c $< -o $@
all : buildrepo $(NAME)
$(HIDE) mkdir -p data/files
$(NAME) : $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
@printf $(GREEN)"[$@] program created\n"$(RESET)
clean :
$(HIDE)rm -rf $(OBJDIR)
@printf $(YELLOW)"[$(NAME)] objects removed\n"$(RESET)
fclean : clean
$(HIDE)rm -f $(NAME)
$(HIDE)rm -rf $(TESTER_TOOLS)
$(HIDE)rm -rf $(TESTER_DIRS)
re : fclean all
utest : buildrepo
$(HIDE) mkdir -p data/files
$(CC) $(CFLAGS) $(SRC_TEST) -o utest
@printf $(GREEN)"[$@] program created\n"$(RESET)
./utest
rm -f utest
tester:
$(HIDE) mkdir -p $(TESTER_DIRS)
$(HIDE) touch $(TESTER_FILES)
$(HIDE) cp test/tester_tools/tester tester
$(HIDE) cp test/tester_tools/cgi_tester cgi_tester
@printf $(RED)"[$@] \n\n\n*** AVANT DE CONTINUER LE TEST, LANCER LE SERVER AVEC make run_tester ***\n\n\n"$(RESET)
./tester http://localhost:8080
print :
@#echo $(SRCS)
@echo $(SRC_TEST)
run : all
./$(NAME)
run_tester : all
./$(NAME) configFiles/tester.config
rrun : re run
mock : all
./$(NAME) -m
pdf :
@open subject/webserv.pdf
# Create repo of objects!
buildrepo :
$(HIDE)$(call make-repo)
.PHONY : all clean fclean re print run buildrepo $(NAME) tester
define make-repo
$(HIDE)mkdir -p $(OBJDIR)
$(HIDE)for dir in $(DIRS); \
do \
mkdir -p $(OBJDIR)/$$dir; \
done
endef
# Color
BLACK := "\e[0;30m"
RED := "\e[0;31m"
GREEN := "\e[0;32m"
YELLOW := "\e[0;33m"
BLUE := "\e[0;34m"
MAGENTA := "\e[0;35m"
CYAN := "\e[0;36m"
RESET :="\e[0m"
# Decide whether the commands will be shwon or not
VERBOSE = FALSE
ifeq ($(VERBOSE),TRUE)
HIDE =
else
HIDE = @
endif
# Recompilation with modified headers
-include $(OBJS:)