-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
295 lines (242 loc) · 8.1 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# You can generate the compile_commands.json file by using
# `make clean -j$(nproc)`
# `bear make all -j$(nproc)`
# `compdb -p ./ list > ../compile_commands.json`
# `cp ../compile_commands.json ./
# or
# `make compiledb`
#
# You can get `bear` from [link](https://github.com/rizsotto/Bear)
# You can get `compdb` from [link](https://github.com/Sarcasm/compdb)
# `-fsanitize=address` and `-lasan` for memory leakage checking
# `-g` and `-pg` for tracing the program
# So, you must delete all when you release the program
.SUFFIXES : .c .cpp .o
CC = gcc
AR = ar
CXX = g++
INTEGRATION_TEST_TARGET = integration-test.out
BENCHMARK_TARGET = benchmark.out
LIBRARY_TARGET = libftl.a
GLIB_INCLUDES = $(shell pkg-config --cflags glib-2.0)
DEVICE_INCLUDES =
GLIB_LIBS = $(shell pkg-config --libs glib-2.0)
DOCKER_TAG_ROOT = ftl
# Device Module Setting
USE_ZONE_DEVICE = 0
USE_BLUEDBM_DEVICE = 0
USE_RASPBERRY_DEVICE = 0
# Debug Setting
USE_DEBUG = 0
USE_LOG_SILENT = 0
# Random Generator Setting
USE_LEGACY_RANDOM = 0
ifeq ($(USE_DEBUG), 1)
DEBUG_FLAGS = -g -pg \
-DCONFIG_ENABLE_MSG \
-DCONFIG_ENABLE_DEBUG
MACROS = -DUSE_GC_MESSAGE -DDEBUG
MEMORY_CHECK_LIBS = -lasan
MEMORY_CHECK_CFLAGS =
MEMORY_CHECK_LIBS += -fsanitize=address
else
DEBUG_FLAGS =
MACROS = -DUSE_GC_MESSAGE
MEMORY_CHECK_LIBS =
MEMORY_CHECK_CFLAGS =
endif
ifeq ($(USE_LOG_SILENT), 1)
DEBUG_FLAGS += -DENABLE_LOG_SILENT
endif
ifeq ($(USE_LEGACY_RANDOM), 1)
MACROS += -DUSE_LEGACY_RANDOM
endif
TEST_TARGET := lru-test.out \
bits-test.out \
ramdisk-test.out
DEVICE_LIBS =
ifeq ($(USE_ZONE_DEVICE), 1)
# Zoned Device's Setting
DEVICE_INFO := -DDEVICE_NR_BUS_BITS=3 \
-DDEVICE_NR_CHIPS_BITS=3 \
-DDEVICE_NR_PAGES_BITS=5 \
-DDEVICE_NR_BLOCKS_BITS=21
TEST_TARGET += zone-test.out
DEVICE_LIBS += -lzbd
else ifeq ($(USE_BLUEDBM_DEVICE), 1)
# BlueDBM Device's Setting
DEVICE_INFO := -DDEVICE_NR_BUS_BITS=3 \
-DDEVICE_NR_CHIPS_BITS=3 \
-DDEVICE_NR_PAGES_BITS=7 \
-DDEVICE_NR_BLOCKS_BITS=19 \
-DUSER_MODE \
-DUSE_PMU \
-DUSE_KTIMER \
-DUSE_NEW_RMW \
-D_LARGEFILE64_SOURCE \
-D_GNU_SOURCE \
-DNOHOST
DEVICE_LIBS += -lmemio
DEVICE_INCLUDES += -I/usr/local/include/memio
else ifeq ($(USE_RASPBERRY_DEVICE), 1)
# Configuration for RaspberryPi Device
# https://www.waveshare.com/wiki/File:K9F1G08U0D.pdf
#
# RaspberryPi does not support the multiple chips and pages.
# For this reason, it does not match with conventional physical address format.
#
# Therefore, I translated conventional physical address format to RaspberryPi compatible format.
# +----------------+--------------+--------------+-------------+
# Compatible => | Block(24 bits) | Page(4 bits) | Chip(1 bits) | Bus(1 bits) |
# +----------------+-------------------------------------------+
# Actual => | Block(24 bits) | Page(6 bits) |
# +----------------+-------------------------------------------+
DEVICE_INFO := -DDEVICE_NR_BUS_BITS=1 \
-DDEVICE_NR_CHIPS_BITS=1 \
-DDEVICE_NR_PAGES_BITS=4 \
-DDEVICE_NR_BLOCKS_BITS=24 \
-DDEVICE_PAGE_SIZE=2048
DEVICE_LIBS += -lnand -lwiringPi
DEVICE_INCLUDES += -I/usr/local/include/nand
else
# Ramdisk Setting (1GiB)
DEVICE_INFO := -DDEVICE_NR_BUS_BITS=2 \
-DDEVICE_NR_CHIPS_BITS=2 \
-DDEVICE_NR_PAGES_BITS=7 \
-DDEVICE_NR_BLOCKS_BITS=19
endif
ifeq ($(USE_ZONE_DEVICE), 1)
DEVICE_INFO += -DDEVICE_USE_ZONED \
-DPAGE_FTL_USE_GLOBAL_RWLOCK
endif
ifeq ($(USE_BLUEDBM_DEVICE), 1)
DEVICE_INFO += -DDEVICE_USE_BLUEDBM
endif
ifeq ($(USE_RASPBERRY_DEVICE), 1)
DEVICE_INFO += -DDEVICE_USE_RASPBERRY
endif
ARFLAGS := rcs
CFLAGS := -Wall \
-Wextra \
-Wpointer-arith \
-Wcast-align \
-Wwrite-strings \
-Wswitch-default \
-Wunreachable-code \
-Winit-self \
-Wmissing-field-initializers \
-Wno-unknown-pragmas \
-Wundef \
-Wconversion \
-Werror \
$(DEVICE_INFO) \
$(DEBUG_FLAGS) \
$(MEMORY_CHECK_CFLAGS) \
-O3
CXXFLAGS := $(CFLAGS) \
-std=c++11
UNITY_ROOT := ./unity
LIBS := -lm -lpthread $(GLIB_LIBS) $(DEVICE_LIBS) $(MEMORY_CHECK_LIBS)
INCLUDES := -I./include -I./unity/src $(GLIB_INCLUDES) $(DEVICE_INCLUDES)
RAMDISK_SRCS = device/ramdisk/*.c
ZONED_SRCS =
BLUEDBM_SRCS =
RASPBERRY_SRCS =
ifeq ($(USE_ZONE_DEVICE), 1)
ZONED_SRCS += device/zone/*.c
endif
ifeq ($(USE_BLUEDBM_DEVICE), 1)
BLUEDBM_SRCS += device/bluedbm/*.c
endif
ifeq ($(USE_RASPBERRY_DEVICE), 1)
RASPBERRY_SRCS += device/raspberry/*.c
endif
DEVICE_SRCS := $(RAMDISK_SRCS) \
$(BLUEDBM_SRCS) \
$(ZONED_SRCS) \
$(RASPBERRY_SRCS) \
device/*.c
UTIL_SRCS := util/*.c
FTL_SRCS := ftl/page/*.c
INTERFACE_SRCS := interface/*.c
SRCS := $(DEVICE_SRCS) \
$(UTIL_SRCS) \
$(FTL_SRCS) \
$(INTERFACE_SRCS)
OBJS := *.o
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
all: $(INTEGRATION_TEST_TARGET) $(BENCHMARK_TARGET)
test: $(TEST_TARGET)
@for target in $(TEST_TARGET) ; do \
./$$target ; \
done
# show coverage
@for target in $(TEST_TARGET) ; do \
gcov ./$$target ; \
done
integration-test: $(INTEGRATION_TEST_TARGET)
./$(INTEGRATION_TEST_TARGET)
install: $(LIBRARY_TARGET)
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 $(LIBRARY_TARGET) $(DESTDIR)$(PREFIX)/lib
install -d $(DESTDIR)$(PREFIX)/include/ftl
install -m 644 include/*.h $(DESTDIR)$(PREFIX)/include/ftl
$(INTEGRATION_TEST_TARGET): integration-test.c $(LIBRARY_TARGET)
$(CXX) $(MACROS) $(CXXFLAGS) -c integration-test.c $(INCLUDES) $(LIBS)
$(CXX) $(MACROS) $(CXXFLAGS) -o $@ integration-test.o -L. -lftl -lpthread $(LIBS) $(INCLUDES)
$(BENCHMARK_TARGET): benchmark.c $(LIBRARY_TARGET)
$(CXX) $(MACROS) $(CFLAGS) -c benchmark.c $(INCLUDES) $(LIBS)
$(CXX) $(MACROS) $(CFLAGS) -o $@ benchmark.o -L. -lftl -lpthread -liberty $(INCLUDES) $(LIBS)
$(LIBRARY_TARGET): $(OBJS)
$(AR) $(ARFLAGS) $@ $^
$(OBJS): $(SRCS)
$(CXX) $(MACROS) $(CFLAGS) -c $^ $(LIBS) $(INCLUDES)
lru-test.out: unity.o ./util/lru.c ./test/lru-test.c
$(CXX) $(MACROS) $(CFLAGS) $(INCLUDES) -o $@ --coverage $^ $(LIBS)
bits-test.out: unity.o ./test/bits-test.c
$(CXX) $(MACROS) $(CFLAGS) $(INCLUDES) -o $@ --coverage $^ $(LIBS)
ramdisk-test.out: $(OBJS) ./test/ramdisk-test.c
$(CXX) $(MACROS) $(CFLAGS) $(INCLUDES) -o $@ --coverage $^ $(LIBS)
ifeq ($(USE_ZONE_DEVICE), 1)
zone-test.out: $(OBJS) ./test/zone-test.c
$(CXX) $(MACROS) $(CFLAGS) -DENABLE_LOG_SILENT $(INCLUDES) -o $@ --coverage $^ $(LIBS)
endif
unity.o: $(UNITY_ROOT)/src/unity.c
$(CXX) $(MACROS) $(CFLAGS) -DENABLE_LOG_SILENT $(INCLUDES) -c $^ $(LIBS)
docker-builder:
docker build -t $(DOCKER_TAG_ROOT)/ftl-builder \
-f docker/Dockerfile ./docker
docker-make-%:
docker run --rm -v $(PWD):/ftl \
$(DOCKER_TAG_ROOT)/ftl-builder /bin/bash -c "make clean && make $*"
docker-console:
docker run --rm -it -v $(PWD):/ftl \
-v ${HOME}/.zshrc:/root/.zshrc \
-v ${HOME}/.vim:/root/.vim \
-v ${HOME}/.vimrc:/root/.vimrc \
$(DOCKER_TAG_ROOT)/ftl-builder /bin/bash
check:
@echo "[[ CPPCHECK ROUTINE ]]"
cppcheck --quiet --error-exitcode=0 --enable=all --inconclusive -I include/ $(SRCS) *.c
@echo "[[ FLAWFINDER ROUTINE ]]"
flawfinder $(SRCS) include/*.h
@echo "[[ STATIC ANALYSIS ROUTINE ]]"
lizard $(SRCS) include/*.h
documents:
doxygen -s Doxyfile
flow:
find . -type f -name '*.[ch]' ! -path "./unity/*" ! -path "./test/*" | xargs -i cflow {}
format:
find . -type f -name '*.[ch]' ! -path "./unity/*" ! -path "./test/*" | xargs -i clang-format -i {}
compiledb:
bear -- $(MAKE) all
compdb -p ./ list > ../compile_commands.json
mv ../compile_commands.json ./
clean:
find . -name '*.o' -exec rm -f {} +
find . -name '*.gcov' -exec rm -f {} +
find . -name '*.gcda' -exec rm -f {} +
find . -name '*.gcno' -exec rm -f {} +
rm -f $(TARGET) $(INTEGRATION_TEST_TARGET) $(TEST_TARGET) $(LIBRARY_TARGET) $(BENCHMARK_TARGET)