-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (123 loc) · 3.72 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
BLUE = \033[0;34m
COMPIL = \033[3;35m
GREEN = \033[0;32m
RED = \033[0;31m
RESET = \033[0;m
OS = $(shell uname)
ifeq ($(OS), Darwin)
RUN_CMD = script -q [email protected] $1 > /dev/null; \
RESULT=$$?
else ifeq ($(OS), Linux)
RUN_CMD = script -q -e -c "$(1)" [email protected] > /dev/null; \
RESULT=$$?; \
sed -i '1d' [email protected]; \
sed -i "$$(($$(wc -l < [email protected])-1)),\$$d" [email protected]
endif
define compile_cmd
printf "%b%-30b" "$(BLUE)compiling " "$(COMPIL)$(@F)$(RESET)";
$(RUN_CMD); \
if [ $$RESULT -ne 0 ]; then \
printf "%b\n" "$(RED)[✖]$(RESET)"; \
cat [email protected]; \
else \
printf "%b\n" "$(GREEN)[✓]$(RESET)"; \
fi; \
rm -f [email protected]; \
exit $$RESULT
endef
NAME = minishell
LIBFTDIR = libft
LIBFT_AR = $(addprefix $(LIBFTDIR)/,libft.a)
ifeq ($(OS), Darwin)
RLINCS = $(shell brew --prefix readline)/include
RLLIB = $(shell brew --prefix readline)/lib
endif
INC = minishell.h \
libs.h \
types.h
INCDIR = includes
INCS = $(addprefix $(INCDIR)/,$(INC))
SRC = minishell.c \
executor/executor.c \
executor/executor_utils.c \
executor/executor_utils2.c \
executor/outfile_handler.c \
executor/infile_handler.c \
executor/heredoc.c \
executor/heredoc_env.c \
parsing/parser.c \
parsing/parser_utils.c \
parsing/split_pipe.c \
parsing/split_quote.c \
parsing/split_redir.c \
parsing/cmd_create.c \
parsing/enverr_pass.c \
parsing/envvar_pass.c \
parsing/tilde_pass.c \
parsing/remquote_pass.c \
parsing/assert/test_quote.c \
parsing/assert/test_pipe.c \
parsing/assert/test_redir.c \
builtins/cd.c \
builtins/pwd.c \
builtins/echo.c \
builtins/exit.c \
builtins/export.c \
builtins/export_print.c \
builtins/env.c \
builtins/unset.c \
builtins/builtins_manager.c \
utils/prompt_misc.c \
utils/safe_memory.c \
utils/fd_gb.c \
utils/fd_gb_close.c \
utils/managers/path_manager.c \
utils/managers/errors_manager.c \
utils/managers/history_manager.c \
utils/managers/env_manager.c \
utils/managers/termios_manager.c \
utils/managers/sig_manager.c
SDIR = srcs
SRCS = $(addprefix $(SDIR)/,$(SRC))
ODIR = build/$(OS)
OBJS = $(patsubst $(SDIR)/%,$(ODIR)/%,$(SRCS:.c=.o))
CC = gcc
CFLAGS = -Wall -Wextra -Werror -I $(INCDIR) -I $(LIBFTDIR) -std=c99 -O1 -g3
all: libft $(NAME)
libft: check-and-reinit-submodules
@printf "$(BLUE)compiling $(COMPIL)libft:$(RESET)\n";
@make -C $(LIBFTDIR) --no-print-directory
$(ODIR)/%.o: $(SDIR)/%.c $(INCS) Makefile
@mkdir -p $(@D)
@$(call compile_cmd, $(CC) $(CFLAGS) -c $< -o $@)
$(NAME): $(OBJS) $(LIBFT_AR)
ifeq ($(OS), Darwin)
@$(call compile_cmd, $(CC) $(OBJS) $(LIBFT_AR) -lreadline -I$(RLINCS) -L$(RLLIB) -o $(NAME))
else ifeq ($(OS), Linux)
@$(call compile_cmd, $(CC) $(OBJS) $(LIBFT_AR) -lreadline -o $(NAME))
endif
@printf "$(GREEN)Done$(RESET)\n";
debug: $(OBJS) $(LIBFT_AR)
ifeq ($(OS), Darwin)
@$(call compile_cmd, $(CC) $(OBJS) $(LIBFT_AR) -o $(NAME) -lreadline -I$(RLINCS) -L$(RLLIB) -fsanitize=address)
else ifeq ($(OS), Linux)
@$(call compile_cmd, $(CC) $(OBJS) $(LIBFT_AR) -o $(NAME) -lreadline -fsanitize=address)
endif
@printf "$(GREEN)Done debug mode$(RESET)\n";
check-and-reinit-submodules:
@if git submodule status | egrep -q '^[-]' ; then \
echo "INFO: Need to reinitialize git submodules"; \
git submodule update --init --remote; \
fi
clean:
@printf "$(RED)Deleting build files$(RESET)\n";
@rm -rf $(ODIR)
@printf "$(RED)Clean libft:$(RESET)\n";
@make clean -C $(LIBFTDIR)
fclean: clean
@printf "$(RED)Deleting $(LIBFT_AR)$(RESET)\n";
@rm -rf $(LIBFT_AR)
@printf "$(RED)Deleting $(NAME)$(RESET)\n";
@rm -rf $(NAME)
re: fclean all
.PHONY: all libft check-and-reinit-submodules clean fclean re