-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
146 lines (126 loc) · 2.75 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
# base dir and target config
NAME := minishell
SRCS_DIR := ./srcs
OBJS_DIR := ./objs
### source files
SRCS := main.c \
token.c \
token_utils.c \
tokenizer.c \
tokenizer_ctype.c \
tokenizer_main.c \
tokenizer_word.c \
tokenizer_redirect.c \
tokenizer_pipeline.c \
ast.c \
ast_utils.c \
parser.c \
parser_main.c \
parser_simple_command.c \
parser_utils.c \
parser_redirect.c \
expander.c \
expander_utils.c \
expander_utils2.c \
expander_parameter.c \
expander_double_quotes.c \
expander_quotes1.c \
exec_main.c \
exec_cmd.c \
exec_dealloc.c \
exec_binary.c \
exec_parent.c \
exec_build.c \
exec_redirect.c \
exec_redirect_prepare.c \
exec_redirect_set.c \
exec_pipes.c \
exec_heredoc.c \
exec_path_utils.c \
err_main.c \
err_parser.c \
err_builtin.c \
err_exec.c \
path_dir_split.c \
path_dir_utils.c \
path_utils.c \
ft_strcmp.c \
ft_strndup.c \
env_main.c \
env_add.c \
env_delete.c \
env_get.c \
env_utils.c \
env_load_environ.c \
builtin.c \
builtin_echo.c \
builtin_cd.c \
builtin_pwd.c \
builtin_export.c \
builtin_export_print.c \
builtin_unset.c \
builtin_env.c \
builtin_exit.c \
builtin_dir_utils.c \
builtin_cd_dir_cannon.c \
signal.c \
SRCS := $(addprefix $(SRCS_DIR)/, $(SRCS))
OBJS := $(patsubst $(SRCS_DIR)/%.c,$(OBJS_DIR)/%.o,$(SRCS))
DEPS := $(OBJS:.o=.d)
### include settings
INC_DIR = $(sort $(dir $(SRCS))) $(LIBFT_INC_DIR) $(RL_INC_DIR)
INCLUDES = $(addprefix -I, $(INC_DIR))
### library settings
# libft
LIBFT_DIR := ./libft
LIBFT := ./libft/libft.a
LIBFT_NAME := ft
LIBFT_INC_DIR := ./libft/includes
# Get target OS name
UNAME := $(shell uname)
# readline
RL_NAME := readline
ifeq ($(UNAME), Darwin)
RL_DIR := $(shell brew --prefix readline)
RL_LIB_DIR := $(addprefix $(RL_DIR)/, lib)
RL_INC_DIR := $(addprefix $(RL_DIR)/, include)
endif
LIBS := $(LIBFT_NAME) $(RL_NAME)
LIB_DIR := $(LIBFT_DIR) $(RL_LIB_DIR)
LIB_DIR := $(addprefix -L, $(LIB_DIR))
LFLAGS := $(addprefix -l, $(LIBS))
LDFLAGS := $(LIB_DIR) $(LFLAGS)
### compiler settings
CC := cc
CFLAGS := -Wall -Wextra -Werror -MMD -MP
# CFLAGS += -g
# CFLAGS += -fsanitize=undefined
# CFLAGS += -fsanitize=address
MAKE := make
RM := rm -rf
.PHONY: all
all: $(NAME)
$(NAME): $(LIBFT) $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(NAME)
$(OBJS_DIR)/%.o: $(SRCS_DIR)/%.c
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<
.PHONY: clean
clean:
$(MAKE) clean -C $(LIBFT_DIR)
$(RM) $(OBJS_DIR)
.PHONY: fclean
fclean: clean
$(MAKE) fclean -C $(LIBFT_DIR)
$(RM) $(NAME)
.PHONY: re
re: fclean all
.PHONY: t
t: all
python3 ./tests/test.py
.PHONY: norm
norm:
-@norminette srcs/ | grep -v "INVALID_HEADER"
$(LIBFT):
$(MAKE) -C $(LIBFT_DIR)
-include $(DEPS)