-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
45 lines (30 loc) · 828 Bytes
/
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
NAME=minishell
CC=gcc
CFLAGS=-Wall -Wextra -Werror
INCLUDE_DIR=include
HEADER_EXT=h
HEADER=$(shell find $(INCLUDE_DIR) -type f -name "*.$(HEADER_EXT)")
SRC_EXT=c
SRC_DIR=src
SRC=$(shell find $(SRC_DIR) -type f -name "*.$(SRC_EXT)")
OBJ_DIR=obj
OBJ_SUBDIR= $(shell find $(SRC_DIR) -type d | grep '/' | sed 's/$(SRC_DIR)/$(OBJ_DIR)/g')
OBJ=$(subst $(SRC_DIR),$(OBJ_DIR),$(SRC:.c=.o))
LIB=./lib -lft-minishell -lreadline
RM=rm -rf
all: ${NAME}
${NAME}: $(OBJ_DIR) $(OBJ_SUBDIR) ${OBJ}
${CC} ${CFLAGS} ${OBJ} -o ${NAME} -L ${LIB}
$(OBJ_DIR):
@mkdir $(OBJ_DIR)
$(OBJ_SUBDIR):
@mkdir $(OBJ_SUBDIR)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.$(SRC_EXT) ${HEADER}
$(CC) $(CFLAGS) -c $< -o $(<:.$(SRC_EXT)=.o)
@mv $(SRC_DIR)/*/*.o $@
clean:
${RM} ${OBJ_DIR}
fclean: clean
${RM} ${NAME}
re: fclean all
.PHONY: all clean fclean re