-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
230 lines (181 loc) · 6.85 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: dpoveda- <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2021/11/20 13:15:01 by dpoveda- #+# #+# #
# Updated: 2021/12/16 21:34:38 by ### ########.fr # #
# #
# **************************************************************************** #
# **************************************************************************** #
# VARS #
# **************************************************************************** #
# COLORS
NOCOL=\033[0m
RED=\033[31m
GRN=\033[32m
YEL=\033[33m
BLU=\033[34m
MAG=\033[35m
CYN=\033[36m
# OS
UNAME_S := $(shell uname -s)
# **************************************************************************** #
# PROGRAM #
# **************************************************************************** #
NAME = minishell
#NAME = msh
BIN_DIR ?= /usr/local/bin
# **************************************************************************** #
# COMPILER #
# **************************************************************************** #
MAKE = make
CC = gcc
CFLAGS += -Wall -Wextra -Werror
# **************************************************************************** #
# PATHS #
# **************************************************************************** #
SRC_PATH = src
OBJ_PATH = obj
INC_PATH = inc
# **************************************************************************** #
# FLAGS #
# **************************************************************************** #
CFLAGS += -I ./$(INC_PATH)
# **************************************************************************** #
# SOURCES #
# **************************************************************************** #
SRC_DIR_MAIN = main
SRC_DIR_BUILTIN = built-in
SRC_DIR_EXEC = exec
SRC_DIR_LEXER = lexer
SRC_DIR_PARSER = parser
SRC_DIR_PROMPT = prompt
SRC_DIR_UTILS = utils
OBJ_DIRS_NAME = $(SRC_DIR_MAIN) $(SRC_DIR_BUILTIN) $(SRC_DIR_EXEC) \
$(SRC_DIR_LEXER) $(SRC_DIR_PARSER) $(SRC_DIR_PROMPT) \
$(SRC_DIR_UTILS)
OBJ_DIRS = $(addprefix $(OBJ_PATH)/, $(OBJ_DIRS_NAME))
SRC_ROOT = main.c
SRC_MAIN = handle_line.c
SRC_BUILTIN = cd.c echo.c env.c \
exit.c export.c pwd.c \
unset.c cd_error.c export_utils.c \
cd_utils.c unset_utils.c
SRC_EXEC = exec.c exec_ast.c exec_cmd.c \
utils.c exec_heredoc.c heredoc.c \
handle_zombies.c redir.c redir_types.c \
path.c
SRC_LEXER = lexer.c utils_1.c utils_2.c \
pc_gen_st.c pc_other_st.c process_tokens.c \
token_utils.c handle_expand.c expand.c \
wildcards.c wc_match.c wc_match_frag.c \
wc_utils.c wc_check.c
SRC_PARSER = parser.c parser_utils.c ast_utils_1.c \
ast_utils_2.c parse_cmd_line.c parse_and_or_1.c \
parse_and_or_2.c parse_job.c parse_cmd.c \
parse_tok_lst.c parse_redir.c parse_redir_in.c \
parse_redir_out.c
SRC_PROMPT = prompt.c
SRC_UTILS = init.c error_utils.c signals.c \
custom_len.c ft_getenv.c env_utils.c \
init_utils.c read_config.c new_tmp.c
SRC_NAME = $(SRC_ROOT) \
$(addprefix $(SRC_DIR_MAIN)/, $(SRC_MAIN)) \
$(addprefix $(SRC_DIR_BUILTIN)/, $(SRC_BUILTIN)) \
$(addprefix $(SRC_DIR_EXEC)/, $(SRC_EXEC)) \
$(addprefix $(SRC_DIR_LEXER)/, $(SRC_LEXER)) \
$(addprefix $(SRC_DIR_PARSER)/, $(SRC_PARSER)) \
$(addprefix $(SRC_DIR_PROMPT)/, $(SRC_PROMPT)) \
$(addprefix $(SRC_DIR_UTILS)/, $(SRC_UTILS))
OBJ_NAME = $(SRC_NAME:%.c=%.o)
SRC = $(addprefix $(SRC_PATH)/, $(SRC_NAME))
OBJ = $(addprefix $(OBJ_PATH)/, $(OBJ_NAME))
# **************************************************************************** #
# LIBS #
# **************************************************************************** #
LFT_NAME = libft.a
LFT_DIR = libft
LFT = $(LFT_DIR)/$(LFT_NAME)
CFLAGS += -I ./$(LFT_DIR)/$(INC_PATH)
LDFLAGS = -L ./$(LFT_DIR)
LDLIBS = -lft
LDLIBS += -lreadline
# **************************************************************************** #
# RULES #
# **************************************************************************** #
.PHONY: all sanitize thread clean fclean re norme
# ALL
all: $(NAME)
# NAME
$(NAME): $(OBJ) $(LFT_NAME)
@printf "\n${YEL}LINKING:${NOCOL}\n"
@printf "${BLU}"
$(CC) $(CFLAGS) $(OBJ) $(LFT_NAME) -o $@ $(LDFLAGS) $(LDLIBS) $(CCFLAGS)
@printf "${NOCOL}"
@printf "\n${GRN}SUCCESS!${NOCOL}\n"
@printf "${CYN}type \"./$(NAME)\" to start!${NOCOL}\n"
# INSTALL
install: $(NAME)
install $(NAME) $(BIN_DIR)
# SANITIZE ADDRESS
ifeq ($(UNAME_S),Linux)
sanitize: CFLAGS += -pedantic -g3 -fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=bounds -fsanitize=null
endif
ifeq ($(UNAME_S),Darwin)
sanitize: CFLAGS += -pedantic -g3 -fsanitize=address
endif
sanitize: $(NAME)
# SANITIZE THREAD
thread: CFLAGS += -g3 -fsanitize=thread
thread: $(NAME)
# LIBFT
$(LFT_NAME): $(LFT)
@printf "${MAG}"
cp $(LFT) $(LFT_NAME)
@printf "${NOCOL}"
$(LFT):
@printf "\n${YEL}LIBFT:${NOCOL}\n"
@printf "${MAG}"
$(MAKE) all -sC $(LFT_DIR)
@printf "${NOCOL}"
# OBJ
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c | $(OBJ_DIRS)
@printf "${BLU}"
$(CC) $(CFLAGS) -c $< -o $@
@printf "${NOCOL}"
# OBJ DIRS
$(OBJ_DIRS): | $(OBJ_PATH)
@printf "${MAG}"
mkdir -p $(OBJ_DIRS)
@printf "${NOCOL}"
$(OBJ_PATH):
@printf "${MAG}"
mkdir -p $(OBJ_PATH)
@printf "${NOCOL}"
# CLEAN
clean:
@printf "${RED}"
$(MAKE) clean -sC $(LFT_DIR)
rm -rf $(LFT_NAME)
rm -rf $(OBJ_PATH)
@printf "${NOCOL}"
# FULL CLEAN
fclean: clean
@printf "${RED}"
$(MAKE) fclean -sC $(LFT_DIR)
rm -rf $(NAME)
@printf "${NOCOL}"
# RE
re: fclean all
# NORMINETTE
norme:
@printf "\n${GRN}##########${YEL} NORMINETTE ${GRN}##########${NOCOL}\n"
@printf "\n${GRN}LIBFT:${BLU}\n\n"
@norminette $(LFT_DIR)
@printf "\n${GRN}MINISHELL:${BLU}\n\n"
@norminette $(INC_PATH)
@norminette $(SRC_PATH)
@printf "${NOCOL}"