-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
246 lines (201 loc) Β· 8.38 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: passunca <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/01/30 09:27:39 by passunca #+# #+# #
# Updated: 2024/02/14 14:41:44 by passunca ### ########.fr #
# #
# **************************************************************************** #
#==============================================================================#
# MAKE CONFIG #
#==============================================================================#
SHELL := bash
#==============================================================================#
# NAMES #
#==============================================================================#
USER = passunca
NAME = fractol
UNAME = $(shell uname)
### Message Vars
_NAME = [$(MAG)fract'ol$(D)]
_LIBFT = [$(MAG)libft$(D)]
_MLX = [$(MAG)mlx$(D)]
_SUCCESS = [$(GRN)SUCCESS$(D)]
_INFO = [$(BLU)INFO$(D)]
_NORM = [$(MAG)Norminette$(D)]
_NORM_SUCCESS = $(GRN)=== OK:$(D)
_NORM_INFO = $(BLU)File no:$(D)
_NORM_ERR = $(RED)=== KO:$(D)
#==============================================================================#
# PATHS #
#==============================================================================#
SRC_PATH = src
LIBS_PATH = lib
BUILD_PATH = .build
LIBFT_PATH = $(LIBS_PATH)/libft
MLX_PATH = $(LIBS_PATH)/mlx
### Files
SRC = $(addprefix $(SRC_PATH)/, main.c ft_usage.c ft_sets.c ft_kill.c \
ft_render.c ft_math.c ft_init.c ft_args.c ft_utils.c ft_ui.c \
ft_sets_newton.c ft_events_mouse.c ft_events_keys.c ft_color.c)
OBJS = $(SRC:$(SRC_PATH)/%.c=$(BUILD_PATH)/%.o)
DEPS = $(OBJS:.o=.d)
### Archives
LIBFT_ARC = $(LIBFT_PATH)/libft.a
MLX_ARC = $(MLX_PATH)/libmlx.a
#==============================================================================#
# COMPILER & FLAGS #
#==============================================================================#
CC = cc
CFLAGS = -Wall -Werror -Wextra
CFLAGS += -g
CFLAGS += -O3
# Enables fastm memory error detection
FSANITIZE := -fsanitize=address
ifeq ($(shell uname), Linux)
MLXFLAGS += -lXext -lX11
else
MLXFLAGS += -L./inc/mlx -framework OpenGL -framework AppKit
endif
#==============================================================================#
# COMMANDS #
#==============================================================================#
AR = ar rcs
RM = rm -rf
MKDIR_P = mkdir -p
MAKE = make -C
#==============================================================================#
# RULES #
#==============================================================================#
##@ Fract'ol Compilation Rules π
all: deps $(NAME) ## Compile Fract'ol
bonus: all ## Compile fractol with bonus features
@echo "[Compiled $(MAG)fractol$(D) $(YEL)with bonus!$(D)] $(_SUCCESS) $(YEL)π$(D)"
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.c
@echo -n "$(MAG)β$(D)"
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_PATH):
@echo "[$(BCYA)Setting up$(D) $(BUILD_PATH) path]"
$(MKDIR_P) $(BUILD_PATH)
$(NAME): $(BUILD_PATH) $(LIBFT_ARC) $(MLX_ARC) $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LIBFT_ARC) $(MLX_ARC) $(MLXFLAGS) -o $(NAME)
@echo "* Compiling $(_NAME) executable : $(_SUCCESS) $(YEL)π$(D)"
$(LIBFT_ARC):
@echo "[$(BCYA)Building$(D) $(_LIBFT) $(BCYA)module$(D)]"
$(MAKE) $(LIBFT_PATH) extra
$(MLX_ARC):
@echo "[$(BCYA)Building$(D) $(_MLX) $(BCYA)module$(D)]"
$(MAKE) $(MLX_PATH)
deps: ## Download/Update libft & mlx
@echo "[$(BCYA)Getting$(D) $(_NAME) $(BCYA)dependencies$(D)]"
@if test ! -d "$(LIBFT_PATH)"; then make get_libft; \
else echo "$(YEL)[libft]$(D) folder found"; fi
@if test ! -d "$(MLX_PATH)"; then make get_mlx; \
else echo "$(YEL)[mlx]$(D) folder found"; fi
@echo " $(RED)ξ$(D) [$(GRN)Nothing to be done!$(D)] $(YEL)π$(D)"
-include $(DEPS)
get_mlx:
@echo "[$(BCYA)Getting$(D) $(_MLX) $(BCYA)submodule$(D)]"
git clone [email protected]:42Paris/minilibx-linux.git $(MLX_PATH)
@echo "* $(_MLX) submodule download : $(_SUCCESS) $(YEL)π$(D)"
get_libft:
@echo "[$(BCYA)Getting$(D) $(_LIBFT) $(BCYA)submodule$(D)]"
git clone [email protected]:PedroZappa/42_libft.git $(LIBFT_PATH)
@echo "* $(_LIBFT) submodule download : $(_SUCCESS) $(YEL)π$(D)"
update_modules:
@echo "* $(BCYA)Updating submodules$(D)"
git submodule init
git submodule update --recursive --remote
@echo "* Submodules update : $(_SUCCESS) $(YEL)π$(D)"
##@ Test, Debug & Leak Check Rules σ°’
norm: ## Run norminette test
@printf "${_NORM}\n"
@ls $(SRC_PATH) | wc -l > norm_ls.txt
@printf "$(_NORM_INFO) $$(cat norm_ls.txt)\n"
@printf "$(_NORM_SUCCESS) "
@norminette $(SRC_PATH) | grep -wc "OK" > norm.txt; \
if [ $$? -eq 1 ]; then \
echo "0" > norm.txt; \
fi
@printf "$$(cat norm.txt)\n"
@if ! diff -q norm_ls.txt norm.txt > /dev/null; then \
printf "$(_NORM_ERR) "; \
norminette $(SRC_PATH) | grep -v "OK" > norm_err.txt; \
cat norm_err.txt | grep -wc "Error:" > norm_errn.txt; \
printf "$$(cat norm_errn.txt)"; \
printf "$$(cat norm_err.txt)"; \
else \
printf "[$(YEL)Everything is OK$(D)]\n"; \
fi
valgrind: ## Check for leaks w/ valgrind
@valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) mandelbrot 42
##@ Clean-up Rules σ°’
clean: ## Remove object files
@echo "* Cleaning $(_NAME) objects σ°’"
$(RM) $(OBJS)
@echo "* $(YEL)Cleaning $(_LIBFT) objects$(D) σ°’"
$(MAKE) $(LIBFT_PATH) clean
@echo "* $(YEL)Removing $(BUILD_PATH)$(D) σ°’"
$(RM) $(BUILD_PATH)
@echo "* $(YEL)Removing $(BUILD_PATH)$(D) : $(_SUCCESS)"
$(RM) norm.txt norm_ls.txt norm_err.txt norm_errn.txt
@echo "* $(YEL)Removing Norminette temp files:$(D) $(_SUCCESS)"
fclean: clean ## Remove archives & executables
@echo "[$(RED)Cleaning executable σ°’$(D)]"
$(RM) $(NAME)
$(MAKE) $(LIBFT_PATH) fclean
@echo "* $(_NAME) removed!"
libclean: fclean ## Remove libft & mlx
@echo "[$(RED)Cleaning libft σ°’$(D)]"
$(RM) $(LIBFT_PATH)
@echo "* $(_LIBFT) removed : $(_SUCCESS)"
$(RM) $(MLX_PATH)
@echo "* $(_MLX) removed : $(_SUCCESS)"
$(RM) $(LIBS_PATH)
@echo "* [$(MAG)$(LIBS_PATH)$(D)] folder removed : $(_SUCCESS)"
re: fclean all ## Purge and Recompile
@echo "* $(_NAME) Recompiled : $(_SUCCESS)$(D) $(YEL)π$(D)"
##@ Help σ°΅
.PHONY: help
help: ## Display this help page
@awk 'BEGIN {FS = ":.*##"; \
printf "\n=> Usage:\n\tmake $(GRN)<target>$(D)\n"} \
/^[a-zA-Z_0-9-]+:.*?##/ { \
printf "\t$(GRN)%-15s$(D) %s\n", $$1, $$2 } \
/^##@/ { \
printf "\n=> %s\n", substr($$0, 5) } ' Makefile
## Tweaked from source:
### https://www.padok.fr/en/blog/beautiful-makefile-awk
.PHONY: deps get_mlx get_libft update_modules norm valgrind clean \
fclean libclean re
#==============================================================================#
# UTILS #
#==============================================================================#
# Colors
#
# Run the following command to get list of available colors
# bash -c 'for c in {0..255}; do tput setaf $c; tput setaf $c | cat -v; echo =$c; done'
#
B = $(shell tput bold)
BLA = $(shell tput setaf 0)
RED = $(shell tput setaf 1)
GRN = $(shell tput setaf 2)
YEL = $(shell tput setaf 3)
BLU = $(shell tput setaf 4)
MAG = $(shell tput setaf 5)
CYA = $(shell tput setaf 6)
WHI = $(shell tput setaf 7)
GRE = $(shell tput setaf 8)
BRED = $(shell tput setaf 9)
BGRN = $(shell tput setaf 10)
BYEL = $(shell tput setaf 11)
BBLU = $(shell tput setaf 12)
BMAG = $(shell tput setaf 13)
BCYA = $(shell tput setaf 14)
BWHI = $(shell tput setaf 15)
D = $(shell tput sgr0)
BEL = $(shell tput bel)
CLR = $(shell tput el 1)