-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (112 loc) · 4.57 KB
/
Makefile
File metadata and controls
131 lines (112 loc) · 4.57 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
# Makefile for the shell project
# Compiler and flags
CC := cc
# Original: Used for AddressSanitizer to detect memory corruption issues like buffer overflows.
# CFLAGS := -Wall -Wextra -Werror -g -fsanitize=address
# # Updated: Added -fsanitize=leak for better memory leak detection since AddressSanitizer alone focuses more on buffer overflows.
# CFLAGS := -Wall -Wextra -Werror -g -fsanitize=address -fsanitize=leak
# # Used when running "make valgrind" as Valgrind cannot be used on binaries compiled with -fsanitize=address. Use MAKE VALGRIND to run (uncomment it at the bottomo of the page)
CFLAGS := -Wall -Wextra -Werror -g
# Include directories
CPPFLAGS := -Iinclude -Ilib/libft -Ilib/dprintf \
-I/usr/local/opt/readline/include
# Readline library linking
LDFLAGS := -L/usr/local/opt/readline/lib -lreadline -lhistory
# Directories
SRC_DIR := src
OBJ_DIR := obj
LIB_DIR := lib
LIBFT_DIR := $(LIB_DIR)/libft
DPRINTF_DIR := $(LIB_DIR)/dprintf
LIBFT_OBJ_DIR := $(LIBFT_DIR)/obj
DPRINTF_OBJ_DIR := $(LIB_DIR)/dprintf
# Libraries
LIBFT := $(LIBFT_DIR)/libft.a
DPRINTF := $(DPRINTF_DIR)/libdprintf.a
# Executable name
NAME := minishell
# Source files and object files
SRC := \
$(SRC_DIR)/main.c \
$(SRC_DIR)/execution/execution.c \
$(SRC_DIR)/execution/execution2.c \
$(SRC_DIR)/execution/execution_utils.c \
$(SRC_DIR)/execution/execution_utils_2.c \
$(SRC_DIR)/execution/pipes/pipes.c \
$(SRC_DIR)/execution/redirections/create_heredoc.c \
$(SRC_DIR)/execution/redirections/set_heredoc.c \
$(SRC_DIR)/execution/redirections/set_redirection.c \
$(SRC_DIR)/execution/signals/signals.c \
$(SRC_DIR)/execution/signals/signals_utils.c \
$(SRC_DIR)/execution/external_cmds/exec_externals.c \
$(SRC_DIR)/execution/external_cmds/exec_externals_utils.c \
$(SRC_DIR)/execution/built_in/cmd_cd.c \
$(SRC_DIR)/execution/built_in/cmd_echo.c \
$(SRC_DIR)/execution/built_in/cmd_env.c \
$(SRC_DIR)/execution/built_in/cmd_exit.c \
$(SRC_DIR)/execution/built_in/cmd_export.c \
$(SRC_DIR)/execution/built_in/cmd_export_print.c \
$(SRC_DIR)/execution/built_in/cmd_export_utils.c \
$(SRC_DIR)/execution/built_in/cmd_pwd.c \
$(SRC_DIR)/execution/built_in/cmd_unset.c \
$(SRC_DIR)/execution/built_in/env/env_init.c \
$(SRC_DIR)/execution/built_in/env/get_env.c \
$(SRC_DIR)/execution/built_in/env/store_home.c \
$(SRC_DIR)/execution/built_in/exec_builtin.c \
$(SRC_DIR)/parsing/nodes/alloc_args.c \
$(SRC_DIR)/parsing/nodes/alloc_cmd.c \
$(SRC_DIR)/parsing/nodes/alloc_nodes.c \
$(SRC_DIR)/parsing/nodes/alloc_option.c \
$(SRC_DIR)/parsing/nodes/alloc_redir.c \
$(SRC_DIR)/parsing/nodes/error_handling.c \
$(SRC_DIR)/parsing/nodes/free_msh.c \
$(SRC_DIR)/parsing/nodes/free_nodes.c \
$(SRC_DIR)/parsing/nodes/print_nodes.c \
$(SRC_DIR)/parsing/nodes/print_on_cli_utils.c \
$(SRC_DIR)/parsing/nodes/print_on_file_utils.c \
$(SRC_DIR)/parsing/nodes/return_nodes.c \
$(SRC_DIR)/parsing/tokens/allocate_tokens.c \
$(SRC_DIR)/parsing/tokens/handle_expansions.c \
$(SRC_DIR)/parsing/tokens/handle_expansion_utils.c \
$(SRC_DIR)/parsing/tokens/handle_nonquoted.c \
$(SRC_DIR)/parsing/tokens/handle_quoted.c \
$(SRC_DIR)/parsing/tokens/print_tokens.c \
$(SRC_DIR)/parsing/tokens/return_tokens.c \
$(SRC_DIR)/parsing/tokens/tokenise_bounds.c \
$(SRC_DIR)/parsing/tokens/tokenize_strings.c
OBJ := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC))
# Rules
all: $(NAME)
$(NAME): $(LIBFT) $(DPRINTF) $(OBJ)
@if [ ! -f $(LIBFT) ]; then \
echo "Error: libft.a not found in $(LIBFT_DIR)"; exit 1; \
fi
@if [ ! -f $(DPRINTF) ]; then \
echo "Error: libftdprintf.a not found in $(DPRINTF_DIR)"; exit 1; \
fi
$(CC) $(CFLAGS) $(OBJ) $(LIBFT) $(DPRINTF) $(LDFLAGS) -o $(NAME)
# Compile object files - cppflags is for realoine funcs to work
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Build libft
$(LIBFT):
$(MAKE) OBJ_DIR=$(LIBFT_OBJ_DIR) -C $(LIBFT_DIR)
# Build ft_dprintf
$(DPRINTF):
@echo "Building libdprintf.a in $(DPRINTF_DIR)"
$(MAKE) OBJ_DIR=$(DPRINTF_OBJ_DIR) -C $(DPRINTF_DIR)
# Clean rules
clean:
$(MAKE) clean OBJ_DIR=$(LIBFT_OBJ_DIR) -C $(LIBFT_DIR)
$(MAKE) clean OBJ_DIR=$(DPRINTF_OBJ_DIR) -C $(DPRINTF_DIR)
rm -rf $(OBJ_DIR)
fclean: clean
$(MAKE) fclean OBJ_DIR=$(LIBFT_OBJ_DIR) -C $(LIBFT_DIR)
$(MAKE) fclean OBJ_DIR=$(DPRINTF_OBJ_DIR) -C $(DPRINTF_DIR)
rm -f $(NAME)
re: fclean all
# Added to use minishell with valgrind and avoid copy/past all the time - cannot be used when the program is compiled with fsanitise
leaks:
valgrind --suppressions=readline.supp --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(NAME)
.PHONY: all clean fclean re