summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 08688599265d854d39665e51c8633ccd87407cd4 (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
default: all
#==============================================================================#
#--------------------------------- SHELL --------------------------------------#
#==============================================================================#
SHELL			:= /bin/sh
#==============================================================================#
#------------------------------ DIRECTORIES -----------------------------------#
#==============================================================================#
SRCS_DIR		 = src/
OBJS_DIR		 = obj/
LFT_DIR			 = libft/
LFT_INCS_DIR	 = ${LFT_DIR}inc/
LFT_SRCS_DIR	 = ${LFT_DIR}src/
#==============================================================================#
#--------------------------------- FILES --------------------------------------#
#==============================================================================#
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_pwd
SRCS_NAME		+= b_type
SRCS_NAME		+= b_unset
SRCS_NAME		+= e_builtins
SRCS_NAME		+= e_externs
SRCS_NAME		+= e_externs_next
SRCS_NAME		+= e_externs_pipes
SRCS_NAME		+= e_lcom
SRCS_NAME		+= e_pipes
SRCS_NAME		+= f_chdir
SRCS_NAME		+= f_errno
SRCS_NAME		+= f_fail
SRCS_NAME		+= f_redir
SRCS_NAME		+= m_argv
SRCS_NAME		+= m_comm
SRCS_NAME		+= m_funptr
SRCS_NAME		+= m_loop
SRCS_NAME		+= m_minishell
SRCS_NAME		+= m_prompt
SRCS_NAME		+= m_redirs
SRCS_NAME		+= s_destroy
SRCS_NAME		+= s_init
SRCS_NAME		+= s_lcom
SRCS_NAME		+= s_lvars
SRCS_NAME		+= s_lpipes
SRCS_NAME		+= p_line
SRCS_NAME		+= p_lcom
SRCS_NAME		+= p_lcom_next
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 ------------------------------------#
#==============================================================================#
CC				 = clang
CFLAGS			 = -std=c89
CFLAGS			+= -Wall
CFLAGS			+= -Wextra
CFLAGS			+= -Werror
CFLAGS			+= -pedantic
#------------------------------------------------------------------------------#
LDFLAGS			 = -L${LFT_DIR}
LDFLAGS			+= -lft
#==============================================================================#
#--------------------------------- UNIX ---------------------------------------#
#==============================================================================#
RM				= rm -rf
MKDIR			= mkdir -p
#==============================================================================#
#--------------------------------- RULES --------------------------------------#
#==============================================================================#
LFTRULE			= all
#------------------------------------------------------------------------------#
${OBJS_DIR}%.o:		${SRCS_DIR}%.c ${INCS}
	@${MKDIR} ${OBJS_DIR}
	${CC} -c ${CFLAGS} ${CDEFS} -I${LFT_INCS_DIR} -o $@ $< 
#------------------------------------------------------------------------------#
$(NAME):	${OBJS} ${LFT_SRCS} ${LFT_INCS_DIR}libft.h
	@$(MAKE) --no-print-directory -C ${LFT_DIR} ${LFTRULE}
	${CC} ${CFLAGS} -o ${NAME} ${OBJS} ${LDFLAGS}
#------------------------------------------------------------------------------#
all: ${NAME}
#------------------------------------------------------------------------------#
debug: CFLAGS += -glldb
debug: LFTRULE = debug
debug: all
#------------------------------------------------------------------------------#
asan: CFLAGS += -glldb
asan: CFLAGS += -fsanitize=address
asan: LFTRULE = asan
asan: 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