-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
340 lines (278 loc) · 9 KB
/
Makefile
File metadata and controls
340 lines (278 loc) · 9 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: ldevelle <ldevelle@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/11/12 15:04:16 by ldevelle #+# #+# #
# Updated: 2020/04/12 13:58:06 by ezalos ### ########.fr #
# #
# **************************************************************************** #
include init.mk
CC = gcc
AR = ar -rcs
##########################
## ##
## ARCHITECTURE ##
## ##
##########################
MAIN_FOLD = $(shell find srcs -maxdepth 1 -type d | grep '/' | cut -d '/' -f 2)
MASTER = srcs/
$(shell mkdir -p $(MASTER))
#AUTO_HEAD = $(MAIN_FOLD:%=auto/auto_%.h)
AUTO_HEAD = auto_$(NAME).h
HEAD = $(HEADERS:%=$(HEAD_DIR)%)
mk = ./.makegenius
mk_p = $(mk)/srcs_path/
include_pat = $(MAIN_FOLD:%=$(mk_p)pat_%.mk)
include_pat += $(mk_p)pat_.mk
include_dep = $(include_pat)
PAT =
$(shell mkdir -p $(mk) $(mk_p))
$(shell touch $(include_dep))
include $(include_dep)
OBJ = $(PAT:%.c=%.o)
OBJS = $(PAT:$(MASTER)%.c=$(DIR_OBJ)%.o)
ARG ?= ldevelle
MSG ?= "Automated commit message!"
SUPPORTED_COMMANDS := run
SUPPORTS_MAKE_ARGS := $(findstring $(firstword $(MAKECMDGOALS)), $(SUPPORTED_COMMANDS))
ifneq "$(SUPPORTS_MAKE_ARGS)" ""
COMMAND_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(COMMAND_ARGS):;@:)
endif
##########################
## ##
## FLAGS ##
## ##
##########################
ifeq ($(f), no)
CFLAGS +=
VALGRIND =
else ifeq ($(f), n)
CFLAGS =
VALGRIND =
else ifeq ($(f), f)
CFLAGS += -fsanitize=address,undefined -g3
VALGRIND =
else ifeq ($(f), v)
CFLAGS += -g3
SHOW_LEAK = --show-leak-kinds=definite
VALGRIND = valgrind --track-origins=yes --leak-check=full $(SHOW_LEAK)
else ifeq ($(f), h)
CFLAGS = -fsanitize=address,undefined -g3 -pedantic\
-ansi -O2 -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int\
-Werror-implicit-function-declaration -Wmain -Wparentheses -Wsequence-point\
-Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas\
-Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast\
-Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return\
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations\
-Wmissing-noreturn -Wformat -Wmissing-format-attribute\
-Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs\
-Winline -Wlong-long -Wunreachable-code
VALGRIND =
endif
##########################
## ##
## COLORS ##
## ##
##########################
UNAME := $(shell uname)
ifeq ($(UNAME),Linux)
RED = \e[31m
GREEN = \e[32m
YELLOW = \e[33m
BLUE = \e[34m
MAGENTA = \e[35m
CYAN = \e[36m
END = \e[0m
else
RED = \x1b[31m
GREEN = \x1b[32m
YELLOW = \x1b[33m
BLUE = \x1b[34m
MAGENTA = \x1b[35m
CYAN = \x1b[36m
END = \x1b[0m
endif
COM_COLOR = $(BLUE)
OBJ_COLOR = $(CYAN)
OK_COLOR = $(GREEN)
ERROR_COLOR = $(RED)
WARN_COLOR = $(YELLOW)
NO_COLOR = $(END)
OK_STRING = [OK]
ERROR_STRING = [ERROR]
WARN_STRING = [WARNING]
COM_STRING = Compiling
##########################
## ##
## OUTPUT ##
## ##
##########################
define run_and_test
printf "%b" "$(COM_COLOR)$(COM_STRING) $(OBJ_COLOR)$(@F)$(NO_COLOR)\r"; \
$(1) 2> $@.log; \
RESULT=$$?; \
if [ $$RESULT -ne 0 ]; then \
printf "%-60b%b" "$(COM_COLOR)$(COM_STRING)$(OBJ_COLOR) $@" "$(ERROR_COLOR)$(ERROR_STRING)$(NO_COLOR)\n" ; \
elif [ -s $@.log ]; then \
printf "%-60b%b" "$(COM_COLOR)$(COM_STRING)$(OBJ_COLOR) $@" "$(WARN_COLOR)$(WARN_STRING)$(NO_COLOR)\n" ; \
else \
printf "%-60b%b" "$(COM_COLOR)$(COM_STRING)$(OBJ_COLOR) $(@F)" "$(OK_COLOR)$(OK_STRING)$(NO_COLOR)\n" ; \
fi; \
cat $@.log; \
rm -f $@.log; \
exit $$RESULT
endef
##############################################################################
##############################################################################
## ##
## ----- ##
## RULES ##
## ----- ##
## ##
##############################################################################
##############################################################################
##########################
## ##
## BASIC ##
## ##
##########################
all : $(modules) $(NAME) auteur $(DIR_OBJ)
ifeq ($(LIB_PRJCT),y)
$(NAME): $(OBJS) $(HEAD_DIR)
@$(call run_and_test, $(AR) $(NAME) $(OBJS))
else
$(NAME): $(LIB) $(OBJS) $(HEAD_DIR)
@$(call run_and_test, $(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LIB) $(HEADERS_DIRECTORIES))
endif
$(DIR_OBJ)%.o:$(MASTER)%.c $(HEAD) Makefile
@mkdir -p $(DIR_OBJ)
@$(call run_and_test, $(CC) $(CFLAGS) $(HEADERS_DIRECTORIES) -o $@ -c $<)
$(LIB): FORCE
$(MAKE) -C $(LIB_DIR)
clean :
rm -f $(OBJS)
echo "\$(YELLOW)$(NAME) objs \$(END)\\thas been \$(GREEN)\\t\\t\\t $@\$(END)"
fclean : clean
rm -rf $(NAME) $(DIR_OBJ)
echo "\$(YELLOW)$(NAME) \$(END)\\thas been \$(GREEN)\\t\\t\\t $@\$(END)"
re : fclean
$(MAKE) all
rere :
$(MAKE) re -C $(LIB_DIR)
$(MAKE) re
auteur : Makefile
echo $(login) > auteur
$(DIR_OBJ) :
mkdir -p $(DIR_OBJ)
##########################
## ##
## RUN IT ##
## ##
##########################
t : all
$(CC) $(CFLAGS) -I$(HEAD_DIR) $(NAME) main.c -o $(TESTEUR)
$(VALGRIND) ./$(TESTEUR) "$(ARG)"
run : all
$(VALGRIND) ./$(NAME) $(COMMAND_ARGS)
@echo ""
unit_test :
big :
n_times ?= 100
n_times=$(n_times); \
while [ $${n_times} -gt 0 ] ; do \
$(MAKE) unit_test \
done; \
true
##########################
## ##
## GIT ##
## ##
##########################
FETCH_MODULES = $(shell grep "url" .gitmodules | cut -d '=' -f 2)
GIT_MODULES = $(FETCH_MODULES:%=git clone % ; )
init:
sh ./.makegenius/scripts/init_makegenius.sh
echo -n "Do you wish to puh your project on github ?" && read ans && [ $${ans:-N} = y ]
$(MAKE) init_git
init_git:
rm -rf .git
echo "# $(NAME)" > README.md
git init
git add -A
git commit -m "first commit"
git remote add origin $(GIT_REPO)
git push -u origin master
REQUEST = 'read -p "Enter a commit message: " pwd && echo $$pwd'
COMMIT_MESSAGE ?= $(shell bash -c $(REQUEST))
# $(GIT_VALID) || (echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ])
git :
git add -A
git status
$(GIT_VALID) || (echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ])
git commit -m "$(COMMIT_MESSAGE)"
git push
modules :
$(GIT_MODULES)
##########################
## ##
## AUTOMATE ##
## ##
##########################
ifeq ($(UNAME),Linux)
update_head = bash .makegenius/scripts/get_protos.sh '' $(MASTER) '' $(NAME);
update_dep = bash .makegenius/scripts/get_mk_srcs.sh '' $(MASTER) '' '-depth 1';
else
#update_head = $(MAIN_FOLD:%=sh .makegenius/scripts/get_protos.sh % $(MASTER);)
update_head = bash .makegenius/scripts/get_protos.sh '' $(MASTER) '' $(NAME);
#update_dep = $(MAIN_FOLD:%=sh .makegenius/scripts/get_mk_srcs.sh % $(MASTER);)
update_dep = bash .makegenius/scripts/get_mk_srcs.sh '' $(MASTER) '' '-d 1';
endif
file : sources prototypes
$(MAKE)
sources : object_ready
rm -rf $(mk_p)
mkdir -p $(mk_p)
echo $(update_dep)
$(update_dep)
echo "\$(YELLOW)automatic sources\$(END)\\thas been \$(GREEN)\\t\\t created\$(END)"
DIR_PREP = $(shell find $(MASTER) -type d -exec echo {} \; | sed 's~$(MASTER)~$(DIR_OBJ)~g')
object_ready : $(DIR_OBJ)
rm -rf $(DIR_OBJ)/*
mkdir -p $(DIR_PREP)
find $(DIR_OBJ) -type d -exec touch {}/.gitkeep \;
echo "\$(YELLOW)objects paths\$(END)\\t\\thas been \$(GREEN)\\t\\t created\$(END)"
prototypes : auto_dir
$(update_head)
bash .makegenius/scripts/get_master_head.sh $(HEAD_DIR) $(NAME)
echo "\$(YELLOW)automatic headers\$(END)\\thas been \$(GREEN)\\t\\t created\$(END)"
auto_dir :
mkdir -p $(HEAD_DIR)auto
##########################
## ##
## SELF ##
## ##
##########################
makegenius_repository=https://github.com/ezalos/Makegenius.git
temp_folder=.tmp_makegenius_update/
update :
rm -rf $(temp_folder)
git clone $(makegenius_repository) $(temp_folder)
bash "$(temp_folder).makegenius/scripts/update_makegenius.sh" $(temp_folder) &
rm_update_tmp_dir:
rm -rf $(temp_folder)
##########################
## ##
## PARAMS ##
## ##
##########################
FORCE:
.PHONY : all clean fclean re git file object_ready check update\
rm_update_tmp_dir auto_dir prototypes sources modules\
rere auteur run unit_test big init init_git FORCE
.SILENT : all clean fclean re git file object_ready check update\
rm_update_tmp_dir auto_dir prototypes sources modules\
rere auteur unit_test big init init_git FORCE