summaryrefslogtreecommitdiff
path: root/Makefile
blob: 2defed048e45ff97f6266e49fbaae51cc5aee2a5 (plain)
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

PREFIX=/usr
INSTALL=install
CFLAGS+=-std=gnu99 -O2 -g -MMD -Wall				\
	-Wno-unused-but-set-variable				\
	-Wno-pointer-sign					\
	-fno-strict-aliasing					\
	-I. -Iinclude -Ilibbcache				\
	-D_FILE_OFFSET_BITS=64					\
	-D_GNU_SOURCE						\
	-D_LGPL_SOURCE						\
	-DRCU_MEMBARRIER					\
	-DNO_BCACHE_ACCOUNTING					\
	-DNO_BCACHE_BLOCKDEV					\
	-DNO_BCACHE_CHARDEV					\
	-DNO_BCACHE_FS						\
	-DNO_BCACHE_NOTIFY					\
	-DNO_BCACHE_WRITEBACK					\
	$(EXTRA_CFLAGS)
LDFLAGS+=-O2 -g

ifdef D
	CFLAGS+=-Werror
else
	CFLAGS+=-flto
	LDFLAGS+=-flto
endif

PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib"
CFLAGS+=`pkg-config --cflags	${PKGCONFIG_LIBS}`
LDLIBS+=`pkg-config --libs	${PKGCONFIG_LIBS}` 		\
	-lm -lpthread -lrt -lscrypt -lkeyutils

ifeq ($(PREFIX),/usr)
	ROOT_SBINDIR=/sbin
else
	ROOT_SBINDIR=$(PREFIX)/sbin
endif

.PHONY: all
all: bcache

CCANSRCS=$(wildcard ccan/*/*.c)
CCANOBJS=$(patsubst %.c,%.o,$(CCANSRCS))

# Linux kernel shim:
LINUX_SRCS=$(wildcard linux/*.c linux/*/*.c)
LINUX_OBJS=$(LINUX_SRCS:.c=.o)

OBJS=bcache.o			\
     bcache-userspace-shim.o	\
     cmd_assemble.o		\
     cmd_debug.o		\
     cmd_device.o		\
     cmd_fs.o			\
     cmd_fsck.o			\
     cmd_format.o		\
     cmd_key.o			\
     cmd_run.o			\
     crypto.o			\
     libbcache.o		\
     qcow2.o			\
     tools-util.o		\
     $(LINUX_OBJS)		\
     $(CCANOBJS)

DEPS=$(OBJS:.o=.d)
-include $(DEPS)

bcache: $(OBJS)

.PHONY: install
install: bcache
	mkdir -p $(DESTDIR)$(ROOT_SBINDIR)
	mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8/
	$(INSTALL) -m0755 bcache	$(DESTDIR)$(ROOT_SBINDIR)
	$(INSTALL) -m0755 mkfs.bcache	$(DESTDIR)$(ROOT_SBINDIR)
	$(INSTALL) -m0644 bcache.8	$(DESTDIR)$(PREFIX)/share/man/man8/

.PHONY: clean
clean:
	$(RM) bcache $(OBJS) $(DEPS)

.PHONY: deb
deb: all
	debuild --unsigned-source	\
		--unsigned-changes	\
		--no-pre-clean		\
		--build=binary		\
		--diff-ignore		\
		--tar-ignore

.PHONE: update-bcache-sources
update-bcache-sources:
	echo BCACHE_REVISION=`cd $(LINUX_DIR); git rev-parse HEAD` > .bcache_revision
	cp $(LINUX_DIR)/drivers/md/bcache/*.[ch] libbcache/
	cp $(LINUX_DIR)/include/trace/events/bcache.h include/trace/events/
	cp $(LINUX_DIR)/include/uapi/linux/bcache.h include/linux/
	cp $(LINUX_DIR)/include/uapi/linux/bcache-ioctl.h include/linux/