-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
348 lines (305 loc) · 11.2 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
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
341
342
343
344
345
346
347
348
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: alelievr <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2014/07/15 15:13:38 by alelievr #+# #+# #
# Updated: 2018/02/16 19:10:35 by alelievr ### ########.fr #
# #
# **************************************************************************** #
#################
## VARIABLES ##
#################
# Sources
SRCDIR = src
SRC = main.cpp \
random_args.cpp \
source_generator.cpp \
# Objects
OBJDIR = obj
# Printf library directory
PRINTFDIR = ../ft_printf/
# Variables
LIBFT = 2 #1 or 0 to include the libft / 2 for autodetct
DEBUGLEVEL = 0 #can be 0 for no debug 1 for or 2 for harder debug
#Warrning: non null debuglevel will disable optlevel
OPTLEVEL = 1 #same than debuglevel
#Warrning: non null optlevel will disable debuglevel
CPPVERSION = c++11
#For simpler and faster use, use commnd line variables DEBUG and OPTI:
#Example $> make DEBUG=2 will set debuglevel to 2
# Includes
INCDIRS = inc
# Libraries
LIBDIRS =
LDLIBS =
# Spec
FINAL_PRINTF_LIB = printf-tests.so
ASSETS_DIR = assets
TMP_LIB_FTPRINTF = $(ASSETS_DIR)/tmp
LIB_FTPRINTF_SO = libftprintf.so
# Output
NAME = run_test
LIB_FTPRINTF= libftprintf.a
# Compiler
WERROR = #-Werror
CFLAGS = -Wall -Wextra -ferror-limit=999
CPROTECTION = -z execstack -fno-stack-protector
DEBUGFLAGS1 = -O2 -ggdb
DEBUGFLAGS2 = -fsanitize=address
OPTFLAGS1 = -funroll-loops -O2
OPTFLAGS2 = -pipe -funroll-loops -Ofast
# Framework
FRAMEWORK =
#################
## COLORS ##
#################
CPREFIX = "\033[38;5;"
BGPREFIX = "\033[48;5;"
CCLEAR = "\033[0m"
CLINK_T = $(CPREFIX)"129m"
CLINK = $(CPREFIX)"93m"
COBJ_T = $(CPREFIX)"119m"
COBJ = $(CPREFIX)"113m"
CCLEAN_T = $(CPREFIX)"9m"
CCLEAN = $(CPREFIX)"166m"
CRUN_T = $(CPREFIX)"198m"
CRUN = $(CPREFIX)"163m"
CNORM_T = "226m"
CNORM_ERR = "196m"
CNORM_WARN = "202m"
CNORM_OK = "231m"
#################
## OS/PROC ##
#################
OS := $(shell uname -s)
PROC := $(shell uname -p)
DEBUGFLAGS =
LINKDEBUG =
OPTFLAGS =
#COMPILATION =
ifeq "$(OS)" "Windows_NT"
endif
ifeq "$(OS)" "Linux"
LDLIBS +=
DEBUGFLAGS += " -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize=thread"
endif
ifeq "$(OS)" "Darwin"
endif
#################
## AUTO ##
#################
NASM = nasm
OBJS = $(patsubst %.c,%.o, $(filter %.c, $(SRC))) \
$(patsubst %.cpp,%.o, $(filter %.cpp, $(SRC))) \
$(patsubst %.s,%.o, $(filter %.s, $(SRC)))
OBJ = $(addprefix $(OBJDIR)/,$(notdir $(OBJS)))
NORME = **/*.[ch]
VPATH += $(dir $(addprefix $(SRCDIR)/,$(SRC)))
VFRAME = $(addprefix -framework ,$(FRAMEWORK))
INCFILES = $(foreach inc, $(INCDIRS), $(wildcard $(inc)/*.h))
CPPFLAGS = $(addprefix -I,$(INCDIRS))
LDFLAGS = $(addprefix -L,$(LIBDIRS))
LINKER = $(CXX)
disp_indent = for I in `seq 1 $(MAKELEVEL)`; do \
test "$(MAKELEVEL)" '!=' '0' && printf "\t"; \
done
color_exec = $(call disp_indent); \
echo $(1)➤ $(3)$(2)"\n"'$(strip $(4))'$(CCLEAR);$(4)
color_exec_t= $(call disp_indent); \
echo $(1)➤ '$(strip $(3))'$(2)$(CCLEAR);$(3)
ifneq ($(filter 1,$(strip $(DEBUGLEVEL)) ${DEBUG}),)
OPTLEVEL = 0
OPTI = 0
DEBUGFLAGS += $(DEBUGFLAGS1)
endif
ifneq ($(filter 2,$(strip $(DEBUGLEVEL)) ${DEBUG}),)
OPTLEVEL = 0
OPTI = 0
DEBUGFLAGS += $(DEBUGFLAGS1) $(DEBUGFLAGS2)
LINKDEBUG += $(DEBUGFLAGS1) $(DEBUGFLAGS2)
export ASAN_OPTIONS=check_initialization_order=1
endif
ifneq ($(filter 1,$(strip $(OPTLEVEL)) ${OPTI}),)
DEBUGFLAGS =
OPTFLAGS = $(OPTFLAGS1)
endif
ifneq ($(filter 2,$(strip $(OPTLEVEL)) ${OPTI}),)
DEBUGFLAGS =
OPTFLAGS = $(OPTFLAGS1) $(OPTFLAGS2)
endif
ifndef $(CXX)
CXX = clang++
endif
ifneq ($(filter %.cpp,$(SRC)),)
LINKER = $(CXX)
endif
ifdef ${NOWERROR}
WERROR =
endif
ifeq "$(strip $(LIBFT))" "2"
ifneq ($(wildcard ./libft),)
LIBDIRS += "libft"
LDLIBS += "-lft"
INCDIRS += "libft"
endif
endif
#################
## TARGETS ##
#################
# First target
all: $(NAME) printf
# Linking
$(NAME): $(OBJ)
@$(if $(findstring lft,$(LDLIBS)),$(call color_exec_t,$(CCLEAR),$(CCLEAR),\
make -j 4 -C libft))
@$(call color_exec,$(CLINK_T),$(CLINK),"Link of $(NAME):",\
$(LINKER) $(WERROR) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(OPTFLAGS) $(DEBUGFLAGS) $(LINKDEBUG) $(VFRAME) -o $@ $^)
$(OBJDIR)/%.o: %.cpp $(INCFILES)
@mkdir -p $(OBJDIR)/$(dir $<)
@$(call color_exec,$(COBJ_T),$(COBJ),"Object: $@",\
$(CXX) -std=$(CPPVERSION) $(WERROR) $(CFLAGS) $(OPTFLAGS) $(DEBUGFLAGS) $(CPPFLAGS) -o $@ -c $<)
# Objects compilation
$(OBJDIR)/%.o: %.c $(INCFILES)
@mkdir -p $(OBJDIR)/$(dir $<)
@$(call color_exec,$(COBJ_T),$(COBJ),"Object: $@",\
$(CC) $(WERROR) $(CFLAGS) $(OPTFLAGS) $(DEBUGFLAGS) $(CPPFLAGS) -o $@ -c $<)
$(OBJDIR)/%.o: %.s
@mkdir -p $(OBJDIR)/$(dir $<)
@$(call color_exec,$(COBJ_T),$(COBJ),"Object: $@",\
$(NASM) -f macho64 -o $@ $<)
# Removing objects
clean:
@$(call color_exec,$(CCLEAN_T),$(CCLEAN),"Clean:",\
$(RM) $(OBJ))
@rm -rf $(OBJDIR)
@rm -rf $(TMP_LIB_FTPRINTF)
@rm -rf $(ASSETS_DIR)/libftprintf.a
# Removing objects and exe
fclean: clean
@$(call color_exec,$(CCLEAN_T),$(CCLEAN),"Fclean:",\
$(RM) $(NAME) $(LIB_FTPRINTF_SO))
printf:
@mkdir -p $(ASSETS_DIR)
@make -C "$(PRINTFDIR)"
@cp "$(PRINTFDIR)"/$(LIB_FTPRINTF) $(ASSETS_DIR)
@rm -rf $(TMP_LIB_FTPRINTF)
@mkdir -p $(TMP_LIB_FTPRINTF)
@$(call color_exec,$(CLINK_T),$(CLINK),"Creating libftprintf.so lib",\
cd $(TMP_LIB_FTPRINTF) && ar -xv ../$(LIB_FTPRINTF) >/dev/null && $(CC) -shared -fPIC *.o -o $(LIB_FTPRINTF_SO) && cp $(LIB_FTPRINTF_SO) ../..)
# All removing then compiling
re: fclean all
f: all printf run
# Checking norme
norme:
@norminette $(NORME) | sed "s/Norme/[38;5;$(CNORM_T)➤ [38;5;$(CNORM_OK)Norme/g;s/Warning/[0;$(CNORM_WARN)Warning/g;s/Error/[0;$(CNORM_ERR)Error/g"
run: $(NAME)
@echo $(CRUN_T)"➤ "$(CRUN)"./$(NAME) ${ARGS}\033[0m"
@./$(NAME) ${ARGS}
codesize:
@cat $(NORME) |grep -v '/\*' |wc -l
functions: $(NAME)
@nm $(NAME) | grep U
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.5
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.5
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.5
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
.PHONY: all clean fclean re norme codesize