-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
128 lines (95 loc) · 3.2 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: pchadeni <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/01/08 14:57:58 by pchadeni #+# #+# #
# Updated: 2019/04/30 15:05:06 by pchadeni ### ########.fr #
# #
# **************************************************************************** #
#------Name of the project------#
NM = ft_nm
OTOOL = ft_otool
NAME = $(NM) $(OTOOL)
#------All sources------#
NM_MAIN = nm.c
OTOOL_MAIN = otool.c
MAIN_SRCS = type.c \
merge_sort.c \
merge_sort_uint.c \
error.c \
print.c \
print_nm.c \
tools.c \
tools_2.c \
symbols_struct.c \
handle_fat.c \
handle_archive.c \
handle_macho_struct.c \
list_symbols.c \
add_sect.c \
cpu_name.c \
handle_file.c \
options.c
OBJ += $(addprefix ./$(OBJ_PATH)/, $(MAIN_SRCS:.c=.o))
OBJ_NM += $(addprefix ./$(OBJ_PATH)/, $(NM_MAIN:.c=.o))
OBJ_OTOOL += $(addprefix ./$(OBJ_PATH)/, $(OTOOL_MAIN:.c=.o))
#------Includes------#
INCLUDES = ./inc/
INC += -I $(INCLUDES)
INC += -I $(LIB_PATH)/$(INCLUDES)
LIB = $(LIB_PATH)/libft.a
HEAD = $(INCLUDES)/lib_nm_otool.h
#------Path------#
SRCS_PATH = srcs
OBJ_PATH = obj
LIB_PATH = libft
#------Main rules------#
all: $(OBJ_PATH) makelib $(NAME)
$(NAME): $(LIB) $(OBJ) $(OBJ_NM) $(OBJ_OTOOL)
@printf "\33[2KObjects created $(BOLD_GREEN)✓$(EOC)\n"
@printf "Start making $(NAME)...\n"
@$(CC) $(C_FLAGS) $(FLAGS) $(INC) -o $(NM) $(OBJ) $(OBJ_NM) $(LIB)
@$(CC) $(C_FLAGS) $(FLAGS) $(INC) -o $(OTOOL) $(OBJ) $(OBJ_OTOOL) $(LIB)
@printf "$(BOLD_GREEN)⤖ $(NAME)$(EOC) created $(BOLD_GREEN)✓$(EOC)\n"
$(OBJ_PATH):
@mkdir -p $(OBJ_PATH)
@printf "$(OBJ_PATH) created\n"
$(OBJ_PATH)/%.o: $(SRCS_PATH)/%.c $(HEAD)
@$(CC) $(FLAGS) $(C_FLAGS) $(INC) -o $@ -c $<
@printf " $(COL_GREEN)[OK]$(EOC) $(COL_YELLOW)Compiling:$(EOC) $<\r"
makelib:
@make -C $(LIB_PATH) NOERR=$(NOERR) DEV=$(DEV) SAN=$(SAN)
clean: cleanlib
@rm -Rf $(OBJ_PATH)
@rm -Rf $(TEST_OBJ)
@echo "$(BOLD_GREEN)$(NAME)$(EOC) clean $(BOLD_GREEN)✓$(EOC)"
cleanlib:
@make clean -C $(LIB_PATH)
fclean: fcleanlib clean
@rm -Rf $(NAME) $(LINK)
@echo "$(BOLD_GREEN)$(NAME) $(LINK)$(EOC) fclean $(BOLD_GREEN)✓$(EOC)"
fcleanlib:
@make fclean -C $(LIB_PATH)
re: fclean all
#------Compilation's flags------#
CC = gcc
# flags
C_FLAGS = -Wall -Wextra
ifneq ($(NOERR),yes)
C_FLAGS += -Werror
endif
ifeq ($(DEV),yes)
FLAGS += -g
endif
ifeq ($(SAN),yes)
FLAGS += -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
endif
#------Define colors------#
BOLD_GREEN = \033[01;32m
COL_GREEN = \033[0;32m
COL_YELLOW = \033[0;33m
EOC = \033[0m
.PHONY: all re fclean clean