-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
158 lines (132 loc) · 3.2 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
# declare makefile variables
NAME = minishell
BONUS = minishell_bonus
CC = cc
CFLAGS = -Wall -Wextra -Werror -g
RM = rm -f
# libft path and flags
LIBFT = libft.a
LIB_DIR = ./libft
LIB_FLAGS = -L $(LIB_DIR) -lft -lreadline
INC = -I ./includes
#------------------------------------------------------------------------
# minishell targets
# init
INIT = main.c \
init_utils.c \
init_minishell.c \
init_env.c
INIT_SRCS = $(addprefix srcs/init/, $(INIT))
# lexer
LEXER = lexer.c \
lexer_utils.c \
lexer_helper.c \
lexer_list.c \
free_tokens.c \
lexer_symbol.c \
lexer_string.c \
lexer_tokens.c \
lexer_error.c
LEXER_SRCS = $(addprefix srcs/lexer/, $(LEXER))
# parser
PARSER = parser.c \
parser_utils.c \
parser_helper.c \
parser_nodes.c \
parser_cmd.c \
parser_io.c \
parser_redir.c \
free_ast.c
PARSER_SRCS = $(addprefix srcs/parser/, $(PARSER))
# expander
EXP = expander.c \
expand_var.c \
wildcard.c \
pattern.c \
utils/expand_var_utils.c \
utils/ft_split_argv.c \
utils/ft_split_whitespace.c \
utils/readdir_utils.c \
utils/remove_quotes.c
EXP_SRCS = $(addprefix srcs/expander/, $(EXP))
# execution
EXEC = exec.c \
exec_utils.c \
exec_heredoc.c \
exec_cmd.c \
exec_path.c \
exec_redir.c \
exec_open.c \
exec_handler.c \
exec_pipe.c
EXEC_SRCS = $(addprefix srcs/execution/, $(EXEC))
# builtins
BUILTIN = check_builtin.c \
exec_builtin.c \
ft_cd.c \
ft_echo.c \
ft_env.c \
ft_exit.c \
ft_export.c \
ft_pwd.c \
ft_unset.c
BUILTIN_SRCS = $(addprefix srcs/builtins/, $(BUILTIN))
# environment
ENV = envp_dup.c \
sort_envp.c \
update_envp.c \
search_envp.c
ENV_SRCS = $(addprefix srcs/env/, $(ENV))
# error utils
ERR = set_exit_status.c \
error_expander.c \
error_builtin.c \
error_exec.c \
print_error.c \
free_data.c
ERR_SRCS = $(addprefix srcs/error/, $(ERR))
# signals
SIG = signals.c \
signals_utils.c
SIG_SRCS = $(addprefix srcs/signals/, $(SIG))
# all srcs
SRCS = $(INIT_SRCS) $(BUILTIN_SRCS) $(EXP_SRCS) $(ERR_SRCS) \
$(LEXER_SRCS) $(PARSER_SRCS) $(EXEC_SRCS) $(ENV_SRCS) $(SIG_SRCS)
OBJS = $(SRCS:.c=.o)
#------------------------------------------------------------------------
# colours
GREEN = \033[0;32m
B_GREEN = \033[1;32m
BROWN = \033[0;33m
B_BROWN = \033[1;33m
END = \033[0m
#------------------------------------------------------------------------
# RULES
# all = create library from sub-make
all: $(LIBFT) $(NAME)
$(NAME): $(LIBFT) $(OBJS)
@$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LIB_FLAGS) $(INC)
@echo "\n$(B_GREEN)$(NAME) compiled.$(END)"
bonus: $(LIBFT) $(OBJS)
@$(CC) $(CFLAGS) $(OBJS) -o $(BONUS) $(LIB_FLAGS) $(INC)
@echo "\n$(B_GREEN)$(BONUS) compiled.$(END)"
$(OBJS): %.o: %.c
@$(CC) $(CFLAGS) $(INC) -c $< -o $@
@echo "\t$(BROWN)$< compiled.$(END)"
$(LIBFT):
@echo "\n$(B_BROWN)[ COMPILING: $(LIBFT) ]$(END)"
@make -s -C $(LIB_DIR)
@echo "\n$(B_BROWN)[ COMPILING: $(NAME) ]$(END)"
# remove temporary generated files
clean:
@$(RM) $(OBJS)
@make clean -s -C $(LIB_DIR)
# remove library and executable file
fclean: clean
@$(RM) $(NAME) $(BONUS)
@cd $(LIB_DIR) && $(RM) $(LIBFT)
@echo "$(B_GREEN)Removed $(NAME) and $(LIBFT).$(END)"
re: fclean all
#------------------------------------------------------------------------
# declare phony
.PHONY: all bonus clean fclean re