-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (60 loc) · 1.81 KB
/
Makefile
File metadata and controls
83 lines (60 loc) · 1.81 KB
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
NAME ?= minishell
BONUS_NAME ?=
BUILD_DIR ?= ./objs
SRC_DIRS ?= ./srcs
INCL_DIR ?= ./include
SUPP ?= ./srcs/lexer/readline.supp
LIB = libft-42
LIBS = $(addprefix -L ,$(LIB))
SRCS := $(filter-out %_bonus.c, $(shell find $(SRC_DIRS) -name *.c))
OBJS := $(subst $(SRC_DIRS), $(BUILD_DIR), $(SRCS:.c=.o))
BONUS_SRCS := $(shell find $(SRC_DIRS) -name *_bonus.c)
BONUS_OBJS := $(subst $(SRC_DIRS), $(BUILD_DIR), $(BONUS_SRCS:.c=.o))
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(INCL_DIR) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CC = cc
CFLAGS ?= $(INC_FLAGS) -Wall -Werror -Wextra -MMD -MP -g
CPPFLAGS += -I/opt/homebrew/opt/readline/include
LD = cc
LDFLAGS = $(LIBS) -L/opt/homebrew/opt/readline/lib
LINKS = -lft -lreadline
HIDE =
all: init_submodules $(NAME)
$(NAME): $(OBJS)
@make -C $(LIB)
@echo "\nLinking:"
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LINKS)
@echo "..\n"
$(BUILD_DIR)/%.o: $(SRC_DIRS)/%.c
$(HIDE) mkdir -p $(@D)
$(HIDE) $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
@echo "Compiling $< ..\n"
bonus: init_submodules $(BONUS_NAME)
$(BONUS_NAME): $(BONUS_OBJS)
@make -C $(LIB)
@echo "\nlinking bonus:"
$(LD) $(LDFLAGS) -o $(BONUS_NAME) $(BONUS_OBJS) $(LINKS)
@echo "..\n"
$(BUILD_DIR)/%_bonus.o: $(SRC_DIRS)/%_bonus.c
$(HIDE) mkdir -p $(@D)
$(HIDE) $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
@echo "Compiling $< ...\n"
clean:
$(HIDE) $(RM) -r $(BUILD_DIR)
$(MAKE) -C $(LIB) clean
$(HIDE) $(RM) heredoc.txt
@echo "removing obj/ ..\n"
fclean: clean
@make fclean -C $(LIB)
$(HIDE) $(RM) $(NAME)
$(HIDE) $(RM) $(BONUS_NAME)
$(MAKE) -C $(LIB) fclean
@echo "removing $(NAME) ..\n"
re: fclean all
init_submodules:
@git submodule update --init
valgrind: all
valgrind --leak-check=full --show-leak-kinds=all --suppressions=$(SUPP) ./$(NAME)
.PHONY: clean fclean re all bonus init_submodules
-include $(DEPS)