-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (92 loc) · 3.2 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fhelena <fhelena@student.21-school.ru> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/08/26 13:14:25 by fhelena #+# #+# #
# Updated: 2021/02/25 10:31:35 by fhelena ### ########.fr #
# #
# **************************************************************************** #
# Target Files
NAME = minishell
LIB = libft.a
# Directories
SRC_DIR = src
INC_DIR = include
LIB_DIR = libft
BLD_DIR = build
OBJ_DIR = $(BLD_DIR)/objs
DEP_DIR = $(BLD_DIR)/deps
-include $(SRC_DIR)/$(SRC_DIR).mk
# Files
SRCS = $(SRC)
OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o)
DEPS = $(SRCS:%.c=$(DEP_DIR)/%.d)
# Programs
SHELL = /bin/bash
CC = gcc
MKDIR = -mkdir -p
MAKE = -make -sC
RM = -rm -rf
# Flags
CFLAGS = -Wall -Wextra -Werror
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d
INCFLAGS = -I $(INC_DIR) -I $(LIB_DIR)/$(INC_DIR)
LDFLAGS = -L $(LIB_DIR)
LDLIBS = -lft
# ANSI Escape Sequences
R_CLEAN = \033[K
C_RESET = \033[00m
COLOR_R = \033[31m
COLOR_G = \033[32m
## all: Call targets 'libft' and 'minishell'
PHONY += all
all: libft $(NAME)
@printf "$(COLOR_G)PASS:$(C_RESET)\t$(NAME)\n"
## libft: Build libft
PHONY += libft
libft:
$(MAKE) $(LIB_DIR)
## minishell: Build minishell
$(NAME): $(OBJS)
@printf "\r$(R_CLEAN)Linking: -> $@\n\t$(subst $(subst ,, ),\n\t,$^)\n"
$(CC) $(CFLAGS) $(INCFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
## *.o: Assemble an object file from same name *.c file
$(OBJ_DIR)/%.o: %.c $(DEP_DIR)/%.d $(LIB_DIR)/$(LIB)
$(MKDIR) $(@D) $(dir $(DEPS))
@printf "\r$(R_CLEAN)Assembling: $< -> $@"
$(CC) $(CFLAGS) $(INCFLAGS) -o $@ -c $< $(DEPFLAGS)
$(DEPS):
## help: Show help message
PHONY += help
help: Makefile
@IFS=$$'\n' ; \
help_lines=(`sed -n 's/^##//p' $<`); \
printf "%-10s %s\n%-10s %s\n" "Target" "Help" "----------" "------------"; \
for help_line in $${help_lines[@]}; do \
IFS=$$':' ; help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | tr -d ' '` ; \
help_info=`echo $${help_split[1]} | sed -e 's/^[[:space:]]*//'` ; \
printf "\033[36m%-10s \033[0m%s\n" $$help_command $$help_info; \
done
## clean: Remove object files and dependency files
PHONY += clean
clean:
$(MAKE) $(LIB_DIR) clean
$(RM) $(BLD_DIR)
@printf "$(COLOR_G)PASS:$(C_RESET)\tmake clean\t[$(NAME)]\n"
## fclean: Call target 'clean' and remove executable files
PHONY += fclean
fclean: clean
$(MAKE) $(LIB_DIR) fclean
$(RM) $(NAME)
@printf "$(COLOR_G)PASS:$(C_RESET)\tmake fclean\t[$(NAME)]\n"
## re: Call targets 'fclean' and 'all'
PHONY += re
re: fclean all
## V=1: Enable verbose output
$(V).SILENT:
-include $(wildcard $(DEPS))
.PHONY: $(PHONY)