-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
322 lines (251 loc) · 8.63 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lpaulo-m <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/03/26 16:25:08 by lpaulo-m #+# #+# #
# Updated: 2022/02/25 10:37:51 by lpaulo-m ### ########.fr #
# #
# **************************************************************************** #
NAME = fractol
FRACTOL_HEADER = $(INCLUDES_PATH)/fractol.h
FRACTOL_ARCHIVE = $(ARCHIVES_PATH)/fractol.a
CC = gcc
CC_STRICT = $(CC) $(CCF_STRICT) $(CCF_OPTIMIZATION)
CCF_STRICT = -Wall -Wextra -Werror
CCF_OPTIMIZATION = -O3
CCF_DEBUG = -g -fsanitize=leak
CCF_LIBS = -lm -lbsd -lmlx -lXext -lX11
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
BITMAPS_PATH = ./bitmaps
SOURCES = $(wildcard $(SOURCES_PATH)/**/*.c) $(wildcard $(SOURCES_PATH)/*.c)
OBJECTS = $(patsubst $(SOURCES_PATH)/%.c, $(OBJECTS_PATH)/%.o, $(SOURCES))
OBJECT_DIRECTORIES = $(sort $(dir $(OBJECTS)))
ARCHIVES = $(FRACTOL_ARCHIVE) $(FT_LIBBMP_ARCHIVE) $(LIBFT_ARCHIVE)
################################################################################
# REQUIRED
################################################################################
REQUIRED_MAIN = ./main.c
all: $(NAME)
$(NAME): $(FRACTOL_ARCHIVE)
$(CC_STRICT) $(CCF_DEBUG) \
-I $(INCLUDES_PATH) \
$(REQUIRED_MAIN) \
$(ARCHIVES) \
$(CCF_LIBS) \
-o $(NAME)
$(FRACTOL_ARCHIVE): initialize build_libft build_ft_libbmp $(FRACTOL_HEADER) $(OBJECTS)
$(ARCHIVE_AND_INDEX) $(FRACTOL_ARCHIVE) $(OBJECTS)
$(OBJECTS_PATH)/%.o: $(SOURCES_PATH)/%.c
$(CC_STRICT) -I $(INCLUDES_PATH) -c -o $@ $<
re: fclean all
################################################################################
# INITIALIZE
################################################################################
initialize: make_dirs build_libs
make_dirs: $(ARCHIVES_PATH) $(OBJECTS_PATH) $(OBJECT_DIRECTORIES) $(BITMAPS_PATH)
$(ARCHIVES_PATH):
$(SAFE_MAKEDIR) $@
$(OBJECTS_PATH):
$(SAFE_MAKEDIR) $@
$(OBJECT_DIRECTORIES):
$(SAFE_MAKEDIR) $@
$(BITMAPS_PATH):
$(SAFE_MAKEDIR) $@
build_libs: build_libft build_ft_libbmp
################################################################################
# CLEAN
################################################################################
clean:
$(REMOVE) $(OBJECTS)
$(REMOVE) $(FRACTOL_ARCHIVE)
fclean: clean
$(REMOVE) $(NAME)
tclean: clean_libs fclean tests_clean example_clean vglog_clean
################################################################################
# FRACTALS
################################################################################
mbt: re
./$(NAME) mandelbrot
julia: re
# ./$(NAME) julia 0.3 0.4
# ./$(NAME) julia -2.0 0.0
# ./$(NAME) julia -1.0 0.0
# ./$(NAME) julia 0.0 0.0
# ./$(NAME) julia 1.0 0.0
# ./$(NAME) julia 2.0 0.0
# ./$(NAME) julia 3.0 0.0
# ./$(NAME) julia 1.0 1.0
# ./$(NAME) julia -0.4 0.6
# ./$(NAME) julia 0.285 0.0
# ./$(NAME) julia 0.285 0.01
# ./$(NAME) julia 0.45 0.1428
./$(NAME) julia -0.70176 -0.3842
# ./$(NAME) julia -0.835 -0.2321
# ./$(NAME) julia -0.8 0.156
# ./$(NAME) julia -0.7269 0.1889
# ./$(NAME) julia 0.0 -0.8
############# Dendrite fractal ##############
# ./$(NAME) julia 0.0 1.0
########## Douady's rabbit fractal ##########
# ./$(NAME) julia -0.123 0.745
############# San Marco fractal #############
# ./$(NAME) julia -0.75 0.0
############ Siegel disk fractal ############
# ./$(NAME) julia -0.391 -0.587
newton: re
./$(NAME) newton
################################################################################
# LIBS
################################################################################
LIBS_PATH = ./libs
LIBFT = libft.a
LIBFT_PATH = $(LIBS_PATH)/libft
LIBFT_ARCHIVE = $(ARCHIVES_PATH)/$(LIBFT)
LIBFT_HEADER = $(LIBFT_PATH)/includes/libft.h
build_libft:
$(MAKE_EXTERNAL) $(LIBFT_PATH) all
$(COPY) $(LIBFT_PATH)/$(LIBFT) $(LIBFT_ARCHIVE)
$(COPY) $(LIBFT_HEADER) $(INCLUDES_PATH)
libft_clean:
$(MAKE_EXTERNAL) $(LIBFT_PATH) fclean
$(REMOVE) $(LIBFT_ARCHIVE)
FT_LIBBMP = ft_libbmp.a
FT_LIBBMP_PATH = $(LIBS_PATH)/ft_libbmp
FT_LIBBMP_ARCHIVE = $(ARCHIVES_PATH)/$(FT_LIBBMP)
FT_LIBBMP_HEADER = $(FT_LIBBMP_PATH)/includes/ft_libbmp.h
build_ft_libbmp:
$(MAKE_EXTERNAL) $(FT_LIBBMP_PATH) all
$(COPY) $(FT_LIBBMP_PATH)/$(FT_LIBBMP) $(FT_LIBBMP_ARCHIVE)
$(COPY) $(FT_LIBBMP_HEADER) $(INCLUDES_PATH)
ft_libbmp_clean:
$(MAKE_EXTERNAL) $(FT_LIBBMP_PATH) fclean
$(REMOVE) $(FT_LIBBMP_ARCHIVE)
clean_libs: libft_clean ft_libbmp_clean
################################################################################
# TESTS
################################################################################
TESTS_PATH = ./tests
TEST_SOURCES = $(wildcard $(TESTS_PATH)/*.c)
CCF_TEST_LIBS = -lrt -lm
EXECUTE_TESTS = ./test
build_tests: re
$(CC) $(CCF_DEBUG) \
-I $(INCLUDES_PATH) \
$(TEST_SOURCES) \
$(ARCHIVES) \
$(CCF_LIBS) $(CCF_TEST_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: $(FRACTOL_ARCHIVE)
$(CC) $(CCF_DEBUG) \
-I $(INCLUDES_PATH) \
$(EXAMPLE_MAIN) $(FRACTOL_ARCHIVE) \
$(FT_LIBBMP_ARCHIVE) $(LIBFT_ARCHIVE) \
$(CCF_LIBS)
example_clean: fclean
$(REMOVE_RECURSIVE) $(EXAMPLE_GARBAGE)
################################################################################
# VALGRIND
################################################################################
VALGRIND = valgrind
VALGRIND_FLAGS = --leak-check=full --show-leak-kinds=all
VALGRIND_LOG = valgrind_leaks.log
VALGRIND_LOG_FLAGS = --log-file=$(VALGRIND_LOG) \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--verbose
VALGRIND_TARGET = ./$(NAME) julia -0.391 -0.587
vg: vg_build
$(VALGRIND) $(VALGRIND_FLAGS) $(VALGRIND_TARGET)
vglog: vg_build
$(VALGRIND) $(VALGRIND_LOG_FLAGS) $(VALGRIND_TARGET)
vg_build: $(FRACTOL_ARCHIVE)
$(CC_STRICT) \
-I $(INCLUDES_PATH) \
$(REQUIRED_MAIN) \
$(ARCHIVES) \
$(CCF_LIBS) \
-o $(NAME)
vglog_clean: fclean
$(REMOVE) $(VALGRIND_LOG)
################################################################################
# MISC
################################################################################
norm:
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 $(REQUIRED_MAIN)
@printf "\n$(G)=== No norminette errors found in $(REQUIRED_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
################################################################################
# PHONY
################################################################################
.PHONY: all required clean fclean re \
initialize make_dirs build_libs \
\
build_libft libft_clean \
build_ft_libbmp ft_libbmp_clean \
\
build_tests test tests_clean \
build_example example example_clean \
vg vglog vg_build vglog_clean \
\
tclean clean_libs \
norm git gitm
################################################################################
# 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