-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (140 loc) · 5.28 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
##
## EPITECH PROJECT, 2024
## MyFTP
## File description:
## This is the Makefile for the MyFTP project
## It job is to compile, clean and tests the project
##
# All the source files
SOURCES = src/main.c \
src/ftp_server.c \
src/ftp_server_advanced.c \
src/ftp_client.c \
src/ftp_client_manager.c \
src/ftp_command.c \
src/ftp_command_preparation.c \
src/utils/my_split.c \
src/commands/user_command.c \
src/commands/password_command.c \
src/commands/quit_command.c \
src/commands/cwd_command.c \
src/commands/pwd_command.c \
src/commands/cdup_command.c \
src/commands/delete_command.c \
src/commands/pasv_command.c \
src/commands/list_command.c \
src/commands/port_command.c \
src/commands/store_command.c \
src/commands/retrieve_command.c \
src/commands/help_command.c \
src/commands/noop_command.c \
TESTS =
# Compiler and linker settings
NAME = myftp
CC = gcc
FLAGS = -W -Wall -Wextra --coverage --std=c11 -I./include
OBJS = $(SOURCES:.c=.o)
TESTS_OBJS = $(TESTS:.c=.o)
LOG = ./build.log
.PHONY: $(NAME) all clean fclean re tests_run clean_test $(OBJS) $(TESTS_OBJS)
# Colors and formatting
GREEN = \033[1;32m
YELLOW = \033[1;33m
RED = \033[1;31m
BLUE = \033[1;36m
GOLD = \033[1;33m
RESET = \033[0m
RUNNING = [$(YELLOW)~$(RESET)]
SUCCESS = [$(GREEN)✔$(RESET)]
FAILURE = [$(RED)✘$(RESET)]
all: $(NAME)
$(NAME): $(OBJS)
# Link the object files
@printf "$(RUNNING) $(BLUE) 🔗 Linking$(RESET)"
@$(CC) -o $(NAME) $(OBJS) $(FLAGS) >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
# Check if the binary was created
@if [ -f $(NAME) ]; then \
printf \
"$(SUCCESS)$(GREEN) 🎉 $(NAME) built successfully$(RESET)\n";\
else \
printf "$(FAILURE)$(RED) 🚨 $(NAME) build failed$(RESET)\n"; \
cat $(LOG); \
fi
$(OBJS): %.o: %.c
# Compile the source file
@printf "$(RUNNING) $(BLUE) 🔨 $$(basename $<)$(RESET)"
@$(CC) -o $@ -c $< $(FLAGS) >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
clean:
# Delete all the object files
@for file in $(OBJS); do \
printf "$(RUNNING) $(RED) 🗑️ Deleting $$file$(RESET)"; \
rm -f $$file >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"; \
done
fclean: clean clean_test
# Delete the binary
@printf "$(RUNNING) $(RED) 🗑️ Deleting $(NAME)$(RESET)"
@rm -f $(NAME) >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
# Delete the log file
@printf "$(RUNNING) $(RED) 🗑️ Deleting $(LOG)$(RESET)"
@rm -f $(LOG) >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
re: fclean all
$(TESTS_OBJS): %.o: %.c
@printf "$(RUNNING) $(BLUE) 🔨 $$(basename $<)$(RESET)"
@$(CC) -o $@ -c $< $(FLAGS) >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
tests_run: fclean $(OBJS) $(TESTS_OBJS)
@printf "$(RUNNING) $(BLUE) 🔗 Linking$(RESET)"
@$(CC) -o tests.out $(filter-out src/main.o, $(OBJS)) \
$(TESTS_OBJS) $(FLAGS) --coverage >> $(LOG) 2>&1 \
-lcriterion >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n";
@printf "$(RUNNING)$(BLUE) 🧪 Running tests$(RESET)" \
&& ./tests.out --xml=criterion.xml --ignore-warnings >> tests.log 2>&1 \
&& printf "\r$(SUCCESS)\n" \
|| printf "\r$(FAILURE)\n";
@cat tests.log;
@printf "$(RUNNING)$(YELLOW) 📊 Generating coverage$(RESET)" \
&& gcovr --exclude tests/ >> coverage.log 2>&1 \
&& printf "\r$(SUCCESS)\n" \
|| printf "\r$(FAILURE)\n";
@cat coverage.log;
clean_test:
@printf "$(RUNNING) $(RED) 🗑️ Deleting tests.out$(RESET)"
@rm -f tests.out >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting coverage$(RESET)"
@rm -f coverage* >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting tests/*.o$(RESET)"
@rm -f $(CXX_TESTS_OBJS) >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting *.gcda$(RESET)"
@find ./ -name "*.gcda" -delete >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting *.gcno$(RESET)"
@find ./ -name "*.gcno" -delete >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting criterion.xml$(RESET)"
@rm -f criterion.xml >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting tests.log$(RESET)"
@rm -f tests.log >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@printf "$(RUNNING) $(RED) 🗑️ Deleting coverage.log$(RESET)"
@rm -f coverage.log >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"
@if [ -d .cache/ ]; then \
printf "$(RUNNING) $(RED) 🗑️ Deleting .cache/$(RESET)"; \
rm -rf .cache >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"; \
fi
@if [ -d .local/ ]; then \
printf "$(RUNNING) $(RED) 🗑️ Deleting .local/$(RESET)"; \
rm -rf .local >> $(LOG) 2>&1 \
&& printf "\r$(SUCCESS)\n" || printf "\r$(FAILURE)\n"; \
fi