-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
287 lines (226 loc) · 8.21 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: abaisago <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/12/13 11:54:38 by abaisago #+# #+# #
# Updated: 2020/07/07 13:02:40 by abosch ### ########.fr #
# #
# **************************************************************************** #
######################################################################
# DEFINITIONS #
######################################################################
#------------------------------------------------#
# PROJECT |
#------------------------------------------------#
NAME := lem-in
PROJECT := lem-in
#------------------------------------------------#
# LIBRARIES |
#------------------------------------------------#
LIB_PATH := lib
LIB_FT_DIR := $(LIB_PATH)/ft
LIB_FT_NAME := libft.a
LIB_FT := $(LIB_FT_DIR)/$(LIB_FT_NAME)
LIB_FT_FLAGS := -lft
LIB := $(LIB_FT)
LDFLAGS := -L$(LIB_FT_DIR)
LDLIBS := $(LIB_FT_FLAGS)
#------------------------------------------------#
# BINARIES |
#------------------------------------------------#
CC := gcc
CFLAGS := -Wall -Wextra -Werror -O3
CPPFLAGS := -Iincludes \
-Ilib/ft/include
AR := /usr/bin/ar
ARFLAGS := rc
MAKE := /usr/bin/make
RANLIB := /usr/bin/ranlib
CP := /bin/cp
NORMINETTE := /usr/bin/norminette
MKDIR := /bin/mkdir
PRINTF := /usr/bin/printf
RM := /bin/rm
#------------------------------------------------#
# SOURCES |
#------------------------------------------------#
SRC_PATH := sources
SRC_DBG := print.c print2.c
SRC_DBG := $(addprefix debug/, $(SRC_DBG))
SRC_LIB := ft_arraysize.c \
ft_count_words.c \
ft_isseparator.c \
ft_silen.c \
ft_strcspn.c \
ft_strspn.c \
ft_strtok.c \
ft_uilen.c \
ft_swap_xor.c \
ft_strccnt.c
SRC_LIB := $(addprefix lib/, $(SRC_LIB))
SRC_PARSE := ant.c \
hmap.c \
link.c \
parsing.c \
room.c \
comments.c \
readline.c
SRC_PARSE := $(addprefix parsing/, $(SRC_PARSE))
SRC_TOOLS := tools.c \
tools_2.c \
predicates.c \
reset.c \
sort.c
SRC_TOOLS := $(addprefix tools/, $(SRC_TOOLS))
SRC_ALGO := algo.c \
dfs.c \
orientation.c \
utils.c \
cost.c \
deadend.c
SRC_ALGO := $(addprefix algo/, $(SRC_ALGO))
SRC_NAME := main.c \
lemin.c \
del.c \
send_ants.c \
farm.c \
$(SRC_DBG) \
$(SRC_LIB) \
$(SRC_PARSE) \
$(SRC_TOOLS) \
$(SRC_ALGO)
SRC := $(addprefix $(SRC_PATH)/,$(SRC_NAME))
OBJ_PATH := obj
OBJ_NAME := $(SRC_NAME:.c=.o)
OBJ := $(addprefix $(OBJ_PATH)/,$(OBJ_NAME))
#------------------------------------------------#
# RELEASE |
#------------------------------------------------#
REL_PATH := release
NAME := $(NAME)
REL_OBJ := $(addprefix $(REL_PATH)/,$(OBJ))
REL_CFLAGS := $(CFLAGS)
#------------------------------------------------#
# DEBUG |
#------------------------------------------------#
DBG_PATH := debug
DBG := $(DBG_PATH)/$(NAME)
DBG_OBJ := $(addprefix $(DBG_PATH)/,$(OBJ))
DBG_CFLAGS := $(CFLAGS) -g3
#------------------------------------------------#
# EXTRA |
#------------------------------------------------#
EOC := "\033[0;0m"
RED := "\033[0;31m"
GREEN := "\033[0;32m"
BASENAME := `basename $(PWD)`
CREAT := $(CR)$(GREEN)
DEL := $(CR)$(RED)
END := $(EOC)"\033[0K\n"
UP := "\033[0F"
######################################################################
# RULES #
######################################################################
.PHONY: all clean fclean re release dbg
.SILENT:
all: release
#------------------------------------------------#
# RELEASE-RULES |
#------------------------------------------------#
release: $(NAME)
$(NAME): $(LIB) $(REL_OBJ)
@$(PRINTF) $(CREAT)"[ $(PROJECT): All object files created ]"$(END)
@$(CC) $(REL_CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
@$(PRINTF) $(CREAT)"[ $(PROJECT): $@ created ]"$(END)
$(REL_PATH)/$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
@$(MKDIR) -p $(dir $@) 2>/dev/null || true
@$(PRINTF) "[ $(PROJECT): %s ]"$(END) $@
@$(CC) $(REL_CFLAGS) $(CPPFLAGS) -c $< -o $@
@$(PRINTF) $(UP)
#------------------------------------------------#
# DEBUG-RULES |
#------------------------------------------------#
dbg: $(DBG)
$(DBG): $(LIB) $(DBG_OBJ)
@$(PRINTF) $(CREAT)"[ $(PROJECT): All debug object files created ]"$(END)
@$(CC) $(DBG_CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
@$(PRINTF) $(CREAT)"[ $(PROJECT): $@ created ]"$(END)
$(DBG_PATH)/$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
@$(MKDIR) -p $(dir $@) 2>/dev/null || true
@$(PRINTF) "[ $(PROJECT): %s ]"$(END) $@
@$(CC) $(DBG_CFLAGS) $(CPPFLAGS) -c $< -o $@
@$(PRINTF) $(UP)
#------------------------------------------------#
# LIBRARY-RULES |
#------------------------------------------------#
### LIBFT
libft: $(LIB_FT)
$(LIB_FT): FORCE
make -sC $(LIB_FT_DIR)
libft_clean:
make -sC $(LIB_FT_DIR) clean
libft_cleandbg:
make -sC $(LIB_FT_DIR) dbgclean
libft_fclean:
make -sC $(LIB_FT_DIR) fclean
### Library Clean Rules
libclean: libft_clean
libcleandbg: libft_cleandbg
libfclean: libft_fclean
#------------------------------------------------#
# CLEAN-RULES |
#------------------------------------------------#
thisclean:
@if [ -d $(REL_PATH)/$(OBJ_PATH) ]; then \
$(RM) -f $(REL_OBJ) \
&& $(RM) -rf $(REL_PATH)/$(OBJ_PATH) \
&& $(PRINTF) $(DEL)"[ $(PROJECT): All object files cleaned ]"$(END); \
fi
thiscleandbg:
@if [ -d $(DBG_PATH)/$(OBJ_PATH) ]; then \
$(RM) -f $(DBG_OBJ) \
&& $(RM) -rf $(DBG_PATH)/$(OBJ_PATH) \
&& $(PRINTF) $(DEL)"[ $(PROJECT): All debug object files cleaned ]"$(END); \
fi
clean: libclean thisclean
cleandbg: libclean thiscleandbg
fclean: libfclean thisclean thiscleandbg
@for TARGET in $(NAME) $(DBG); do \
if [ -e "$$TARGET" ]; then \
$(RM) -f $$TARGET \
&& $(PRINTF) $(DEL)"[ $(PROJECT): $$TARGET cleaned ]"$(END); \
fi; \
done
ifneq '$(REL_PATH)' '.'
@$(RM) -rf $(REL_PATH)
endif
ifneq '$(DBG_PATH)' '.'
@$(RM) -rf $(DBG_PATH)
endif
#------------------------------------------------#
# OTHER-RULES |
#------------------------------------------------#
soft: thisclean all
softdbg: thiscleandbg dbg
shallow: soft softdbg
re: fclean all
redbg: fclean dbg
full: fclean all dbg
clear: all clean
cleardbg: dbg cleandbg
pure: clear cleardbg
whole: all dbg
FORCE:
norme:
$(NORMINETTE) $(SRC) includes/*.h
update_libft:
$(RM) -rf $(LIB_FT_DIR)
git clone http://gitlab.com/abaisago/42_libft $(LIB_FT_DIR)
$(RM) -rf $(LIB_FT_DIR)/.git* $(LIB_FT_DIR)/tags
update_libht:
$(RM) -rf $(LIB_HT_DIR)
git clone http://gitlab.com/abaisago/libht $(LIB_HT_DIR)
$(RM) -rf $(LIB_HT_DIR)/.git* $(LIB_HT_DIR)/tags