-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
135 lines (117 loc) · 4.01 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
131
132
133
134
135
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: amalliar <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/02/09 23:55:29 by amalliar #+# #+# #
# Updated: 2021/01/25 20:19:04 by amalliar ### ########.fr #
# #
# **************************************************************************** #
SHELL := /bin/sh
CC := clang
CFLAGS := -Wall -Wextra -fdiagnostics-color -g -pipe \
-march=native -O2 -flto
INCLUDE := -I./include -I./libft/include
NAME := minishell
LIBFT := ./libft/libft.a
LIBS := -L./libft -lft
SRCDIR := src
OBJDIR := .obj
DEPDIR := .dep
BUILTIN_SRCS := builtin.c \
env_main.c \
echo_main.c \
pwd_main.c \
cd_main.c \
export_main.c \
unset_main.c \
exit_main.c
BUILTIN_SRCS := $(addprefix builtin/, $(BUILTIN_SRCS))
UTILS_SRCS := error_tools.c \
strarr_tools.c \
prompt_tools.c \
env_tools.c \
env_tools_2.c \
fd_tools.c \
test_tools.c \
exit_failure.c \
get_full_name.c \
handlers.c
UTILS_SRCS := $(addprefix utils/, $(UTILS_SRCS))
LEXER_SRCS := lexer.c \
lexer_2.c \
lexer_utils.c \
lexer_utils_2.c
LEXER_SRCS := $(addprefix lexer/, $(LEXER_SRCS))
PARSER_SRCS:= parser.c \
parser_2.c \
parser_3.c \
parser_utils.c \
parser_utils_2.c
PARSER_SRCS := $(addprefix parser/, $(PARSER_SRCS))
SRCS := main.c \
process.c
SRCS := $(SRCS) $(LEXER_SRCS) $(PARSER_SRCS) $(UTILS_SRCS) $(BUILTIN_SRCS)
SRCS := $(addprefix src/, $(SRCS))
OBJS := $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEPS := $(SRCS:$(SRCDIR)/%.c=$(DEPDIR)/%.d)
# Run multiple threads.
MAKEFLAGS = -j 4 --output-sync=recurse --no-print-directory
# Protect against make incorrectly setting 'last modified' attribute
# when running in parallel (-j flag).
POST_COMPILE = mv -f $(DEPDIR)/$*.tmp $(DEPDIR)/$*.d && touch $@
# Define some colors for echo:
LGREEN := \033[1;32m
WHITE := \033[1;37m
NOC := \033[0m
all: $(NAME)
$(NAME): $(OBJS) $(LIBFT)
@echo -e "$(LGREEN)Linking executable $(NAME)$(NOC)"
$(CC) $(CFLAGS) $(INCLUDE) $(OBJS) $(LIBS) -o $@
@echo -e "Built target $(NAME)"
.PHONY: all
$(LIBFT): NONE
@$(MAKE) -C ./libft
.PHONY: NONE
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(DEPDIR)/%.d | $(OBJDIR) $(DEPDIR)
$(CC) $(CFLAGS) $(INCLUDE) -MMD -MF $(DEPDIR)/$*.tmp -c $< -o $@
@$(POST_COMPILE)
$(OBJDIR):
@mkdir -p $(dir $(OBJS))
$(DEPDIR):
@mkdir -p $(dir $(DEPS))
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
clean:
@$(MAKE) -C ./libft clean
@echo -e "$(WHITE)Removing C object files...$(NOC)"
@-rm -rf $(OBJDIR)
@echo -e "$(WHITE)Removing make dependency files...$(NOC)"
@-rm -rf $(DEPDIR)
.PHONY: clean
fclean: clean
@$(MAKE) -C ./libft fclean
@echo -e "$(WHITE)Removing executable $(NAME)$(NOC)"
@-rm -f $(NAME)
.PHONY: fclean
re:
$(MAKE) fclean
$(MAKE) all
.PHONY: re
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... fclean"
@echo "... re"
.PHONY: help
run: all
./$(NAME)
.PHONY: run
# Do not include dependency files if the current goal is
# set to clean/fclean/re.
ifeq ($(findstring $(MAKECMDGOALS), clean fclean re),)
-include $(DEPS)
endif