-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (115 loc) · 2.92 KB
/
Copy pathMakefile
File metadata and controls
142 lines (115 loc) · 2.92 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
#
# Macros
#
NAME = minishell
CC = cc
CFLAGS = -Wall -Wextra -Werror
SRC = src/
INCLUDE = include/
HEADER = minishell.h executor.h parser.h lexer.h
HEADER := $(addprefix $(INCLUDE), $(HEADER))
UTILS_FILES = utils/io_utils1.c \
utils/io_utils2.c \
utils/error_utils.c \
utils/env_utils1.c \
utils/env_utils2.c \
utils/env_utils3.c \
utils/global_utils1.c \
utils/global_utils2.c \
utils/global_utils3.c \
utils/global_utils4.c \
utils/display_utils.c
BUILTINS_FILES = builtins/cd_cmd.c \
builtins/pwd_cmd.c \
builtins/echo_cmd.c \
builtins/exit_cmd.c \
builtins/unset_cmd.c \
builtins/env_cmd.c \
builtins/export_cmd.c
TOKENZIER_FILES = tokenizer/lexer.c \
tokenizer/tokenizer.c \
tokenizer/tokenizer_utils.c \
tokenizer/list_constructor_utils.c \
tokenizer/list_destructor_utils.c
EXECUTOR_FILES = executor/ft_execvp.c \
executor/exec_utils.c \
executor/executor.c \
executor/executor_utils1.c \
executor/executor_utils2.c
PARSER_FILES = parser/astree_constructors.c \
parser/parser_helpers.c \
parser/parser_utils1.c \
parser/parser_utils2.c \
parser/parser.c
SYNTAX_UTILS = syntax_analyser/syntax_analyser.c \
syntax_analyser/syntax_utils.c
EXPANDER_FILES = expander/expander.c \
expander/expander_utils1.c \
expander/expander_utils2.c \
expander/wildcard_matching.c
FILES = minishell.c \
$(UTILS_FILES) \
$(BUILTINS_FILES) \
$(TOKENZIER_FILES) \
$(SYNTAX_UTILS) \
$(EXPANDER_FILES) \
$(PARSER_FILES) \
$(EXECUTOR_FILES) \
OBJS = $(FILES:%.c=%.o)
OBJS := $(addprefix $(SRC), $(OBJS))
# readline: on macOS use the Homebrew prefix, on Linux rely on system paths
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
RL_PREFIX := $(shell brew --prefix readline 2>/dev/null)
RL_INC := -I$(RL_PREFIX)/include
RL_LIB := -L$(RL_PREFIX)/lib
else
RL_INC :=
RL_LIB :=
endif
LIBFT_PATH = libft/
LIBFT = $(addprefix $(LIBFT_PATH), libft.a)
LIBGC_PATH = libgc/
LIBGC = $(addprefix $(LIBGC_PATH), libgc.a)
#
# Rules
#
# All
all: $(NAME)
# Debug
debug: CFLAGS+=-g
debug: clean $(NAME)
# minishell
$(NAME): $(LIBFT) $(LIBGC)
$(NAME): $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ -lreadline -lm $(RL_LIB)
# libft
$(LIBFT): $(addprefix $(LIBFT_PATH), libft.h)
make -C $(LIBFT_PATH) all clean
# libgc
$(LIBGC): $(addprefix $(LIBGC_PATH), include/gc.h)
make -C $(LIBGC_PATH) all clean
# object files
%.o: %.c $(HEADER)
$(CC) $(CFLAGS) -c $< -o $@ -I $(INCLUDE) $(RL_INC) -I $(LIBFT_PATH) -I $(addprefix $(LIBGC_PATH), include)
# tests
test: $(NAME)
bash tests/run_tests.sh
# parser fuzz (override via FUZZ_ITER / FUZZ_LINES / FUZZ_LINELEN)
fuzz: $(NAME)
ITERATIONS=$(FUZZ_ITER) LINES_PER_RUN=$(FUZZ_LINES) LINE_LEN=$(FUZZ_LINELEN) \
bash tests/fuzz.sh
FUZZ_ITER ?= 100
FUZZ_LINES ?= 30
FUZZ_LINELEN ?= 80
# clean
clean:
rm -f $(OBJS)
# full clean
fclean: clean
rm -f $(NAME)
make -C $(LIBFT_PATH) fclean
make -C $(LIBGC_PATH) fclean
# remake
re: fclean all
.PHONY: all debug test fuzz clean fclean re