-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
150 lines (114 loc) · 3.12 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
.PHONY: all clean fclean re bonus libft libbdlst create_dir debug_sh
.SILENT: libft libbdlst
NAME = msh
LIBFT_NAME = libft.a
LIBBDLST_NAME = libbdlst.a
######################### CC && FLAGS ########################
CC = gcc # clang
DEBUG = -g # -fsanitize=address
CFLAGS = -Wall -Wextra -Werror
ifdef (BONUS)
CFLAGS += -D BONUS=1
endif
TERMCAP = -ltermcap
LIBFT_FLAGS = -L $(LFT_DIR) -lft
LIBBDLST_FLAGS = -L $(LBDLST_DIR) -lbdlst
INCLUDE_FLAGS = -I $(INC_DIR) -I $(LFT_DIR) -I $(GNL_DIR) -I $(LBDLST_DIR)
######################### DIRECTORIES ########################
SRC_DIR = src
OBJ_DIR = obj
LFT_DIR = libft
INC_DIR = include
LBDLST_DIR = libbdlst
GNL_DIR = get_next_line
######################### SOURCES ############################
SOURCES = array_utils.c \
clean.c \
cmd_cd.c \
cmd_clear.c \
cmd_echo.c \
cmd_env.c \
cmd_exit.c \
cmd_export.c \
cmd_history.c \
cmd_not_found.c \
cmd_pwd.c \
cmd_unset.c \
cmd_usercmd.c \
cmd_utils.c \
cursor.c \
dir_utils.c \
dollar.c \
env_copy.c \
env_get.c \
env_update.c \
env_utils.c \
error.c \
execute.c \
fds.c \
history.c \
init.c \
key_actions.c \
key_arrows.c \
key_signals.c \
key_utils.c \
lexer.c \
main.c \
main_functions.c \
parse_redirect.c \
parser.c \
parser_utils.c \
pipes.c \
pipes_utils.c \
readline.c \
redirects.c \
shell_exit.c \
shell_split.c \
signal.c \
term_utils.c \
termcaps.c \
tilda.c \
HEADER_FILES = msh.h \
builtin.h \
shell_keys.h \
get_next_line.h \
GNL_SRC = get_next_line.c
######################## OBJECT FILES ########################
GNL_OBJ = $(addprefix $(GNL_DIR)/, $(GNL_SRC:.c=.o))
OBJECTS = $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o))
######################## HEADERS #############################
HEADERS = $(addprefix $(INC_DIR)/, $(HEADER_FILES))
######################## INSTRUCTIONS ########################
debug: all
all: libft libbdlst create_dir $(GNL_OBJ) $(NAME)
create_dir:
@mkdir -p $(OBJ_DIR)
test: libft libbdlst
gcc -g src/test.c $(LBDLST_DIR)/$(LIBBDLST_NAME) $(LFT_DIR)/$(LIBFT_NAME) $(INCLUDE_FLAGS)
libft:
@$(MAKE) -C $(LFT_DIR) bonus
libbdlst:
@$(MAKE) -C $(LBDLST_DIR)
$(GNL_DIR)/%.o: $(GNL_DIR)/%.c
@$(CC) $(DEBUG) $(CFLAGS) -c $< $(INCLUDE_FLAGS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(HEADERS) $(GNL_OBJ)
@$(CC) $(DEBUG) $(CFLAGS) -c $< $(INCLUDE_FLAGS) $() -o $@
$(NAME): $(OBJECTS) $(GNL_OBJ) $(HEADERS)
@$(CC) $(DEBUG) $(CFLAGS) $(GNL_OBJ) $(OBJECTS) $(LIBFT_FLAGS) $(LIBBDLST_FLAGS) $(TERMCAP) -o $@
@echo "${NAME} created."
clean:
@$(MAKE) clean -C $(LFT_DIR) --no-print-directory
@$(MAKE) clean -C $(LBDLST_DIR) --no-print-directory
@rm -rf $(OBJ_DIR)/*.o
fclean: clean
@$(MAKE) fclean -C $(LFT_DIR) --no-print-directory
@$(MAKE) fclean -C $(LBDLST_DIR) --no-print-directory
@rm -rf ${NAME}
@echo "${NAME} has been deleted."
clean_bonus:
@rm -rf $(OBJ_DIR)/*.o
bonus: clean_bonus
@$(MAKE) BONUS=1 all --no-print-directory
run: all
./msh
re: fclean all