-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (100 loc) · 3.32 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
# VAR = val: Normal setting - values within are recursively expand when var used.
# VAR := val: Setting of var with simple expansion of values inside - values are expanded at decl time.
# VAR ?= val: Set var only if it doesn't have a value.
# VAR += val: Append val to existing value (or set if var didn't exist).
#
# $@: name of the target file (one before colon)
# $<: name of first prerequisite file (first one after colon)
# $^: names of all prerequisite files (space separated)
# $*: stem (bit which matches the % wildcard in rule definition)
# name
OUTPUT_DIR = .
NAME = $(OUTPUT_DIR)/minishell
# dirs
INCL_DIR = incl
SRCS_DIR = srcs
OBJS_DIR = objs
LIBFT_DIR = libs/libft
# Files
INCL = $(wildcard $(INCL_DIR)/*.h) # FIX: change this before submit
# INCL = $(INCL_DIR)/minishell.h
SRCS = $(wildcard $(SRCS_DIR)/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/lex_analysis/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/execute/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/redirect/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/builtin/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/utils_error_exit/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/utils/*.c) # FIX: change this before submit
SRCS += $(wildcard $(SRCS_DIR)/test/*.c) # FIX: change this before submit
# SRCS = $(SRCS_DIR)/main.c \
# $(SRCS_DIR)/tokenization.c \
# ...
OBJS = $(patsubst $(SRCS_DIR)/%.c,$(OBJS_DIR)/%.o,$(SRCS))
#libft
LIBFT_DIR = libs/libft
LIBFT_INCL_DIR = $(LIBFT_DIR)/incl
LIBFT = $(LIBFT_DIR)/libft.a
LIBFT_LL_FLAGS += -lft
CC = cc
CFLAGS = -Wall -Werror -Wextra -g
UI_FLAGS := -I$(INCL_DIR) -I$(LIBFT_INCL_DIR)
UL_FLAGS := -L$(LIBFT_DIR)
LL_FLAGS := $(LIBFT_LL_FLAGS) -lreadline
# use gnu readline library in mac
ifeq ($(shell uname -s),Darwin)
ifeq ($(shell uname -m),arm64)
# Additional flags for M1 Mac
RLDIR := /opt/homebrew/opt/readline
UI_FLAGS += -I$(RLDIR)/include
UL_FLAGS += -L$(RLDIR)/lib
endif
endif
# Link Targets
all: $(NAME)
$(NAME): $(OBJS) | libft
@echo "--------------------------------"
@echo "make OBJECTS done.\n"
$(CC) $(UI_FLAGS) $(UL_FLAGS) $^ $(LL_FLAGS) -o $@
@echo "--------------------------------"
@echo "make $(NAME) done.\n"
chmod 777 $(NAME)
@echo "--------------------------------"
@echo "change permission of $(NAME) done.\n"
# Compile Targets
$(OBJS_DIR)/%.o: $(SRCS_DIR)/%.c | $(OBJS_DIR)
$(CC) $(CFLAGS) $(UI_FLAGS) -c $< -o $@
$(OBJS_DIR):
mkdir $(OBJS_DIR)
mkdir $(OBJS_DIR)/lex_analysis
mkdir $(OBJS_DIR)/redirect
mkdir $(OBJS_DIR)/execute
mkdir $(OBJS_DIR)/builtin
mkdir $(OBJS_DIR)/utils_error_exit
mkdir $(OBJS_DIR)/utils
mkdir $(OBJS_DIR)/test
# make libft
libft: $(LIBFT)
$(LIBFT):
@echo "Compiling libft library..."
make -C $(LIBFT_DIR)
@echo "----------------"
@echo "make libft done.\n"
clean:
rm -rf $(OBJS)
rm -rfd $(OBJS_DIR)
make -C $(LIBFT_DIR) clean
fclean: clean
rm -rf $(NAME)
make fclean -C $(LIBFT_DIR)
re: fclean all
update: fclean
make
norm:
norminette $(SRCS) $(INCL)
memcheck:
make
valgrind --suppressions=valgrind_pref.txt ./minishell
memcheck-full:
make
valgrind --suppressions=valgrind_pref.txt --leak-check=full --show-leak-kinds=all ./minishell
.PHONY = all clean fclean re update norm