-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (132 loc) · 2.94 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
ifeq ($(HOSTTYPE),)
HOSTTYPE := $(shell uname -m)_$(shell uname -s)
endif
SRCDIR := srcs
OBJDIR := objs
INCDIR := includes
FILES := \
actual_malloc.c\
actual_free.c\
actual_realloc.c\
visualize.c\
arena_initialize.c\
lock.c\
malloc.c\
memory_alloc.c\
realm_initialize.c\
zone_initialize.c\
zone_bitmap.c\
zone_operation.c\
zone_utils.c\
memory_utils.c\
debug.c\
printf.c\
history.c\
release.c\
assert.c\
SRCS := $(FILES:%.c=$(SRCDIR)/%.c)
OBJS := $(FILES:%.c=$(OBJDIR)/%.o)
LIB_NAME := libmalloc.a
LIBFT := libft.a
LIBFT_DIR := libft
RM := rm -rf
TEST_NAME := malloc
FILES_TEST :=\
main.c\
test_basic.c\
test_mass.c\
test_multithread.c\
test_extreme.c\
test_fine.c\
test_utils.c\
OBJS_TEST := $(FILES_TEST:%.c=$(OBJDIR)/%.o)
CC := gcc
CCOREFLAGS = -Wall -Wextra -Werror -O2 -I$(INCDIR)
CFLAGS = $(CCOREFLAGS) -DNDEBUG -g #-fsanitize=thread
LIBFLAGS := -fPIC -fpic
ifdef WITH_BONUS
CCOREFLAGS += -D BONUS
endif
BASE_LIBNAME := ft_malloc
SONAME := libft_malloc_$(HOSTTYPE).so
BASE_SONAME := libft_malloc.so
DYLIBNAME := libft_malloc_$(HOSTTYPE).dylib
BASE_DYLIBNAME := libft_malloc.dylib
TIME := /usr/bin/time
TIMEFLAGS := -v
all: so
bonus:
$(MAKE) all WITH_BONUS=1
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) $(LIBFLAGS) -c $< -o $@
$(OBJDIR)/%.o: %.c
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
$(LIB_NAME): $(OBJS)
ar rcs $(LIB_NAME) $(OBJS)
$(TEST_NAME): $(LIB_NAME) $(OBJS_TEST) $(LIBFT) #$(BASE_DYLIBNAME)
$(CC) $(CFLAGS) -o $@ $(OBJS_TEST) $(LIBFT) $(LIB_NAME)
./$@
.PHONY: t
t: $(TEST_NAME)
./$^
.PHONY: so
so: $(BASE_SONAME)
$(SONAME): $(OBJS)
$(CC) -shared -fPIC $^ -o $@
$(BASE_SONAME): $(SONAME)
rm -f $@
ln -s $^ $@
.PHONY: dylib
dylib: $(BASE_DYLIBNAME)
$(DYLIBNAME): $(OBJS)
$(CC) -shared -fPIC $^ -o $@
# $(CC) -dynamiclib $^ -o $@
$(BASE_DYLIBNAME): $(DYLIBNAME)
rm -f $@
ln -s $^ $@
$(LIBFT):
$(MAKE) -C $(LIBFT_DIR)
cp $(LIBFT_DIR)/$(LIBFT) .
.PHONY: clean
clean:
$(RM) $(OBJDIR) $(LIBFT)
.PHONY: fclean
fclean: clean
$(RM) $(LIB_NAME) $(SONAME) $(DYLIBNAME) $(BASE_SONAME) $(BASE_DYLIBNAME)
$(MAKE) -C $(LIBFT_DIR) fclean
.PHONY: re
re: fclean all
.PHONY: up
up:
docker-compose up --build -d
.PHONY: down
down:
docker-compose down
.PHONY: it
it:
docker-compose exec app bash
rerv:
rm -rf test0 test1 test2
.PHONY: test0
test0: $(BASE_SONAME)
$(CC) [email protected] -o $@
@echo System:
$(TIME) $(TIMEFLAGS) ./$@ 2>&1 | grep Minor
@echo FT:
LD_PRELOAD=./$(BASE_SONAME) $(TIME) $(TIMEFLAGS) ./$@ 2>&1 | grep Minor
.PHONY: test1
test1: $(BASE_SONAME)
$(CC) [email protected] -o $@
@echo System:
$(TIME) $(TIMEFLAGS) ./$@ 2>&1 | grep Minor
@echo FT:
LD_PRELOAD=./$(BASE_SONAME) $(TIME) $(TIMEFLAGS) ./$@ 2>&1 | grep Minor
.PHONY: test2
test2: $(BASE_SONAME)
$(CC) [email protected] -o $@
@echo System:
$(TIME) $(TIMEFLAGS) ./$@ 2>&1 | grep Minor
@echo FT:
LD_PRELOAD=./$(BASE_SONAME) $(TIME) $(TIMEFLAGS) ./$@ 2>&1 | grep Minor