-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
371 lines (315 loc) · 13.6 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# **************************************************************************** #
# #
# :::::::: #
# Makefile :+: :+: #
# +:+ #
# By: sverschu <[email protected]> +#+ #
# +#+ #
# Created: 2020/08/25 18:13:09 by sverschu #+# #+# #
# Updated: 2020/10/25 22:48:32 by sverschu ######## odam.nl #
# #
# **************************************************************************** #
NAME = libexectree.a
# internal libraries ########################################################
COMMON = common.a
TREE = node.a
LOGGER = logger.a
GRAMMARGENERATOR = grammargenerator.a
LEXER = lexer.a
PARSER = parser.a
ALLDEPS = $(COMMON) $(TREE) $(LOGGER) $(GRAMMARGENERATOR) $(LEXER) $(PARSER)
# directories ###############################################################
SRC_D = src
OBJ_D = obj
INC_D = inc
LIB_D = lib
# common source files #######################################################
SRC = $(SRC_D)/common/exectree_lifetime.c \
$(SRC_D)/common/exectree_parse.c \
OBJ := $(SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)
# tree source files #########################################################
TREE_SRC = $(SRC_D)/tree/node_lifetime.c \
$(SRC_D)/tree/tree_lifetime.c \
TREE_OBJ := $(TREE_SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)
### logger source files
LOG_SRC= $(SRC_D)/logger/logger.c \
LOG_OBJ := $(LOG_SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)
### grammar generator source files
GG_SRC = $(SRC_D)/grammargenerator/grammar_ir.c \
$(SRC_D)/grammargenerator/grammar_ir_lifetime.c \
$(SRC_D)/grammargenerator/gg_process_production.c \
$(SRC_D)/grammargenerator/gg_process_rules.c \
$(SRC_D)/grammargenerator/gg_process_nonterminal.c \
$(SRC_D)/grammargenerator/gg_process_terminal.c \
$(SRC_D)/grammargenerator/gg_rule_lifetime.c \
$(SRC_D)/grammargenerator/gg_production_lifetime.c \
$(SRC_D)/grammargenerator/gg_token_lifetime.c \
$(SRC_D)/grammargenerator/gg_dump.c \
$(SRC_D)/grammargenerator/gg_search.c \
$(SRC_D)/grammargenerator/gg_post_processing.c \
$(SRC_D)/grammargenerator/gg_jumptable.c \
GG_OBJ := $(GG_SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)
### lexer source files
LEX_SRC = $(SRC_D)/lexer/lexer.c \
LEX_OBJ := $(LEX_SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)
### parser source files
PARSE_SRC = $(SRC_D)/parser/parser.c \
PARSE_OBJ := $(PARSE_SRC:$(SRC_D)/%.c=$(OBJ_D)/%.o)
# dependencies ##############################################################
LIBGNL=lib/libgnl/libgnl.a
LIBFT=lib/libft/libft.a
LIBVECTOR=lib/libvector/libvector.a
LIB_INC= -I$(LIB_D)/libgnl/inc \
-I$(LIB_D)/libft/inc \
-I$(LIB_D)/libvector/inc \
# output format #############################################################
CC_LOG=./.cc.log
CC_ERROR=./.cc.error
NO_COLOR=\x1b[0m
OK_COLOR=\x1b[32;01m
ERROR_COLOR=\x1b[31;01m
WARN_COLOR=\x1b[33;01m
OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)
ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)
WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)
# warriors of choice ########################################################
ECHO=printf
CAT=cat
# compiler and linker #######################################################
CC = clang
LD = ar
LT = libtool
# compile, linker and test flags ############################################
CC_FLAGS = -Wall -Wextra -Werror
LD_FLAGS = -rcs
LT_FLAGS = --tag CXX --mode=link cc
T_FLAGS = -lcriterion
# debugging or optimilization flags #########################################
CC_OPT_FLAGS = -O3 \
-march=native
ifeq ($(ASAN),1)
CC_FLAGS += -fsanitize=address \
-fno-optimize-sibling-calls
LD_FLAGS +=
DEBUG = 1
endif
ifeq ($(DEBUG),1)
CC_FLAGS += -g \
-O0 \
-fno-omit-frame-pointer \
-fstack-protector-all \
-DDEBUG
LD_FLAGS +=
else
CC_FLAGS += $(CC_OPT_FLAGS)
LD_FLAGS +=
endif
# os variables ##############################################################
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS = LINUX
CC_FLAGS += -D LINUX -Wno-misleading-indentation
LD_FLAGS +=
endif
ifeq ($(UNAME_S),Darwin)
OS = OSX
CC_FLAGS += -D OSX
LD_FLAGS +=
endif
# daily submodule autoupdate ################################################
GIT_MODULES=.refresh
TIME := $(shell date +'%d')
ifneq ("$(wildcard $(GIT_MODULES))","")
LAST_UPDATE=$(shell cat $(GIT_MODULES))
ifneq ($(LAST_UPDATE),$(TIME))
$(shell rm -f $(GIT_MODULES))
endif
endif
# make commands #############################################################
all: $(NAME)
$(GIT_MODULES):
@$(ECHO) "Updating submodules..."
@git submodule update --init --remote
@$(ECHO) $(shell date +'%d') > $(GIT_MODULES)
@$(ECHO) "$(OK_STRING)\n"
submodule:
@git submodule update --init --remote --recursive
# this is incredibly hacky, but there seems to be no other portable way to
# combine static libs using standard makefiles...
# https://stackoverflow.com/questions/24954747/how-to-use-libtool-to-create
# -a-static-library-from-a-bunch-of-static-libraries
$(NAME): $(ALLDEPS)
@$(ECHO) "Linking $(NAME)..."
@mkdir -p artmp
@list='$^'; for p in $$list; do \
(cd artmp; ar x "../$$p"; ar q "../$@" *.o; rm *.o) || false 2>$(CC_LOG); done
@rm -rf artmp
@ranlib $@ 2> $(CC_LOG) || touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(COMMON): $(GIT_MODULES) $(LIBGNL) $(LIBFT) $(LOGGER) $(OBJ_D) $(OBJ)
@$(ECHO) "Linking $(COMMON)..."
@$(LD) $(LD_FLAGS) $(COMMON) $(OBJ) 2>$(CC_LOG) || touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(TREE): $(GIT_MODULES) $(LIBFT) $(LOGGER) $(OBJ_D) $(TREE_OBJ)
@$(ECHO) "Linking $(TREE)..."
@$(LD) $(LD_FLAGS) $(TREE) $(TREE_OBJ) 2>$(CC_LOG) || touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(LOGGER): $(GIT_MODULES) $(LIBFT) $(OBJ_D) $(LOG_OBJ)
@$(ECHO) "Linking $(LOGGER)..."
@$(LD) $(LD_FLAGS) $(LOGGER) $(LOG_OBJ) 2>$(CC_LOG) || touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(GRAMMARGENERATOR): $(GIT_MODULES) $(LIBGNL) $(LIBFT) $(LIBVECTOR) $(LOGGER)\
$(OBJ_D) $(GG_OBJ)
@$(ECHO) "Linking $(GRAMMARGENERATOR)..."
@$(LD) $(LD_FLAGS) $(GRAMMARGENERATOR) $(GG_OBJ) 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(LEXER): $(GIT_MODULES) $(LIBFT) $(LIBVECTOR) $(LOGGER) \
$(OBJ_D) $(LEX_OBJ)
@$(ECHO) "Linking $(LEXER)..."
@$(LD) $(LD_FLAGS) $(LEXER) $(LEX_OBJ) 2>$(CC_LOG) || touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(PARSER): $(GIT_MODULES) $(LIBFT) $(LIBVECTOR) $(LOGGER) \
$(OBJ_D) $(PARSE_OBJ)
@$(ECHO) "Linking $(PARSER)..."
@$(LD) $(LD_FLAGS) $(PARSER) $(PARSE_OBJ) 2>$(CC_LOG) || touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG) && false; elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(OBJ_D):
@mkdir -p $(OBJ_D)
@mkdir -p $(OBJ_D)/common
@mkdir -p $(OBJ_D)/tree
@mkdir -p $(OBJ_D)/logger
@mkdir -p $(OBJ_D)/grammargenerator
@mkdir -p $(OBJ_D)/lexer
@mkdir -p $(OBJ_D)/parser
$(OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(ECHO) "Compiling $<..."
@$(CC) $(CC_FLAGS) -I$(INC_D) $(LIB_INC) -c $< -o $@ 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(TREE_OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(ECHO) "Compiling $<..."
@$(CC) $(CC_FLAGS) -I$(INC_D) $(LIB_INC) -c $< -o $@ 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(LOG_OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(ECHO) "Compiling $<..."
@$(CC) $(CC_FLAGS) -I$(INC_D) $(LIB_INC) -c $< -o $@ 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(GG_OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(ECHO) "Compiling $<..."
@$(CC) $(CC_FLAGS) -I$(INC_D) $(LIB_INC) -c $< -o $@ 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(LEX_OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(ECHO) "Compiling $<..."
@$(CC) $(CC_FLAGS) -I$(INC_D) $(LIB_INC) -c $< -o $@ 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(PARSE_OBJ): $(OBJ_D)/%.o: $(SRC_D)/%.c
@$(ECHO) "Compiling $<..."
@$(CC) $(CC_FLAGS) -I$(INC_D) $(LIB_INC) -c $< -o $@ 2>$(CC_LOG) \
|| touch $(CC_ERROR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(RM) -f $(CC_LOG) $(CC_ERROR)
$(LIBGNL):
@$(MAKE) -C $(LIB_D)/libgnl
$(LIBFT):
@$(MAKE) -C $(LIB_D)/libft
$(LIBVECTOR):
@$(MAKE) -C $(LIB_D)/libvector
clean:
@$(RM) $(OBJ)
@$(RM) -r *.dSYM
@$(RM) *.testbin
@$(RM) -r artmp
@$(RM) -r $(OBJ_D)
@$(MAKE) -C $(LIB_D)/libgnl clean || true
@$(MAKE) -C $(LIB_D)/libft clean || true
@$(MAKE) -C $(LIB_D)/libvector clean || true
fclean: clean
@$(RM) $(ALLDEPS) $(NAME)
@$(MAKE) -C $(LIB_D)/libgnl fclean || true
@$(MAKE) -C $(LIB_D)/libft fclean || true
@$(MAKE) -C $(LIB_D)/libvector fclean || true
norm:
@norminette $(SRC) $(INC)
re: fclean all
basics_test: TEST='basics_t'
basics_test: $(ALLDEPS) $(NAME)
@$(ECHO) "Compiling $(TEST).c..." 2>$(CC_LOG) || touch $(CC_ERROR)
@$(CC) $(CC_FLAGS) $(T_FLAGS) -I$(INC_D) $(LIB_INC)-o $(TEST).testbin \
tests/$(TEST).c $(NAME) $(ALLDEPS) $(LIBGNL) $(LIBFT) $(LIBVECTOR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(ECHO) "Running $(TEST)...\n"
@$(DBG) ./$(TEST).testbin examples/bash.bnf "$(CMD)"
@$(RM) -f $(CC_LOG) $(CC_ERROR)
grammargenerator_test: TEST='grammargenerator_t'
grammargenerator_test: $(GRAMMARGENERATOR)
@$(ECHO) "Compiling $(TEST).c..." 2>$(CC_LOG) || touch $(CC_ERROR)
@$(CC) $(CC_FLAGS) $(T_FLAGS) -I$(INC_D) $(LIB_INC) -o $(TEST).testbin \
tests/$(TEST).c $(ALLDEPS) $(LIBGNL) $(LIBFT) $(LIBVECTOR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(ECHO) "Running $(TEST)...\n"
@$(DBG) ./$(TEST).testbin examples/bash.bnf
@$(RM) -f $(CC_LOG) $(CC_ERROR)
lexer_test: TEST='lexer_t'
lexer_test: $(GRAMMARGENERATOR) $(LEXER)
@$(ECHO) "Compiling $(TEST).c..." 2>$(CC_LOG) || touch $(CC_ERROR)
@$(CC) $(CC_FLAGS) $(T_FLAGS) -I$(INC_D) $(LIB_INC) -o $(TEST).testbin \
tests/$(TEST).c $(ALLDEPS) $(LOGGER) $(LIBGNL) $(LIBFT) $(LIBVECTOR)
@if test -e $(CC_ERROR); then $(ECHO) "$(ERROR_STRING)\n" \
&& $(CAT) $(CC_LOG); elif test -s $(CC_LOG); then $(ECHO) \
"$(WARN_STRING)\n" && $(CAT) $(CC_LOG); else $(ECHO) "$(OK_STRING)\n"; fi
@$(ECHO) "Running $(TEST)...\n"
@$(DBG) ./$(TEST).testbin examples/bash.bnf "$(CMD)"
@$(RM) -f $(CC_LOG) $(CC_ERROR)
tests:
@$(MAKE) ASAN=1 re
@$(MAKE) ASAN=1 basics_test
@$(MAKE) ASAN=1 grammargenerator_test
@$(MAKE) ASAN=1 lexer_test
.PHONY: all clean fclean re tests