aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: b3a18f384e02e9cb8a8ad19fa0a42c2a38e088db (plain)
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
################################################################################
################################## VARIABLES ###################################
################################################################################

################################################################################
################################## VARIABLES ###################################
################################################################################

NAME    := minishell

CC      =  cc
CFLAGS  =  -Wall -Wextra -Werror
LIB_DIR = lib
LIBS    =  -L $(LIB_DIR)/libft -lft -lreadline
HEADERS =  -I include -I $(LIB_DIR)/libft

VPATH   := src
SRC     := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \
           free_token.c new_node.c free_node.c tokenizer.c parser.c \
           parse_cmd.c collect_redirs.c print_ast.c interpreter.c env.c \
           get_cmd_path.c env_to_strlst.c execute_cmd.c format_string.c \
		   builtins_part_one.c builtins_part_two.c env_tools.c error.c \
		   read_heredoc.c create_files.c builtins_part_three.c handle_redir.c \
		   praise_the_norme.c

OBJ_DIR := _obj
OBJ     := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o))

################################################################################
#################################### RULES #####################################
################################################################################

all: libs $(NAME)

$(NAME): $(OBJ)
	@$(CC) $(CFLAGS) $(HEADERS) $(LIBS) $^ -o $@
	@echo "[$(NAME)] Created binary."

libs:
	@make -C $(LIB_DIR)/libft

$(OBJ_DIR)/%.o: %.c
	@if [ ! -d "$(dir $@)" ]; then \
		mkdir -p $(dir $@); \
	fi
	@$(CC) $(CFLAGS) $(HEADERS) -c $< -o $@
	@echo "[$(NAME)] Compiled $<."

clean:
	@if [ -d "$(OBJ_DIR)" ]; then \
		rm -rf $(OBJ_DIR); \
		echo "[$(NAME)] Removed object files."; \
	fi
	@make fclean -C $(LIB_DIR)/libft

fclean: clean
	@if [ -f "$(NAME)" ]; then \
		rm -f $(NAME); \
		echo "[$(NAME)] Removed binary."; \
	fi

re:	fclean all

debug: CFLAGS += -g
debug: CFLAGS += -fsanitize=address -fsanitize=undefined \
				 -fno-sanitize-recover=all -fsanitize=float-divide-by-zero \
				 -fsanitize=float-cast-overflow -fno-sanitize=null \
				 -fno-sanitize=alignment -fno-sanitize=object-size \
				 -fno-sanitize=vptr -fno-sanitize=return -fno-sanitize=signed-integer-overflow \
				 -fno-sanitize=bounds -fno-sanitize=pointer-subtract -fno-sanitize=pointer-compare
debug: CFLAGS += -DDEBUG=1
debug: clean all

.PHONY: all clean fclean re libs debug

################################################################################
################################################################################