-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (111 loc) · 3.7 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mnouchet <mnouchet@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/01/06 22:19:57 by mnouchet #+# #+# #
# Updated: 2023/05/27 02:36:20 by mnouchet ### ########.fr #
# #
# **************************************************************************** #
NAME := minishell
## ########################################################################## ##
# INGREDIENTS ##
## ########################################################################## ##
# LIBS libraries to be used
# LIBS_TARGET libraries to be built
# INCS header file locations
#
# SRCS_DIR source directory
# SRCS source files
#
# BUILD_DIR build directory
# OBJS object files
#
# CC compiler
# CFLAGS compiler flags
# CPPFLAGS preprocessor flags
# LDFLAGS linker flags
# LDLIBS libraries name
LIBS := ft \
readline
LIBS_TARGET := libs/libft/libft.a
INCS := includes \
libs/libft
SRCS_DIR := srcs
SRCS := main.c \
builtins/cd.c \
builtins/echo.c \
builtins/env.c \
builtins/exit.c \
builtins/export.c \
builtins/pwd.c \
builtins/unset.c \
types/command.c \
types/env.c \
types/token.c \
utils/exec/exec.c \
utils/exec/pipeline.c \
utils/exec/process.c \
utils/exec/redirs.c \
utils/exec/redirs2.c \
utils/parse/errors.c \
utils/parse/free.c \
utils/parse/str.c \
utils/parse/trim.c \
utils/env.c \
utils/error.c \
utils/path.c \
utils/pipes.c \
utils/signal.c \
utils/token.c
SRCS := $(SRCS:%=$(SRCS_DIR)/%)
BUILD_DIR := .build
OBJS := $(SRCS:$(SRCS_DIR)/%.c=$(BUILD_DIR)/%.o)
CC := cc
CFLAGS := -g3 -Wall -Wextra -Werror
CPPFLAGS := $(INCS:%=-I%)
LDFLAGS := $(addprefix -L,$(dir $(LIBS_TARGET)))
LDLIBS := $(addprefix -l,$(LIBS))
## ########################################################################## ##
# UTENSILS ##
## ########################################################################## ##
# RM force remove
# MAKEFLAGS make flags
# DIR_UP duplicate directory tree
RM := rm -f
MAKEFLAGS += --silent --no-print-directory
DIR_DUP = mkdir -p $(@D)
## ########################################################################## ##
# RECIPES ##
## ########################################################################## ##
# all default goal
# $(NAME) link .o -> archive
# %.o compilation .c -> .o
# clean remove .o
# fclean remove .o + binary
# re remake default goal
all: $(NAME)
$(LIBS_TARGET):
echo "→ Compiling $(@F)"
$(MAKE) -C $(@D)
$(BUILD_DIR)/%.o: $(SRCS_DIR)/%.c
echo "→ Compiling $<"
$(DIR_DUP)
$(CC) $(CFLAGS) -c $< -o $@ $(CPPFLAGS)
$(NAME): $(LIBS_TARGET) $(OBJS)
make -C libs/libft
$(CC) $(OBJS) -o $(NAME) $(LDLIBS) $(LDFLAGS)
echo "\033[0;32m✓ $@ READY\033[0m"
bonus: all
clean:
echo "→ Removing objects"
make clean -C libs/libft
$(RM) $(OBJS)
fclean: clean
make fclean -C libs/libft
echo "→ Removing binaries"
$(RM) $(NAME)
re: fclean all
.PHONY: re