-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
128 lines (104 loc) · 3.39 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: youkim < [email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/09/09 14:12:20 by youkim #+# #+# #
# Updated: 2021/12/03 14:22:36 by youkim ### ########.fr #
# #
# **************************************************************************** #
# ===== Target & FLAGS =====
NAME := so_long
CC := gcc
CFLAGS := -Wall -Wextra -Werror \
#-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" -g
VFLAGS := --leak-check=full --show-leak-kinds=all \
--track-origins=yes --show-reachable=no \
--suppressions=./libft/macos.supp \
--suppressions=./mlx.supp
VSFLAGS := --show-reachable=yes --error-limit=no --gen-suppressions=all \
# --log-file=./mlx.supp
RM := rm -rf
PRE := src/
INC := -I includes/ -I mlx
MLX := -l mlx -framework OpenGL -framework Appkit
LIBFT := libft/libft.a
TEST := ./so_long map/map5.ber
# ===== Packages =====
PKGS := engine map utils
engineV := so_long initialize updates images \
player enemy enemies turn
mapV := new_map del_map render render_utils valdidate
utilsV := vectors colors utils texts
# ===== Macros =====
define choose_modules
$(foreach pkg, $(1),\
$(foreach file, $($(pkg)V),\
$(PRE)$(pkg)/$(file).c\
)\
)
endef
define build_library
@echo "$(Y)<Building Library>$(E)"
@make all -C libft/
@echo "$(G)<Built Library>$(E)"
endef
# ===== Sources & Objects & Includes =====
SRC := $(call choose_modules, $(PKGS))
OBJ := $(SRC:%.c=%.o)
# ===== Recipes =====
%.o: %.c
@echo $(subst .c,.o, $(lastword $(subst /, , $<)))
@$(CC) $(CFLAGS) $(INC) -c -o $@ $<
$(NAME): $(OBJ)
@$(call build_library)
@$(CC) $(CFLAGS) $(INC) $(LIBFT) $(MLX) -o $@ $^
@echo "$(G)<<$(NAME)>>$(E)"
all: $(NAME)
bonus: all
clean:
@$(RM) $(OBJ)
@echo "$(Y)<Cleaned Object files>$(E)"
fclean: clean
@$(RM) $(NAME)
@echo "$(Y)<Cleaned Names>$(E)"
re: fclean all
# ===== Custom Recipes =====
red: fclean docs all
ald: docs all
docs:
@echo "$(G)<Generating Documentation...>$(E)"
@set -e;\
for p in $(PKGS); do\
../hgen/run.py "" includes/$$p.h src/$$p;\
done
@echo "$(G)<Updated Docs>$(E)"
test: docs all
@echo "$(Y)<Running Test>$(E)"
@$(TEST)
@echo "$(G)<Ended Test>$(E)"
leak: docs all
@echo "$(Y)<Running Leak Test>$(E)"
@colour-valgrind $(VFLAGS) $(TEST)
@rm so_long
leaksupp: docs all
@echo "$(Y)<Creating Leak Suppressions>$(E)"
@valgrind $(VFLAGS) $(VSFLAGS) $(TEST)
@rm so_long
leaks: docs all
@echo "$(Y)<Info for Leaks>$(E)"
@$(TEST) &
@set -e; \
PID=$$(ps -U $$USER | grep -i so_long | \
grep -v grep | cut -d ' ' -f 1) ;\
echo "so_long: $$PID" ;\
pbcopy <<< "leakchk $$PID" ;\
# @$(CC) $(INC) $(NAME) test.c -o test
.PHONY: all bonus re clean fclean red ald test leak leaksupp leaks
# ===== Colors =====
Y ?= \033[0;33m
G ?= \033[0;92m
V ?= \033[0;35m
E ?= \033[0m