-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
204 lines (153 loc) · 5.57 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: twang <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/03/20 14:09:46 by twang #+# #+# #
# Updated: 2023/10/23 14:19:14 by twang ### ########.fr #
# #
# **************************************************************************** #
include config/print.mk
include config/mandatory/headers.mk
include config/mandatory/sources.mk
include config/bonus/headers.mk
include config/bonus/sources.mk
.SILENT:
#--variables-------------------------------------------------------------------#
NAME = cub3D
DEBUG = no
VALGRIND = no
BONUS = no
OS = $(shell uname)
WHO = $(shell whoami)
AASCEDU = \e]8;;https://profile.intra.42.fr/users/aascedu\a\e[34maascedu\e[34m\e]8;;\a
TWANG = \e]8;;https://profile.intra.42.fr/users/twang\a\e[34mtwang\e[34m\e]8;;\a
#--includes & libraries--------------------------------------------------------#
INC_DIR = incs/mandatory/
INC_B_DIR = incs/bonus/
LIB_DIR = libraries
LIBFT_DIR = $(LIB_DIR)/libft
ifeq ($(OS), Darwin)
MLX_DIR = $(LIB_DIR)/mlx_mac
else ifeq ($(OS), Linux)
MLX_DIR = $(LIB_DIR)/mlx_linux
endif
#--sources & objects-----------------------------------------------------------#
SRC_DIR = sources/mandatory
SRC_B_DIR = sources/bonus
OBJ_DIR = .objs
#--flags mandatory & bonus ----------------------------------------------------#
ifeq ($(BONUS), no)
CFLAGS = -Wall -Wextra -Werror -O3 -pipe -g3 -I $(LIBFT_DIR) -I $(MLX_DIR) -I $(INC_DIR)
else
CFLAGS = -Wall -Wextra -Werror -O3 -pipe -g3 -I $(LIBFT_DIR) -I $(MLX_DIR) -I $(INC_B_DIR)
endif
#--mlx flags-------------------------------------------------------------------#
MLX_FLAGS = -L $(MLX_DIR)
ifeq ($(OS), Darwin)
MLX_FLAGS += -framework OpenGL -framework AppKit
else ifeq ($(OS), Linux)
MLX_FLAGS += -l m -l Xext -l X11 -I $(MLX_DIR)
endif
#--debug flags-----------------------------------------------------------------#
DFLAGS = -g3 -fsanitize=address
ifeq ($(DEBUG), yes)
CFLAGS += $(DFLAGS)
endif
#--leaks flags-----------------------------------------------------------------#
LEAKS = valgrind --leak-check=full --show-leak-kinds=all --quiet
LEAKS_FULL = valgrind --leak-check=full --show-leak-kinds=all --track-fds=yes --log-file=valgrind_report.txt #-v
#--define flags----------------------------------------------------------------#
ifeq ($(OS), Darwin)
CFLAGS += -DMACOS
endif
ifeq ($(WHO), twang)
WHO = Théa 🐼
else ifeq ($(WHO), aascedu)
WHO = Arthur 🦋
else
WHO = !
endif
#--libs------------------------------------------------------------------------#
LIBFT = $(LIBFT_DIR)/libft.a
MLX = $(MLX_DIR)/libmlx.a
#--objects mandatory & bonus --------------------------------------------------#
ifeq ($(BONUS), no)
OBJECTS = $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o))
else
OBJECTS = $(addprefix $(OBJ_DIR)/, $(SOURCES_BONUS:.c=.o))
endif
#--global rules----------------------------------------------------------------#
.DEFAULT_GOAL = all
#--compilation rules-----------------------------------------------------------#
all:
$(MAKE) header
$(MAKE) lib
$(MAKE) $(NAME) -j
$(MAKE) welcome
$(NAME): $(OBJECTS) $(LIBFT)
$(CC) $^ $(CFLAGS) $(LIBFT) $(MLX) -o $@ $(MLX_FLAGS)
$(PRINT_CREATING)
ifeq ($(BONUS), no)
$(OBJ_DIR)/%.o: %.c $(HEADERS)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(PRINT_COMPILING)
else
$(OBJ_DIR)/%.o: %.c $(HEADERS_BONUS)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(PRINT_COMPILING)
endif
#--libs, debugs & bonus -------------------------------------------------------#
lib:
$(MAKE) -C $(LIBFT_DIR)
$(MAKE) -C $(MLX_DIR)
debug:
$(MAKE) re -j DEBUG=yes BONUS=yes
leaks:
clear
$(MAKE) -j VALGRIND=yes
$(LEAKS) ./cub3D assets/maps/map.cub
leaks_full:
clear
$(MAKE) -j VALGRIND=yes
$(LEAKS_FULL) ./cub3D assets/maps/map.cub
bonus:
$(MAKE) re -j BONUS=yes
#--print header----------------------------------------------------------------#
header:
printf "\n${PURPLE}project:\t${END}${BLUE}cub3D${END}\n"
printf "${PURPLE}author:\t\t${END}${BLUE}${AASCEDU} && ${TWANG}${END}\n"
printf "${PURPLE}bonus mode:\t${END}${BLUE}${BONUS}${END}\n"
printf "${PURPLE}leaks mode:\t${END}${BLUE}${VALGRIND}${END}\n"
printf "${PURPLE}debug mode:\t${END}${BLUE}${DEBUG}${END}\n"
printf "${PURPLE}compiler:\t${END}${BLUE}${CC}${END}\n"
printf "${PURPLE}flags:\t\t${END}${BLUE}${CFLAGS}${END}\n"
printf "${PURPLE}date:\t\t${END}${BLUE}2023/${END}\n"
printf " ____________________________\n\n"
welcome:
printf "\n${GREEN}Welcome ${WHO}${END}\n\n"
#--re, clean, fclean & norminette----------------------------------------------#
re:
clear
$(MAKE) fclean
$(MAKE) -j all
clean:
$(MAKE) -C $(LIBFT_DIR) clean
$(MAKE) -C $(MLX_DIR) clean
$(RM) -rf $(OBJECTS)
$(RM) -rf $(OBJ_DIR)
$(PRINT_CLEAN)
fclean:
clear
$(MAKE) clean
$(MAKE) -C $(LIBFT_DIR) fclean
$(RM) $(NAME)
$(PRINT_FCLEAN)
norm:
norminette $(LIBFT_DIR) $(INC_DIR) $(SRC_DIR) $(INC_B_DIR) $(SRC_B_DIR)
#--PHONY-----------------------------------------------------------------------#
.PHONY: all lib debug leaks bonus header welcome re clean fclean norm