-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (114 loc) · 3.68 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mguerrea <mguerrea@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/03/07 04:11:46 by ezonda #+# #+# #
# Updated: 2020/06/11 19:12:27 by mguerrea ### ########.fr #
# #
# **************************************************************************** #
NAME := 42sh
PROJECT := 42SH
AUTHORS := Niguinti
RM = /bin/rm
### Directories ###
SRC_DIR := ./srcs
OBJ_DIR := ./.obj
INC_DIR := ./incs
### SUB FILES ###
SUB_DIRS := \
error_handler \
tokenizer \
parser \
visitor \
shell \
builtins \
builtins/test \
utils \
line_edit \
ast \
stack \
expansions \
jobs \
### INCLUDE SRC MAKEFILE ###
include $(SRC_DIR)/sources.mk
### INCLUDE INC MAKEFILE ###
include $(INC_DIR)/includes.mk
### ALL SUB DIRS ###
SRC_SUB_DIRS = $(addprefix $(SRC_DIR)/,$(SUB_DIRS))
OBJ_SUB_DIRS = $(addprefix $(OBJ_DIR)/,$(SUB_DIRS))
INC_SUB_DIRS = $(addprefix $(INC_DIR)/,$(SUB_DIRS))
### MAIN AND SUB FILES ###
O_FILES = $(C_FILES:.c=.o)
### Full Paths ###
SRC = $(addprefix $(SRC_DIR)/,$(C_FILES))
OBJ = $(addprefix $(OBJ_DIR)/,$(O_FILES))
INC = $(addprefix $(INC_DIR)/,$(H_FILES))
### Lib ###
PRINTF = printf
PRINTF_DIR = ./$(PRINTF)
PRINTF_INC_DIR = $(PRINTF_DIR)/includes
FT = ft
FT_DIR = ./lib$(FT)
FT_INC_DIR = $(FT_DIR)/incs
FT_LNK = -L$(FT_DIR) -l$(FT) -L$(PRINTF_DIR) -lprintf
### CC && FLAGS ###
CC = gcc #-fsanitize=address
DEBUG_FLAGS = -g3
NO_WARNING ?= false
ifeq ($(NO_WARNING), false)
CFLAGS = \
$(addprefix -I ,$(INC_DIR) $(INC_SUB_DIRS) $(FT_INC_DIR) $(PRINTF_INC_DIR))\
-Wall -Werror -Wextra
else
CFLAGS = \
$(addprefix -I ,$(INC_DIR) $(INC_SUB_DIRS) $(FT_INC_DIR) $(PRINTF_INC_DIR))
endif
LFLAGS = -ltermcap \
$(FT_LNK) \
.PHONY: all clean fclean re
all: init $(FT) $(NAME) bye_msg
### Lib compil ###
$(FT): | lib_msg
@make -sC $(FT_DIR)
@make -sC $(PRINTF_DIR)
### Mkdir obj ###
$(OBJ_DIR): | mkdir_msg
mkdir -p $(OBJ_DIR) $(OBJ_SUB_DIRS)
echo $(INC)
### Compilation ###
.ONESHELL:
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INC) $(MAKEFILE_LIST) | compil_msg
@echo "$(SCURSOR)$(YELLOW)\t- Compiling:$(RESET)$(@F) \c"
@$(CC) $(CFLAGS) -o $@ -c $<
@echo "$(RCURSOR)$(ERASEL)\c"
### Link ###
.ONESHELL:
$(NAME): init $(OBJ_DIR) $(OBJ) $(INC) $(MAKEFILE_LIST) $(FT_DIR)/libft.a $(PRINTF_DIR)/libprintf.a | link_msg
@echo "$(YELLOW)\t- Building $(RESET)$(NAME) $(YELLOW)...$(RESET) \c"
@$(CC) $(OBJ) $(LFLAGS) -o $(NAME)
@echo "$(GREEN)*** Project $(NAME) successfully compiled ***\n$(RESET)"
### Clean ###
$(FT)_clean: | lib_msg
@make -C $(FT_DIR) clean
$(PRINTF)_clean: | lib_msg
@make -C $(PRINTF_DIR) clean
clean: $(FT)_clean $(PRINTF)_clean | clean_msg
@echo "$(GREEN)*** Deleting all object from $(NAME) ... ***\n$(RESET)"
$(RM) -rf $(OBJ_DIR)
$(FT)_fclean: | lib_msg
@make -C $(FT_DIR) fclean
$(PRINTF)_fclean: | lib_msg
@make -C $(PRINTF_DIR) fclean
fclean: $(FT)_fclean $(PRINTF)_fclean | fclean_msg
@echo "$(GREEN)*** Deleting executable file from $(NAME) ... ***\n$(RESET)"
$(RM) -rf $(OBJ_DIR)
$(RM) -rf $(NAME).dSYM
$(RM) -rf $(NAME)
re: fclean all
init:
-@ sh ./.githooks/initme.sh 2>&- || true
### INCLUDE TOOLS MAKEFILE ###
include ./tools.mk