-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
120 lines (81 loc) · 2.76 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
######### Sources #########
SOURCES = cmd/manager.c \
cmd/malloc.c \
cmd/realloc.c \
cmd/zone.c \
cmd/chunk.c \
cmd/show_alloc_mem.c \
cmd/utils.c \
cmd/free.c \
pkg/ft_print/ft_putchar.c \
pkg/ft_print/ft_putstr.c \
pkg/ft_print/ft_putnbr_base.c \
pkg/ft_print/ft_putnbr.c \
HEADERS = cmd/ft_malloc.h \
cmd/malloc.h \
pkg/ft_print/ft_print.h
HEADERS_DIRECTORIES = cmd \
######### Details #########
NAME = libft_malloc.so
SHORT_NAME = libft_malloc
SOURCES_EXTENSION = c
######### Compilation #########
COMPILE = gcc
LIB = ar rc
DELETE = rm -f
FLAGS = -Wall -Werror -Wextra -pedantic
######### Additional Paths #########
vpath %.h $(HEADERS_DIRECTORIES)
# ################################### #
# DO NOT ALTER FURTHER! #
# ################################### #
######### Additional Paths #########
vpath %.o $(OBJS_DIR)
vpath %.d $(DEPS_DIR)
######### Implicit Macros #########
OBJS_DIR = .objs/
DEPS_DIR = .deps/
OBJS = $(addprefix $(OBJS_DIR), $(SOURCES:.$(SOURCES_EXTENSION)=.o))
DEPS = $(addprefix $(DEPS_DIR), $(SOURCES:.$(SOURCES_EXTENSION)=.d))
######### Rules #########
ifeq ($(HOSTTYPE),)
HOSTTYPE := $(shell uname -m)_$(shell uname -s)
endif
ifdef BONUS
FLAGS += -DMALLOC_THREADSAFE=1
FLAGS += -DFT_MALLOC_DEBUG=1
endif
LIB_NAME := $(SHORT_NAME)_$(HOSTTYPE).so
all: $(OBJS_DIR) $(DEPS_DIR) $(NAME) ## Compile project and dependencies
$(LIB_NAME): $(OBJS)
$(LIB) $(LIB_NAME) $(OBJS)
$(NAME): $(LIB_NAME) ## Compile project
rm -f libft_malloc.so
ln -s $(shell pwd)/$(LIB_NAME) $(NAME)
clean: clean_deps clean_objs ## Delete object files
fclean: clean clean_bin ## Delete object files and binary
re: fclean ## Delete object files and binary, then recompile all
@make --no-print-directory all
help: ## Print this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
######### Sub Rules #########
objs: $(OBJS_DIR) $(DEPS_DIR) $(OBJS) ## Compile object files
clean_deps: ## Delete dependency files and directory
$(DELETE) -r $(DEPS_DIR)
clean_objs: ## Delete object files and directory
$(DELETE) -r $(OBJS_DIR)
clean_bin: ## Delete produced binary
$(DELETE) $(SHORT_NAME)_$(HOSTTYPE).so
$(DELETE) $(NAME)
######### Implicit Rules #########
$(OBJS_DIR):
@mkdir -p $(OBJS_DIR)
$(DEPS_DIR):
@mkdir -p $(DEPS_DIR)
$(OBJS_DIR)%.o: %.$(SOURCES_EXTENSION)
mkdir -p $(OBJS_DIR)$(dir $<)
@mkdir -p $(DEPS_DIR)$(dir $<)
$(COMPILE) $(FLAGS) -MMD -MP -MF $(DEPS_DIR)$*.d -c $< -o $@
.PHONY : all clean fclean re help
######### Includes #########
-include $(DEPS)