-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
287 lines (222 loc) · 7.06 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lpaulo-m <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/03/26 16:25:08 by lpaulo-m #+# #+# #
# Updated: 2022/08/23 22:30:06 by lpaulo-m ### ########.fr #
# #
# **************************************************************************** #
NAME = netmon
CC = gcc
CC_STRICT = $(CC) \
$(CCF_INCLUDES) \
$(CCF_STRICT)
CC_FULL = $(CC_STRICT) \
$(CCF_DEBUG)
# $(CCF_OPTIMIZATION) \
CCF_INCLUDES = -I $(LOCAL_INCLUDES) -I $(LIBFT_INCLUDES) -I $(INCLUDES_PATH)
CCF_STRICT = -Wall -Wextra -Werror
CCF_OPTIMIZATION = -O3
CCF_DEBUG = -g #-fsanitize=leak
CCF_LIBS = -L $(LOCAL_LIBS) -lcurl -pthread
MAKE_EXTERNAL = make -C
SAFE_MAKEDIR = mkdir -p
ARCHIVE_AND_INDEX = ar -rcs
COPY = cp
REMOVE = /bin/rm -f
REMOVE_RECURSIVE = /bin/rm -rf
OBJECTS_PATH = ./objects
SOURCES_PATH = ./sources
INCLUDES_PATH = ./includes
ARCHIVES_PATH = ./archives
LIBS_PATH = ./libs
LIBFT_PATH = $(LIBS_PATH)/libft
LIBFT = $(LIBFT_PATH)/libft.a
LIBFT_INCLUDES = $(LIBFT_PATH)/includes
LOCAL_INCLUDES = /home/lgeniole/.local/include
LOCAL_LIBS = /home/lgeniole/.local/lib
################################################################################
# MANDATORY
################################################################################
M_HEADER = $(INCLUDES_PATH)/netmon.h
M_ARCHIVE = $(ARCHIVES_PATH)/netmon.a
M_SOURCES_PATH = $(SOURCES_PATH)
M_OBJECTS_PATH = $(OBJECTS_PATH)
M_SOURCES = $(wildcard $(M_SOURCES_PATH)/**/*.c) $(wildcard $(M_SOURCES_PATH)/*.c)
# M_SOURCES =
M_OBJECTS = $(patsubst $(M_SOURCES_PATH)/%.c, $(M_OBJECTS_PATH)/%.o, $(M_SOURCES))
M_OBJECT_DIRECTORIES = $(sort $(dir $(M_OBJECTS)))
M_MAIN = ./main.c
M_ARCHIVES = $(M_ARCHIVE) $(LIBFT)
all: $(NAME)
$(NAME): $(LIBFT) $(M_ARCHIVE)
$(CC_FULL) \
$(M_MAIN) \
$(M_ARCHIVES) \
$(CCF_LIBS) \
-o $(NAME)
$(M_ARCHIVE): $(M_HEADER) $(M_OBJECTS)
$(ARCHIVE_AND_INDEX) $(M_ARCHIVE) $(M_OBJECTS)
$(M_OBJECTS_PATH)/%.o: $(M_SOURCES_PATH)/%.c
$(CC_FULL) -c -o $@ $<
clean:
$(REMOVE) $(M_OBJECTS)
$(REMOVE) $(M_ARCHIVE)
fclean: clean
$(REMOVE) $(NAME)
re: fclean all
################################################################################
# DIRS
################################################################################
dirs: $(ARCHIVES_PATH) $(OBJECTS_PATH) \
$(M_OBJECT_DIRECTORIES) $(B_OBJECT_DIRECTORIES)
$(ARCHIVES_PATH):
$(SAFE_MAKEDIR) $@ && touch "[email protected]"
$(OBJECTS_PATH):
$(SAFE_MAKEDIR) $@ && touch "[email protected]"
$(M_OBJECT_DIRECTORIES):
$(SAFE_MAKEDIR) $@ && touch "[email protected]"
################################################################################
# CLEAN
################################################################################
tclean: clean_libs fclean tests_clean example_clean vglog_clean
################################################################################
# LIBS
################################################################################
$(LIBFT):
$(MAKE_EXTERNAL) $(LIBFT_PATH) all
libft_clean:
$(MAKE_EXTERNAL) $(LIBFT_PATH) fclean
clean_libs: libft_clean
################################################################################
# TESTS
################################################################################
TESTS_PATH = ./tests
TEST_SOURCES = $(wildcard $(TESTS_PATH)/*.c)
CCF_TEST_LIBS = -lrt -lm
EXECUTE_TESTS = ./test
build_tests: re
$(CC_FULL) \
$(TEST_SOURCES) \
$(M_ARCHIVES) \
$(CCF_TEST_LIBS) \
$(CCF_LIBS) \
-o $(EXECUTE_TESTS)
test: build_tests
$(EXECUTE_TESTS)
tests_clean:
$(REMOVE_RECURSIVE) $(EXECUTE_TESTS)
################################################################################
# EXAMPLE
################################################################################
EXAMPLES_PATH = ./examples
EXAMPLE_MAIN = $(EXAMPLES_PATH)/example.c
EXECUTE_EXAMPLE = ./a.out
EXAMPLE_GARBAGE = a.out a.out.dSYM
example: build_example
$(EXECUTE_EXAMPLE)
build_example: $(M_ARCHIVE)
$(CC_FULL) \
$(EXAMPLE_MAIN) \
$(M_ARCHIVES) \
$(CCF_LIBS)
example_clean: fclean
$(REMOVE_RECURSIVE) $(EXAMPLE_GARBAGE)
################################################################################
# VALGRIND
################################################################################
CC_VG = $(CC) \
$(CCF_INCLUDES) \
$(CCF_STRICT)
VG = valgrind
VG_FLAGS = --leak-check=full --show-leak-kinds=all --trace-children=yes
VG_LOG = valgrind_leaks.log
VG_LOG_FLAGS = --log-file=$(VG_LOG) \
--leak-check=full \
--show-leak-kinds=all \
--trace-children=yes \
--track-origins=yes \
--verbose
# VG_TARGET = ./$(NAME)
VG_TARGET = ./$(NAME) --debug --config-file test.db
vg: vg_build
$(VG) $(VG_FLAGS) $(VG_TARGET)
vglog: vg_build
$(VG) $(VG_LOG_FLAGS) $(VG_TARGET)
vg_build: $(LIBFT) $(M_ARCHIVE)
$(CC_VG) \
$(M_MAIN) \
$(M_ARCHIVES) \
$(CCF_LIBS) \
-o $(NAME)
vglog_clean: fclean
$(REMOVE) $(VG_LOG)
################################################################################
# MISC
################################################################################
norm:
$(MAKE_EXTERNAL) $(LIBFT_PATH) norm
@printf "\n$(G)=== No norminette errors found in $(LIBFT_PATH) ===$(RC)\n\n"
norminette $(INCLUDES_PATH)
@printf "\n$(G)=== No norminette errors found in $(INCLUDES_PATH) ===$(RC)\n\n"
norminette $(SOURCES_PATH)
@printf "\n$(G)=== No norminette errors found in $(SOURCES_PATH) ===$(RC)\n\n"
norminette $(M_MAIN)
@printf "\n$(G)=== No norminette errors found in $(M_MAIN) ===$(RC)\n\n"
git:
git add -A
git commit -m "AUTOMATIC MESSAGE"
git push
gitm:
git add -A
git commit -m $m
git push
dump_sources:
@echo =========== SOURCES ===========
@echo "M_SOURCES = $(M_SOURCES)"
@echo =================================
################################################################################
# PHONY
################################################################################
.PHONY: \
all clean fclean re \
\
dirs \
\
tclean \
\
libft_clean clean_libs \
\
build_tests test tests_clean \
\
example build_example example_clean \
\
vg vglog vg_build vglog_clean \
\
norm git gitm dump_sources
################################################################################
# Colors
################################################################################
# Black, Red, Green, Yellow, Blue, Purple, Cyan, White
BK = \033[0;30m
R = \033[0;31m
G = \033[0;32m
Y = \033[0;33m
B = \033[0;34m
P = \033[0;35m
C = \033[0;36m
W = \033[0;37m
# Bold
BKB = \033[1;30m
RB = \033[1;31m
GB = \033[1;32m
YB = \033[1;33m
BB = \033[1;34m
PB = \033[1;35m
CB = \033[1;36m
WB = \033[1;37m
# Reset Color
RC = \033[0m