-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
211 lines (178 loc) · 5.57 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
#### MAIN SETTINGS ####
# Compiler to be used
CC := cc
# Compiler flags
CFLAGS := -Wall -Werror -Wextra -pedantic -O3
# Include directories
INCLUDES := -Iinc/
# Target executable
TARGET := minishell
# Libraries to be linked (if any)
LIBS := -lreadline
# Source files directory
SRC_DIR := src/
# Source files
SRC_FILES += main.c
SRC_FILES += core/f_signal_setup.c
SRC_FILES += core/f_init.c
SRC_FILES += core/f_gc_malloc.c
SRC_FILES += core/f_gc_clean.c
SRC_FILES += core/f_free_and_exit.c
SRC_FILES += builtins/f_echo.c
SRC_FILES += builtins/f_pwd.c
SRC_FILES += builtins/f_env.c
SRC_FILES += builtins/f_cd.c
SRC_FILES += builtins/f_unset.c
SRC_FILES += builtins/f_export.c
SRC_FILES += builtins/f_exit.c
SRC_FILES += env/f_env_add_back.c
SRC_FILES += env/f_env_create_2da.c
SRC_FILES += env/f_env_create_lnklst.c
SRC_FILES += env/f_env_remove_one.c
SRC_FILES += env/f_env_find_key.c
SRC_FILES += env/f_env_keyvaluetostr.c
SRC_FILES += env/f_env_last.c
SRC_FILES += env/f_env_lstlen.c
SRC_FILES += env/f_env_new.c
SRC_FILES += env/f_env_strtokey.c
SRC_FILES += env/f_env_strtovalue.c
SRC_FILES += env/f_increase_shlvl.c
SRC_FILES += token/f_get_token_end.c
SRC_FILES += token/f_tokenize.c
SRC_FILES += token/f_tok_add_back.c
SRC_FILES += token/f_tok_last.c
SRC_FILES += token/f_tok_new.c
SRC_FILES += token/f_print_tokens.c
SRC_FILES += token/f_create_tokens.c
SRC_FILES += token/f_tok_check_syntax.c
SRC_FILES += token/f_tok_remove_one.c
SRC_FILES += token/f_tok_remove_one_universal.c
SRC_FILES += token/f_unite_double_ops.c
SRC_FILES += token/f_add_categories.c
SRC_FILES += token/f_var_find_key.c
SRC_FILES += token/f_var_new_string.c
SRC_FILES += token/f_var_end.c
SRC_FILES += token/f_resolve_quotes.c
SRC_FILES += token/f_join_tokens.c
SRC_FILES += token/f_delete_white_toks.c
SRC_FILES += token/f_toks_to_cmds_n_args.c
SRC_FILES += token/f_add_arg_to_tok.c
SRC_FILES += token/f_tok_is_redir.c
SRC_FILES += token/f_add_redirs_to_cmds.c
SRC_FILES += token/f_delete_pipes.c
SRC_FILES += token/f_is_builtin.c
SRC_FILES += token/f_contains_heredoc.c
SRC_FILES += token/f_expandable_dollar_sign.c
SRC_FILES += token/f_do_expansions_in_str.c
SRC_FILES += token/f_is_operator.c
SRC_FILES += token/f_do_expansions_for_toks.c
SRC_FILES += token/f_delete_empty_tokens.c
SRC_FILES += token/f_only_white_tokens.c
SRC_FILES += utils/f_memcpy.c
SRC_FILES += utils/f_strchr.c
SRC_FILES += utils/f_strcmp.c
SRC_FILES += utils/f_strjoin.c
SRC_FILES += utils/f_strlen.c
SRC_FILES += utils/f_strncmp.c
SRC_FILES += utils/f_split.c
SRC_FILES += utils/f_itoa.c
SRC_FILES += utils/f_strdup.c
SRC_FILES += utils/f_strscmp.c
SRC_FILES += utils/f_strncpy.c
SRC_FILES += utils/f_strcpy.c
SRC_FILES += utils/f_is_alpha.c
SRC_FILES += utils/f_is_dig.c
SRC_FILES += utils/f_atoi.c
SRC_FILES += utils/f_atoi_mod.c
SRC_FILES += utils/f_array_length.c
SRC_FILES += execution/f_do_execute.c
SRC_FILES += execution/f_handle_cmd.c
SRC_FILES += execution/f_execution.c
SRC_FILES += execution/f_get_cmd_path.c
SRC_FILES += execution/f_do_heredoc.c
SRC_FILES += execution/f_init_pipex.c
SRC_FILES += execution/f_open_file.c
SRC_FILES += execution/f_set_redirects.c
SRC_FILES += execution/f_do_builtin.c
SRC_FILES += execution/f_handle_final_cmd.c
SRC_FILES += execution/f_handle_single_cmd.c
SRC_FILES += execution/f_do_child.c
SRC_FILES += execution/f_resolve_heredocs.c
# Object files directory
OBJ_DIR := obj/
# Object files
OBJ_FILES := $(patsubst %.c, $(OBJ_DIR)%.o, $(SRC_FILES))
# Dependency files directory
DEP_DIR := dep/
# Dependency files
DEPENDS := $(patsubst %.o, $(DEP_DIR)%.d, $(OBJ_FILES))
-include $(DEPENDS)
#### SHELL COMMANDS ####
RM := /bin/rm -f
MKDIR := /bin/mkdir -p
TOUCH := /bin/touch
#### DEBUG SETTINGS ####
# ifeq ($(DEBUG), 1)
# Uncomment above line and delete below to disable automatic debug settings
ifeq (1, 1)
CFLAGS += -g3 -O0
endif
#### TARGET COMPILATION ####
.DEFAULT_GOAL := all
all: $(TARGET) ## Build this project
# Compilation rule for object files
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
@$(MKDIR) $(@D)
@echo -n "[build] "
$(CC) $(CFLAGS) -MMD -MF $(patsubst %.o, %.d, $@) $(INCLUDES) -c $< -o $@
# Rule for linking the target executable
$(TARGET): $(OBJ_FILES)
@echo -n "\n[link] "
$(CC) $(CFLAGS) -o $(TARGET) $(OBJ_FILES) $(LIBS)
-@echo -n "🚀 $(MAGENTA)" && ls -lah $(TARGET) && echo -n "$(RESET)"
#### LOCAL LIBS COMPILATION ####
#### ADDITIONAL RULES ####
clean: ## Clean objects and dependencies
@echo -n "[clean] "
$(RM) $(OBJ_FILES)
@echo -n "[clean] "
$(RM) -r $(OBJ_DIR)
@echo -n "[clean] "
$(RM) $(DEPENDS)
@echo -n "[clean] "
$(RM) -r $(DEP_DIR)
fclean: clean ## Restore project to initial state
@echo -n "[fclean] "
$(RM) $(TARGET)
re: fclean all ## Rebuild project
help: ## Show help info
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-30s$(RESET) %s\n", $$1, $$2}'
.PHONY: all re clean fclean help
#### COLORS ####
# Color codes
RESET := \033[0m
BOLD := \033[1m
UNDERLINE := \033[4m
# Regular colors
BLACK := \033[30m
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
BLUE := \033[34m
MAGENTA := \033[35m
CYAN := \033[36m
WHITE := \033[37m
# Background colors
BG_BLACK := \033[40m
BG_RED := \033[41m
BG_GREEN := \033[42m
BG_YELLOW := \033[43m
BG_BLUE := \033[44m
BG_MAGENTA := \033[45m
BG_CYAN := \033[46m
BG_WHITE := \033[47m
# Credits:
# This Makefile was copied from https://github.com/tesla33io/philosophers.git
# Gratitude to the maker
# It was edited to fit the needs of our project (Gabe and Karl)