-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (80 loc) · 2.69 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
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lucocozz <lucocozz@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/10/30 15:23:20 by lucocozz #+# #+# #
# Updated: 2023/03/28 16:19:08 by lucocozz ### ########.fr #
# #
# **************************************************************************** #
ifeq ($(HOSTTYPE),)
HOSTTYPE := $(shell uname -m)_$(shell uname -s)
endif
NAME = libft_malloc_$(HOSTTYPE).so
SRCS = malloc.c \
free.c \
realloc.c \
calloc.c \
print_memory.c \
show_alloc_mem.c \
show_alloc_mem_hex.c \
show_alloc_mem_freed.c \
show_page_num.c \
libft.c
OBJS = $(SRCS:%.c=$(OBJS_DIR)/%.o)
DEPENDENCIES = $(OBJS:%.o=%.d)
SRCS_DIR = sources
OBJS_DIR = .objs
INCLUDES_DIR = ./includes $(LIBS:%=lib%/includes) $(LIBS:%=lib%)
LIBS =
MAKE = make
CC = clang
RM = rm -f
MKDIR = mkdir -p
DEBUG = off
CFLAGS = -MMD -Wall -Wextra -Werror -fPIC
CXXFLAGS = $(INCLUDES_DIR:%=-I %)
ifeq ($(DEBUG), on)
CXXFLAGS += -g3
endif
LDFLAGS = $(LIBS:%=-L lib%) $(LIBS:%=-l%)
vpath %.c $(addprefix $(SRCS_DIR), /.)
all:
$(foreach LIB, ${LIBS}, ${MAKE} -C lib${LIB} ;)
$(MAKE) $(NAME)
$(CC) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) main.c -lpthread libft_malloc.so -o tests
mv tests.d .objs/
scan:
scan-build-12 $(MAKE)
$(NAME): $(OBJS) | $(LIBS:%=lib%.a)
$(CC) -shared -o $(NAME) $(OBJS)
$(RM) libft_malloc.so
ln -s $(NAME) libft_malloc.so
-include $(DEPENDENCIES)
$(OBJS_DIR)/%.o: %.c $(OBJS_DIR)/debug$(DEBUG) | $(OBJS_DIR)
$(CC) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS) -c $< -o $@
$(OBJS_DIR):
$(MKDIR) $(OBJS_DIR)
lib%.a:
$(MAKE) -C $(@:%.a=%)
$(OBJS_DIR)/debug$(DEBUG): | $(OBJS_DIR)
$(RM) $(OBJS_DIR)/debug*
touch $@
clean:
$(foreach LIB, $(LIBS), $(MAKE) $@ -C lib$(LIB);)
$(RM) -r $(OBJS_DIR)
fclean: clean
$(RM) $(NAME) $(foreach LIB, $(LIBS), lib$(LIB)/lib$(LIB).a) libft_malloc.so
$(RM) test*
$(RM) a.out
re: fclean all
test:
$(CC) mains/test$(main).c -o test$(main)
$(CC) mains/test$(main).c -D LIBFT libft_malloc.so -o test$(main)_libft
/usr/bin/time -v ./test$(main)
./run.sh /usr/bin/time -v ./test$(main)_libft
rm test$(main)
rm test$(main)_libft
.PHONY: all clean fclean re scan test