summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: c42ef99578181de623c2a665fbc03c383c35a19b (plain)
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
default: debug
#==============================================================================#
#--------------------------------- SHELL --------------------------------------#
#==============================================================================#
SHELL			:= /bin/sh
OS				 = $(shell uname)
#==============================================================================#
#------------------------------ DIRECTORIES -----------------------------------#
#==============================================================================#
SRCS_DIR		 = src/
OBJS_DIR		 = obj/
LFT_DIR			 = libft/
LFT_INCS_DIR	 = ${LFT_DIR}include/
LFT_SRCS_DIR	 = ${LFT_DIR}src/
#==============================================================================#
#--------------------------------- FILES --------------------------------------#
#==============================================================================#
SRCS_NAME		 = b_alias
SRCS_NAME		+= b_alias_print
SRCS_NAME		+= b_alias_register
SRCS_NAME		+= b_cd
SRCS_NAME		+= b_echo
SRCS_NAME		+= b_env
SRCS_NAME		+= b_exit
SRCS_NAME		+= b_export
SRCS_NAME		+= b_export_next
SRCS_NAME		+= b_export_mute
SRCS_NAME		+= b_h
SRCS_NAME		+= b_pwd
SRCS_NAME		+= b_sqb
SRCS_NAME		+= b_sqb_err
SRCS_NAME		+= b_sqb_file
SRCS_NAME		+= b_sqb_nbr
SRCS_NAME		+= b_sqb_str
SRCS_NAME		+= b_type
SRCS_NAME		+= b_unset
SRCS_NAME		+= c_ctrls
SRCS_NAME		+= c_init
SRCS_NAME		+= c_input
SRCS_NAME		+= c_keys
SRCS_NAME		+= c_utils_next
SRCS_NAME		+= c_utils
SRCS_NAME		+= e_builtins
SRCS_NAME		+= e_externs
SRCS_NAME		+= e_line
SRCS_NAME		+= e_pipes
SRCS_NAME		+= e_pipes_next
SRCS_NAME		+= e_redirs
SRCS_NAME		+= e_unshebanged
SRCS_NAME		+= f_alloc
SRCS_NAME		+= f_chdir
SRCS_NAME		+= f_com
SRCS_NAME		+= f_errno
SRCS_NAME		+= f_exec
SRCS_NAME		+= f_fail
SRCS_NAME		+= f_file
SRCS_NAME		+= f_parse
SRCS_NAME		+= f_redir
SRCS_NAME		+= f_shlvl
SRCS_NAME		+= m_argv
SRCS_NAME		+= m_comm
SRCS_NAME		+= m_funptr
SRCS_NAME		+= m_init
SRCS_NAME		+= m_loop
SRCS_NAME		+= m_loop_counter
SRCS_NAME		+= m_loop_multis
SRCS_NAME		+= m_loop_next
SRCS_NAME		+= m_minishell
SRCS_NAME		+= m_mshrc
SRCS_NAME		+= m_prompt
SRCS_NAME		+= m_prompt_seq
SRCS_NAME		+= s_destroy
SRCS_NAME		+= s_com
SRCS_NAME		+= s_init
SRCS_NAME		+= s_init_next
SRCS_NAME		+= s_set_cwd
SRCS_NAME		+= s_lalias
SRCS_NAME		+= s_line
SRCS_NAME		+= s_lvars
SRCS_NAME		+= s_lpipes
SRCS_NAME		+= s_lpipes_split
SRCS_NAME		+= s_lredir
SRCS_NAME		+= p_args
SRCS_NAME		+= p_args_next
SRCS_NAME		+= p_args_len
SRCS_NAME		+= p_args_escape
SRCS_NAME		+= p_line
SRCS_NAME		+= p_lblock
SRCS_NAME		+= p_lblock_next
SRCS_NAME		+= p_lblock_more
SRCS_NAME		+= p_redirs
SRCS_NAME		+= p_redirs_heredoc
SRCS_NAME		+= p_split
SRCS_NAME		+= p_subst_alias
SRCS_NAME		+= p_subst_home
SRCS_NAME		+= p_subst_vars
SRCS_NAME		+= u_alias
SRCS_NAME		+= u_parse
SRCS_NAME		+= u_path
SRCS_NAME		+= u_utils
SRCS_NAME		+= u_vars
SRCS_NAME		+= u_vars_next
#------------------------------------------------------------------------------#
SRCS			 = $(addprefix ${SRCS_DIR}, $(addsuffix .c, ${SRCS_NAME}))
#------------------------------------------------------------------------------#
INCS_NAME		 = b_builtins
INCS_NAME		+= d_enum
INCS_NAME		+= d_define
INCS_NAME		+= s_struct
#------------------------------------------------------------------------------#
INCS			 = $(addprefix ${SRCS_DIR}, $(addsuffix .h, ${INCS_NAME}))
INCS			+= $(patsubst %.c,%.h,${SRCS})
#------------------------------------------------------------------------------#
OBJS			 = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS})
#------------------------------------------------------------------------------#
NAME			 = minishell
#------------------------------------------------------------------------------#
LFT_SRCS		 = $(shell find ${LFT_SRCS_DIR} -name "*.c")
#==============================================================================#
#-------------------------------- COMPILER ------------------------------------#
#==============================================================================#
ifeq (${OS}, FreeBSD)
CC				 = cc
endif
ifeq (${OS}, Linux)
CC				 = clang
endif
ifeq (${OS}, Darwin)
CC				 = cc
endif
CFLAGS			 = -std=c89
CFLAGS			+= -Wall
CFLAGS			+= -Wextra
CFLAGS			+= -Werror
CFLAGS			+= -pedantic
#------------------------------------------------------------------------------#
CDEFS			 = -D_POSIX_C_SOURCE=200112L
#------------------------------------------------------------------------------#
LDFLAGS			 = -L${LFT_DIR}
LDFLAGS			+= -lft
LDFLAGS			+= -lncurses
#==============================================================================#
#--------------------------------- UNIX ---------------------------------------#
#==============================================================================#
RM				= rm -rf
MKDIR			= mkdir -p
#==============================================================================#
#--------------------------------- RULES --------------------------------------#
#==============================================================================#
LFTRULE			= all
#------------------------------------------------------------------------------#
${OBJS_DIR}%.o:	${SRCS_DIR}%.c ${INCS}
	${CC} -c ${CFLAGS} ${CDEFS} -I${LFT_INCS_DIR} -o $@ $<
#------------------------------------------------------------------------------#
${OBJS_DIR}:
	${MKDIR} ${OBJS_DIR}
#------------------------------------------------------------------------------#
$(NAME): ${OBJS} ${LFT_SRCS} ${LFT_INCS_DIR}libft.h
	$(MAKE) --no-print-directory -C ${LFT_DIR} ${LFTRULE}
	${CC} ${CFLAGS} ${CDEFS} -o ${NAME} ${OBJS} ${LDFLAGS}
#------------------------------------------------------------------------------#
all: ${OBJS_DIR} ${NAME}
#------------------------------------------------------------------------------#
debug: CFLAGS += -glldb
debug: LFTRULE = debug
debug: all
#------------------------------------------------------------------------------#
asan: CFLAGS += -glldb
asan: CFLAGS += -fsanitize=address
asan: LFTRULE = asan
asan: all
#------------------------------------------------------------------------------#
msan: CFLAGS += -glldb
msan: CFLAGS += -fsanitize=memory
msan: CFLAGS += -fsanitize-memory-track-origins
msan: CFLAGS += -fno-common
msan: CFLAGS += -fno-omit-frame-pointer
msan: LFTRULE = msan
msan: all
#------------------------------------------------------------------------------#
clean:
	@$(MAKE) --no-print-directory -C ${LFT_DIR} clean
	${RM} ${OBJS_DIR} vgcore*
#------------------------------------------------------------------------------#
fclean: clean
	@$(MAKE) --no-print-directory -C ${LFT_DIR} fclean
	${RM} ${NAME} ${NAME}.core ${NAME}.dSYM/ qwe minishell_history
#------------------------------------------------------------------------------#
re: fclean all
#------------------------------------------------------------------------------#
run: all
	clear; ./${NAME}
#------------------------------------------------------------------------------#
.PHONY:	all clean clean fclean re debug asan run