-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
152 lines (104 loc) · 3.43 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
145
146
147
148
149
150
151
152
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lmartin <lmartin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/16 10:53:35 by lmartin #+# #+# #
# Updated: 2021/02/10 09:53:43 by lmartin ### ########.fr #
# #
# **************************************************************************** #
## PIMPED MAKEFILE ##
# COLORS #
# This is a minimal set of ANSI/VT100 color codes
_END = \e[0m
_BOLD = \e[1m
_UNDER = \e[4m
_REV = \e[7m
# Colors
_GREY = \e[30m
_RED = \e[31m
_GREEN = \e[32m
_YELLOW = \e[33m
_BLUE = \e[34m
_PURPLE = \e[35m
_CYAN = \e[36m
_WHITE = \e[37m
# Inverted, i.e. colored backgrounds
_IGREY = \e[40m
_IRED = \e[41m
_IGREEN = \e[42m
_IYELLOW = \e[43m
_IBLUE = \e[44m
_IPURPLE = \e[45m
_ICYAN = \e[46m
_IWHITE = \e[47m
# **************************************************************************** #
# NORMINETTE #
NORMINETTE := $(shell which norminette)
ifeq (, $(shell which norminette))
NORMINETTE := ${HOME}/.norminette/norminette.rb
endif
# HOSTTYPE #
ifeq ($(HOSTTYPE),)
HOSTTYPE := $(shell uname -m)_$(shell uname -s)
endif
## VARIABLES ##
# COMPILATION #
CC = gcc
# fPIC needed to compile on xubuntu because of mutex
CC_FLAGS = -Wall -Wextra -Werror -fPIC
# DELETE #
RM = rm -rf
# DIRECTORIES #
DIR_HEADERS = ./includes/
DIR_SRCS = ./srcs/
DIR_OBJS = ./compiled_srcs/
SUB_DIRS = .
SUB_DIR_OBJS = $(SUB_DIRS:%=$(DIR_OBJS)%)
SRCS = malloc.c \
free.c \
realloc.c \
show_alloc_mem.c \
zone.c \
block.c \
utils.c
# COMPILED_SOURCES #
OBJS = $(SRCS:%.c=$(DIR_OBJS)%.o)
NAME = libft_malloc.so
DYNAMIC_LIB = libft_malloc_$(HOSTTYPE).so
# **************************************************************************** #
## RULES ##
all: $(NAME)
# VARIABLES RULES #
$(NAME): $(DYNAMIC_LIB)
@ln -sf $(DYNAMIC_LIB) $(NAME)
@printf "$(_GREEN) Library '$(DYNAMIC_LIB)' linked as '$(NAME)'. $(_END)✅\n"
$(DYNAMIC_LIB): $(OBJS)
@printf "\033[2K\r$(_GREEN) All files has been compiled into '$(DIR_OBJS)'. $(_END)✅\n"
@$(CC) $(CC_FLAGS) $(OBJS) -shared -o $(DYNAMIC_LIB)
@printf "$(_GREEN) Library '$(DYNAMIC_LIB)' created. $(_END)✅\n"
# COMPILED_SOURCES RULES #
$(OBJS): | $(DIR_OBJS)
$(DIR_OBJS)%.o: $(DIR_SRCS)%.c
@printf "\033[2K\r $(_YELLOW)Compiling $< $(_END)⌛"
@$(CC) $(CC_FLAGS) -I $(DIR_HEADERS) -c $< -o $@
$(DIR_OBJS): $(SUB_DIR_OBJS)
$(SUB_DIR_OBJS):
@mkdir -p $(SUB_DIR_OBJS)
# OBLIGATORY PART #
clean:
@$(RM) $(DIR_OBJS)
@printf "$(_RED) '"$(DIR_OBJS)"' has been deleted. $(_END)🗑️\n"
fclean: clean
@$(RM) $(NAME)
@printf "$(_RED) '"$(NAME)"' has been deleted. $(_END)🗑️\n"
@$(RM) $(DYNAMIC_LIB)
@printf "$(_RED) '"$(DYNAMIC_LIB)"' has been deleted. $(_END)🗑️\n"
norm:
@$(NORMINETTE) $(DIR_SRCS)
@$(NORMINETTE) $(DIR_HEADERS)
re: fclean all
# PHONY #
.PHONY: all clean fclean re norm