-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
129 lines (104 loc) · 3.47 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
# **************************************************************************** #
# #
# ::: :::::::: #
# makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: youkim < youkim@student.42seoul.kr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/09/09 14:12:20 by youkim #+# #+# #
# Updated: 2021/12/21 09:44:23 by youkim ### ########.fr #
# #
# **************************************************************************** #
# ===== Target & FLAGS =====
NAME := push_swap
CC := gcc
CFLAGS := -Wall -Wextra -Werror
RM := rm -rf
PRE := src/
INC := -I includes/ -I libft/includes
LIBFT := libft/libft.a
# ===== Test & Debugging =====
DFLAGS := #-g3 -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
VFLAGS := --leak-check=full --show-leak-kinds=all \
--track-origins=yes --show-reachable=no \
--suppressions=./libft/macos.supp
VSFLAGS := --show-reachable=yes --error-limit=no --gen-suppressions=all \
# --log-file=./mlx.supp
HGEN := hgen
TPARAM := $(shell ruby -e "puts (1..11).to_a.shuffle.join (' ')")
TEST := ./$(NAME) $(TPARAM)
# ===== Packages =====
PKGS := engine utils quicksort
engineV := push_swap engine checks
quicksortV := quicksort smolsort
utilsV := opers opers_util util_compares util_numbers util_quicksort
# ===== Macros =====
define choose_modules
$(foreach pkg, $(1),\
$(foreach file, $($(pkg)V),\
$(PRE)$(pkg)/$(file).c\
)\
)
endef
# ===== Sources & Objects & Includes =====
SRC = $(call choose_modules, $(PKGS))
OBJ = $(SRC:%.c=%.o)
# ===== Rules =====
%.o: %.c
@echo " $(WU)$(<F)$(R) -> $(E)$(@F)"
@$(CC) $(CFLAGS) $(DFLAGS) $(INC) -c -o $@ $<
$(NAME): $(OBJ) $(LIBFT)
@$(CC) $(CFLAGS) $(INC) -o $@ $^
@$(call log, V, Linked Object files,\
\n\twith flag $(R)$(DFLAGS)$(E)$(CFLAGS))
@echo "$(G)<<$(NAME)>>$(E)"
all: $(NAME)
clean:
@$(RM) $(OBJ)
@$(call log, R, Cleaned Object files)
fclean: clean
@$(RM) $(NAME)
@$(call log, R, Cleaned Names)
re: fclean all
$(LIBFT):
@$(call log, G, Building $(CU)$(LIBFT)$(V))
@make all -C libft/ DFLAGS="$(DFLAGS)"
@$(call log, G, Built $(CU)$(LIBFT)$(V))
# ===== Custom Rules =====
red: fclean docs all cls
ald: docs all cls
docs:
@$(call log, V, Generating Docs,...)
@set -e;\
for p in $(PKGS); do\
$(HGEN) -I includes/$$p.h src/$$p;\
done
@$(call log, G, Updated Docs)
test: docs all cls
@$(call log, Y, Running Test, \n\twith param $(R)$(TPARAM)$(E))
@$(TEST)
@$(call log, G, Ended Test)
leak: docs all cls
@$(call log, Y, Running Leak Test,...)
@colour-valgrind $(VFLAGS) $(TEST)
supp: docs all cls
@$(call log, Y, Creating Leak Suppressions,...)
@valgrind $(VFLAGS) --gen-suppressions=all $(TEST)
.PHONY: all re clean fclean test red docs
# ===== Colors =====
cls:
@set -e; clear
R ?= \033[0;91m
WU ?= \033[4;37m
C ?= \033[0;96m
CU ?= \033[4;36m
Y ?= \033[0;33m
YU ?= \033[4;33m
G ?= \033[0;92m
V ?= \033[0;35m
E ?= \033[0m
CNAM ?= for $(YU)$(strip $(NAME)$(E))
define log
printf "$($(strip $(1)))<$(strip $(2))\
$(CNAM)$($(strip $(1)))$(strip $(3))$($(strip $(1)))>$(E)\n"
endef