-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
219 lines (185 loc) · 7.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
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
CC = cc
SRC_DIR = src/
OBJ_DIR = obj/
RM = rm -rf
NAME = minishell
DN = > /dev/null
LIBFT = libft/libft.a
OS = $(shell uname)
USER = $(shell whoami)
SLEEP = $(shell sleep 2)
CFLAGS = -Wall -Werror -Wextra
INSTALL_READL = $(shell brew install readline)
#DELETE THE PRINT FUNCTIONS FILE
MAIN = main/prompt \
main/minishell \
main/shell_loop \
main/main_utils \
main/print_functions \
BUILTINS = builtins/cd/cd \
builtins/env/env \
builtins/pwd/pwd \
builtins/exit/exit \
builtins/echo/echo \
builtins/unset/unset \
builtins/cd/cd_utils \
builtins/run_builtins \
builtins/cd/cd_options \
builtins/export/export \
builtins/env/env_utils \
builtins/exit/exit_utils \
builtins/echo/echo_utils \
builtins/unset/unset_utils \
builtins/export/empty_cont \
builtins/export/export_utils \
INIT = init/init \
LEXER = lexer/lexer \
lexer/lexer_utils \
lexer/syntax_check \
lexer/syntax_utils \
PARSER = parser/parser \
parser/token_utils \
parser/create_tokens \
parser/init_cmd_table \
parser/add_token_utils \
parser/cmd_table_utils \
parser/create_cmd_table \
parser/remove_quotes \
EXPANDER = expander/expander \
expander/extra_utils \
expander/expand_tokens \
expander/expander_utils \
EXECUTOR = executor/open/open \
executor/execute/execute \
executor/path/path_check \
executor/heredoc/here_doc \
executor/path/extract_path \
executor/pipe_handling/pipe \
executor/execute/execute_cmd \
executor/heredoc/open_heredoc \
executor/execute/execute_utils \
executor/heredoc/here_doc_utils \
executor/redirections/wrong_redirs \
executor/redirections/handle_redirs \
executor/execute/execute_without_pipes \
executor/pipe_handling/exec_only_heredoc \
SIGNALS = signals/signals \
signals/signals_child \
signals/signals_parent \
CLEANUP_TOOLS = cleanup_tools/free \
GENERAL_UTILS = general_utils/error \
general_utils/general_utils \
SOURCE = $(MAIN) $(INIT) $(SIGNALS) $(EXPANDER) $(LEXER) $(PARSER) \
$(EXECUTOR) $(BUILTINS) $(GENERAL_UTILS) $(CLEANUP_TOOLS) \
SRC = $(addprefix $(SRC_DIR), $(addsuffix .c, $(SOURCE)))
OBJ = $(addprefix $(OBJ_DIR), $(addsuffix .o, $(SOURCE)))
ifeq ($(OS), Linux)
INCL_RDL_HEADER = -I /home/linuxbrew/.linuxbrew/opt/readline/include/readline
INCL_RDL_LIB = -lreadline -L /home/linuxbrew/.linuxbrew/opt/readline/lib
else
INCL_RDL_HEADER = -I /Users/$(USER)/.brew/opt/readline/include
INCL_RDL_LIB = -lreadline -L /Users/$(USER)/.brew/opt/readline/lib
endif
BREW = /Users/$(USER)/.brew/bin
READLINE = /Users/$(USER)/.brew/opt/readline/include/readline
run: brew_check
@$(SLEEP)
@clear
@./$(NAME)
brew_check:
@if [ -d $(BREW) ]; then \
echo "$(GREEN)BREW is already installed in $(BREW)$(DEF_COLOR)"; \
else \
{ \
echo "$(YELLOW)Installing Homebrew...$(DEF_COLOR)"; \
curl -fsSL https://rawgit.com/kube/42homebrew/master/install.sh | zsh; \
}; \
fi
@$(MAKE) readline_check
readline_check:
@if [ -d $(READLINE) ]; then \
echo "$(GREEN)READLINE is already installed in $(READLINE)$(DEF_COLOR)"; \
else \
{ \
echo "$(YELLOW)Installing Readline..."$(DEF_COLOR); \
$(INSTALL_READL) \
}; \
fi
@$(MAKE) all
all: $(NAME)
$(NAME): $(LIBFT) $(OBJ)
@echo ""
@echo "$(YELLOW) Compiling: $(DEF_COLOR)$(PURPLE)$(NAME) Mandatory Part By:$(DEF_COLOR) $(RED)Mr. Minishell Community$(DEF_COLOR)"
@echo "$(CYAN2)" $(DN)
@$(CC) $(CFLAGS) $(OBJ) $(INCL_RDL_LIB) $(LIBFT) -lreadline -o minishell $(DN)
@cd obj/general_utils && touch user.txt && echo $$USER > user.txt
@echo "$(PURPLE) $(NAME) $(DEF_COLOR)$(GREEN)Compiling done.$(DEF_COLOR)"
@echo ""
@echo "$(RED) ████▒░▒████▒░██▒░███▒░ █▒░██▒░ ████▒░ ██▒░░▒██▒░██████▒░██▒░ ██▒░"
@echo " ██▒██▒██▒██▒░██▒░█▒██▒░ █▒░██▒░█▒░ ██▒░██▒░░▒██▒░██▒░ ██▒░ ██▒░"
@echo " ██▒░███▒░██▒░██▒░█▒░██▒░█▒░██▒░ ██▒░ ████████▒░████▒░ ██▒░ ██▒░"
@echo " ██▒░░█▒░ ██▒░██▒░█▒░ ██▒█▒░██▒░██▒░ █▒░██▒░░▒██▒░██▒░ ██▒░ ██▒░"
@echo " ██▒░░░ ██▒░██▒░█▒░ ███▒░██▒░ ████▒░ ██▒░░▒██▒░██████▒░██████▒░██████▒░"
@echo " ▓▓▒░░ ▓░▒▓▓▒░ ░▒▓▓▒░▓▒░ ░▒▓▓▒░ ▓▒░░▒▓▒░░▒▓▓▒░░░░░░▒▓▓▒░░░▒▓▓▒░"
@echo " ▓▒░░ ░▒▓▒░ ░▒▓▒░ ░▒▓ ▒░ ▒░ ░▒▓▒░ ░░▒▓▒░ ░░▒▓▒░"
@echo " ▒░░ ▒░ ▒░ ░░ ░ ░ ░▒░ ░▒▒░ ░▒▒░"
@echo " ░░ ░ ░ ░ ░ ░░ ░░"
@echo " ░ ░ ░ $(DEF_COLOR)"
$(OBJ_DIR)%.o : $(SRC_DIR)%.c
@mkdir -p $(@D)
@$(CC) $(INCL_RDL_HEADER) -c $< -o $@ $(DN)
$(LIBFT):
@echo "$(YELLOW)Compiling: $(DEF_COLOR)$(CYAN)LIBFT. $(DEF_COLOR)"
@echo "$(CYAN2)" $(DN)
@git submodule update --init --recursive --remote $(DN)
@make -C ./libft $(DN)
@echo "$(PURPLE)LIBFT $(DEF_COLOR)$(GREEN)has been compiled.$(DEF_COLOR)"
clean:
@echo "$(CYAN)CLEAN$(DEF_COLOR)"
@echo "$(RED)Deleting objects.$(DEF_COLOR)"
@echo "$(CYAN2)" $(DN)
@$(RM) $(OBJ_DIR) $(DN)
@make clean -C ./libft $(DN)
@echo "$(RED)Object files have been successfully removed!$(DEF_COLOR)"
fclean:
@make clean $(DN)
@echo "$(CYAN)FCLEAN$(DEF_COLOR)"
@echo "$(RED)Deleting objects, executables.$(DEF_COLOR)"
@echo "$(CYAN2)" $(DN)
@$(RM) $(NAME) $(DN)
@make fclean -C ./libft $(DN)
@$(RM) minishell.dSYM $(DN)
@echo "$(RED)Executable and object files have been successfully removed.$(DEF_COLOR)"
re: fclean all
@echo "$(RED)Files have been cleaned and project has been rebuilt!$(DEF_COLOR)"
r:
@./$(NAME)
v:
valgrind ./minishell
vm:
valgrind --read-var-info=yes --leak-check=full --track-origins=yes ./minishell
vf:
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --error-limit=no --tool=memcheck ./minishell
ne:
env -i ./minishell
tester:
@if [ -d 42_minishell_tester ]; then \
cd 42_minishell_tester; \
bash tester.sh m ; \
else \
git clone https://github.com/zstenger93/42_minishell_tester.git; \
cd 42_minishell_tester; \
bash tester.sh m; \
fi
rt:
rm -rf 42_minishell_tester
DEF_COLOR = \033[0;39m
CYAN3 = \033[1;4;96m
YELLOW = \033[1;33m
PURPLE = \033[1;35m
BWhite = \033[1;37m
RED = \033[1;4;91m
GREEN = \033[4;92m
CYAN2 = \x1B[1;36m
CYAN = \033[1;96m
.PHONY: brew_check readline_check all clean fclean re run r v vm vf ne tester rt