-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
92 lines (71 loc) · 2.81 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: eseferi <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/08/08 16:46:30 by eseferi #+# #+# #
# Updated: 2024/04/11 16:49:29 by eseferi ### ########.fr #
# #
# **************************************************************************** #
# Variables
CC = gcc
CFLAGS = -Wall -Wextra -Iinc -Isrc -O3 -g #-fsanitize=address -fno-omit-frame-pointer
RM = rm -rf
MINISHELL = minishell
NAME = $(MINISHELL)
# readline, leaks, valgrind
RL_PREFIX = $(HOME)/.local/pkg/readline
RL_CFLAGS = -I $(RL_PREFIX)/inc
RL_LIBS = -L $(RL_PREFIX)/lib -lreadline -lhistory -lcurses
VALGRIND = valgrind --track-fds=yes --trace-children=yes#--log-file="valog" #--leak-check=full -s --show-leak-kinds=all #--track-origins=yes
LEAKS = leaks --atExit --
# Libraries
LIBFT = libft.a
LIBFT_DIR = lib/libft
LIBFT_FILE = $(LIBFT_DIR)/$(LIBFT)
CFLAGS += -I $(LIBFT_DIR)/inc
MAKE_LIB = make --no-print-directory -C
# Source and Object Files
VPATH = src:inc:src/execution:src/lexer:src/parenthesis:src/parsing:src/expander:src/tree:src/utils:inc
MINISHELL_INC = minishell.h
MINISHELL_SRC = $(shell find src -name '*.c')
# Object Files
OBJ_DIR = obj
MINISHELL_OBJ = $(addprefix $(OBJ_DIR)/, $(MINISHELL_SRC:.c=.o))
# Rules
all: $(NAME)
$(OBJ_DIR)/%.o: %.c $(MINISHELL_INC)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) $(RL_CFLAGS) -c $< -o $@
$(LIBFT_FILE):
$(MAKE_LIB) $(LIBFT_DIR)
$(NAME): $(LIBFT_FILE) $(MINISHELL_OBJ)
@$(CC) $(CFLAGS) $(MINISHELL_OBJ) $(LIBFT_FILE) $(RL_LIBS) -o $@
@echo "$(GREEN)$(NAME) was successfully created!$(DEFAULT)"
lib_clean:
$(MAKE_LIB) $(LIBFT_DIR) clean
lib_fclean:
$(MAKE_LIB) $(LIBFT_DIR) fclean
clean: lib_clean
$(RM) $(OBJ_DIR)
@echo "$(YELLOW)$(NAME) object files deleted!$(DEFAULT)"
fclean: clean lib_fclean
$(RM) $(NAME)
@echo "$(RED)$(NAME) program deleted!$(DEFAULT)"
re: fclean all
# Valgrind testing
valgrind: $(NAME)
$(VALGRIND) ./$(NAME)
# Leaks at exit testing
leaks: $(NAME)
$(LEAKS) ./$(NAME)
.SILENT:
.PHONY: all lib_clean lib_fclean clean fclean re
# COLORS DEFINITION
RED = \033[1;31m
DEFAULT = \033[0m
GREEN = \033[1;32m
BOLD = \033[1m
YELLOW = \033[1;33m