-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
126 lines (101 loc) · 2.86 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
# ===== Target & FLAGS =====
NAME := minishell
CC := clang
CFLAGS := -Wall -Wextra -Werror
RM := rm -rf
PRE := src
INC := -I ~/.brew/opt/readline/include -I./include/ -I./lib/include
LIB := -L ~/.brew/opt/readline/lib -lreadline -L./lib -lft
LIBFT := lib/libft.a
# ===== Test & Debugging =====
DFLAGS := -g3 #-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
VFLAGS := --leak-check=full --show-leak-kinds=all \
--track-fds=yes \
--track-origins=yes --suppressions=./supp_mac.txt \
--suppressions=./supp.txt
HGEN := hgen
# ===== Packages =====
PKGS := scanner lexer parser \
api shell prompt tree errormsg \
open exec pipe builtin
# AST
scannerV := scanner scanner_list expansion util util2 util3 \
dollar_scan1 dollar_scan2 metachar_scan1 metachar_scan2
lexerV := lexer tokenizer util
parserV := parser new1 new2 del util1 util2 expander1 expander2 heredoc_parser
# Shell API
apiV := signal path tilde util env1 env2
shellV := shell script
promptV := prompt interrupt ps check util
treeV := repr1 repr2
errormsgV:= error
# Script
openV := open redirect heredoc file check
execV := context exec argv util
pipeV := pipe send status util
builtinV := builtin cd echo exit env export unset pwd util check
# ===== Macros =====
define choose_modules
$(foreach pkg, $(1),\
$(foreach file, $($(pkg)V),\
$(PRE)/$(pkg)/$(file).c\
)\
) $(PRE)/main.c
endef
# ===== Sources & Objects & Include =====
SRC := $(call choose_modules, $(PKGS))
OBJ := $(SRC:%.c=%.o)
# ===== Rules =====
.PHONY: all re clean fclean test red docs
%.o: %.c
@printf "$(Y)%-10s$(WU)$(<F)$(R) -> $(E)$(@F)\n" [$(subst src/,,$(*D))]
@$(CC) $(CFLAGS) $(DFLAGS) $(INC) -c -o $@ $<
$(NAME): $(OBJ) $(LIBFT)
@$(CC) $(CFLAGS) $(INC) $(LIB) $^ -o $@
@$(call log, V, 🚀 linked with flag $(R)$(DFLAGS)$(E)$(CFLAGS))
$(LIBFT):
@make --no-print-directory all -C lib/ DFLAGS="$(DFLAGS)"
all: $(NAME)
clean:
@$(RM) $(OBJ)
@$(call log, G, 🗑 cleaned $(NAME)'s object files)
fclean: clean
@$(RM) $(NAME)
@$(call log, G, 🗑 cleaned $(NAME))
tclean: fclean
@make fclean -C lib
@$(call log, G, 🗑 Remove $(LIBFT))
re: fclean all
# ===== Custom Rules =====
docs:
@make --no-print-directory docs -C lib/
@set -e;\
for p in $(PKGS); do\
$(HGEN) -I include/$$p.h src/$$p 1> /dev/null;\
done
run: docs all
@./$(NAME)
leak: docs all cls
@$(call log, Y, 🧪 Running Leak Test)
@valgrind $(VFLAGS) ./$(NAME)
supp: docs all cls
@$(call log, Y, Creating Leak Suppressions,...)
@valgrind $(VFLAGS) \
--log-file=supp3.txt\
--gen-suppressions=all ./$(NAME)
# ===== Colors =====
cls:
@set -e; clear
R ?= \033[0;91m
WU ?= \033[4;37m
C ?= \033[0;96m
CU ?= \033[4;36m
Y ?= \033[0;33m
YU ?= \033[4;33m
G ?= \033[0;92m
V ?= \033[0;35m
E ?= \033[0m
BD ?= \033[1m
define log
printf "$($(strip $(1)))$(strip $(2))$(strip $(3))$(E)\n"
endef