-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
120 lines (95 loc) · 2.58 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
##########################################################################################
NAME := minishell
SRCPATH := src
SRC := $(shell find $(SRCPATH) -name *.c)
VPATH := $(SRCPATH)
OBJPATH := obj
OBJDIR := $(subst $(SRCPATH), $(OBJPATH), $(shell find $(SRCPATH) -type d))
OBJ := $(subst $(SRCPATH), $(OBJPATH), $(SRC:.c=.o))
LIBFT := lib/libft/libft.a
LIB := $(LIBFT)
LIB += -lreadline
ifeq ($(OS), $(shell uname -s))
LIB += -LUsers/$(shell whoami)/.brew/Cellar/readline/8.1/lib/
endif
INC := -Iinclude/ -Ilib/libft/include
############################################################################################
#_____ _____ _____
#/ ____| / ____| / ____|
#| | __ | | | |
#| | |_ | | | | |
#| |__| | | |____ | |____
#\_____| \____| \_____|
CC := gcc
CFLAGS := -Wall -Wextra -Werror -MMD -MP#--std=c99 -D_POSIX_SOURCE
CFLAGS += -g3
#CFLAGS += -Ofast
#CLFAGS += -fsanitize=address
############################################################################################
ifeq ($(MAKECMDGOALS),re)
MAKEFLAGS=
else
MAKEFLAGS=-j4
endif
all: $(NAME)
ifeq ($(MAKECMDGOALS),clean)
DEPFILES=
else ifeq ($(MAKECMDGOALS),fclean)
DEPFILES=
else
DEPFILES := $(OBJ:.o=.d)
-include $(DEPFILES)
endif
$(NAME): $(OBJPATH) $(LIBFT) $(OBJ)
@echo -n $(GREEN)
$(CC) $(CFLAGS) $(INC) $(OBJ) $(LIB) -o $(NAME)
@echo $(RESET) "\n===========>\t$(NAME) Successfully compiled [+]"
$(OBJPATH)/%.o: %.c
@echo -n $(GREEN)
$(CC) $(INC) $(CFLAGS) -c $< -o $@
$(OBJPATH):
@echo -n $(GREEN)
mkdir -p $(OBJDIR)
@echo -n $(RESET)
$(LIBFT):
@echo -n $(GREEN)
make -C $(dir $(LIBFT))
@echo -n $(RESET)
clean:
@echo -n $(RED)
make clean -C $(dir $(LIBFT))
rm -rf $(OBJPATH)
@echo -n $(RESET)
fclean: clean
@echo -n $(RED)
make fclean -C $(dir $(LIBFT))
rm -rf $(NAME)
@echo -n $(RESET)
re:
$(MAKE) fclean
$(MAKE) all
.PHONY: run re fclean clean all
############################################################################################
run: $(NAME)
./$(NAME)
bash:
bash
VALFLAGS += --leak-check=full
VALFLAGS += --track-origins=yes
#VALFLAGS += --trace-children=yes
#VALFLAGS += --show-leak-kinds=all
val: $(NAME)
valgrind $(VALFLAGS) ./$(NAME)
docker-build:
@echo building image minishell:latest
@(docker ps -a | grep minishell) || docker build . --tag minishell
docker-run: docker-build
docker run --name minishell -it --rm minishell
docker-rm:
docker rmi -f minishell
debug: $(NAME)
gdb ./$(NAME)
###########################################################################################
GREEN := "\033[1;32m"
RESET := "\033[1;0m"
RED := "\033[1;31m"