-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
98 lines (74 loc) · 3.05 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
################################################################################
## MINISHELL ##
################################################################################
NAME := minishell
CYAN := \33[1;36m
RESET := \033[0m
LOG := printf "[$(CYAN)INFO$(RESET)] %s\n"
################################################################################
## DIRECTORIES ##
################################################################################
OBJ_DIR := obj
LIBFT_DIR := libft
INC_DIRS := include $(LIBFT_DIR)
SRC_DIRS := table signals builtins scanner parser parser/grammar debug
SRC_DIRS += helpers exec expansion
SRC_DIRS := $(addprefix src/, $(SRC_DIRS))
SRC_DIRS += src
vpath %.h $(INC_DIRS)
vpath %.c $(SRC_DIRS)
LIBFT := $(LIBFT_DIR)/libft.a
DEBUG := scanning.c parsing.c
HEADERS := minishell.h hash_table.h builtins.h parser.h parser.h tree.h
HEADERS += helpers.h exec.h expansion.h events.h
SOURCES := minishell.c hash_table.c hash_table_utils.c
SOURCES += handlers.c events.c
SOURCES += echo.c pwd.c unset.c cd.c export.c exit.c
SOURCES += scanner.c scanner_utils.c token_word.c parser.c syntax_error.c
SOURCES += tree.c tree_utils.c table.c
SOURCES += rules1.c rules2.c rules3.c rules4.c rules5.c
SOURCES += environ.c environ2.c builtin_pool.c env.c path.c error.c string.c
SOURCES += exec.c exec_cmd.c pcall.c exec_redir.c exec_utils.c exec_pipe.c
SOURCES += exec_list.c exec_heredoc.c exec_subshell.c
SOURCES += exp_utils.c wildcard.c wildcard_utils.c expand.c quotes.c
SOURCES += exit_utils.c heredoc_utils.c exec_builtin.c
SOURCES += $(DEBUG)
OBJS := $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o))
################################################################################
## COMPILATION ##
################################################################################
CFLAGS := -Wall -Werror -Wextra -g $(addprefix -I,$(INC_DIRS))
LDFLAGS := -L $(LIBFT_DIR) -lft -lreadline
all: $(NAME)
test: $(NAME)
@make -C tests --no-print-directory
$(NAME): $(OBJS) | $(LIBFT)
@$(LOG) "Linking objects to $@"
$(CC) $^ $(LDFLAGS) -o $@
$(OBJ_DIR)/%.o: %.c $(HEADERS) | $(OBJ_DIR)
@$(LOG) "Compiling $@"
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR):
@$(LOG) "Creating objects directory"
@mkdir $@
$(LIBFT):
@make bonus -C $(LIBFT_DIR) --no-print-directory
leaks: $(NAME)
valgrind --leak-check=full --show-leak-kinds=all --track-fds=yes \
--suppressions=readline.supp ./$(NAME)
checks: $(NAME)
valgrind -q --leak-check=full --show-leak-kinds=all --track-fds=yes \
--track-origins=yes --trace-children=yes \
--trace-children-skip='*/bin/*,*/sbin/*' \
--suppressions=readline.supp ./$(NAME)
clean:
@$(RM) -r $(OBJS)
@$(LOG) "Removing objects"
@$(RM) -r $(OBJ_DIR)
@$(LOG) "Removing objects directory"
fclean: clean
@$(RM) -r $(NAME)
@$(LOG) "Removing $(NAME)"
@make fclean -C $(LIBFT_DIR) --no-print-directory --silent
re: fclean all
.PHONY: all clean fclean re