]> git.sesse.net Git - bcachefs-tools-debian/blob - Makefile
Cleanup Makefile for better compatibility + enable "make debug"
[bcachefs-tools-debian] / Makefile
1 PREFIX?=/usr/local
2 PKG_CONFIG?=pkg-config
3 INSTALL=install
4 PYTEST=pytest-3
5 CFLAGS+=-std=gnu89 -O2 -g -MMD -Wall                            \
6         -Wno-pointer-sign                                       \
7         -fno-strict-aliasing                                    \
8         -fno-delete-null-pointer-checks                         \
9         -I. -Iinclude -Iraid                                    \
10         -D_FILE_OFFSET_BITS=64                                  \
11         -D_GNU_SOURCE                                           \
12         -D_LGPL_SOURCE                                          \
13         -DRCU_MEMBARRIER                                        \
14         -DZSTD_STATIC_LINKING_ONLY                              \
15         -DFUSE_USE_VERSION=32                                   \
16         -DNO_BCACHEFS_CHARDEV                                   \
17         -DNO_BCACHEFS_FS                                        \
18         -DNO_BCACHEFS_SYSFS                                     \
19         -DVERSION_STRING='"$(VERSION)"'                         \
20         $(EXTRA_CFLAGS)
21 LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
22
23 VERSION?=$(shell git describe --dirty=+ 2>/dev/null || echo v0.1-nogit)
24
25 include Kbuild.include
26
27 CFLAGS+=$(call cc-disable-warning, unused-but-set-variable)
28 CFLAGS+=$(call cc-disable-warning, stringop-overflow)
29 CFLAGS+=$(call cc-disable-warning, zero-length-bounds)
30 CFLAGS+=$(call cc-disable-warning, missing-braces)
31 CFLAGS+=$(call cc-disable-warning, zero-length-array)
32 CFLAGS+=$(call cc-disable-warning, shift-overflow)
33 CFLAGS+=$(call cc-disable-warning, enum-conversion)
34
35 PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev"
36 ifdef BCACHEFS_FUSE
37         PKGCONFIG_LIBS+="fuse3 >= 3.7"
38         CFLAGS+=-DBCACHEFS_FUSE
39 endif
40
41 PKGCONFIG_CFLAGS:=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
42 ifeq (,$(PKGCONFIG_CFLAGS))
43     $(error pkg-config error, command: $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
44 endif
45 PKGCONFIG_LDLIBS:=$(shell $(PKG_CONFIG) --libs   $(PKGCONFIG_LIBS))
46 ifeq (,$(PKGCONFIG_LDLIBS))
47     $(error pkg-config error, command: $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
48 endif
49
50 CFLAGS+=$(PKGCONFIG_CFLAGS)
51 LDLIBS+=$(PKGCONFIG_LDLIBS)
52
53 LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio -ldl
54 LDLIBS+=$(EXTRA_LDLIBS)
55
56 ifeq ($(PREFIX),/usr)
57         ROOT_SBINDIR=/sbin
58         INITRAMFS_DIR=$(PREFIX)/share/initramfs-tools
59 else
60         ROOT_SBINDIR=$(PREFIX)/sbin
61         INITRAMFS_DIR=/etc/initramfs-tools
62 endif
63
64 .PHONY: all
65 all: bcachefs
66
67 .PHONY: tests
68 tests: tests/test_helper
69
70 .PHONY: check
71 check: tests bcachefs
72         cd tests; $(PYTEST)
73
74 .PHONY: TAGS tags
75 TAGS:
76         ctags -e -R .
77
78 tags:
79         ctags -R .
80
81 SRCS=$(shell find . -type f -iname '*.c')
82 DEPS=$(SRCS:.c=.d)
83 -include $(DEPS)
84
85 OBJS=$(SRCS:.c=.o)
86 bcachefs: $(filter-out ./tests/%.o, $(OBJS))
87
88 MOUNT_SRCS=$(shell find mount/src -type f -iname '*.rs') \
89     mount/Cargo.toml mount/Cargo.lock mount/build.rs
90
91 debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
92 debug: bcachefs
93
94 libbcachefs_mount.a: $(MOUNT_SRCS)
95         LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
96         cp mount/target/release/libbcachefs_mount.a $@
97
98 MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
99 mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
100         $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
101
102 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
103
104 # If the version string differs from the last build, update the last version
105 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
106 .PHONY: .version
107 endif
108 .version:
109         echo '$(VERSION)' > $@
110
111 # Rebuild the 'version' command any time the version string changes
112 cmd_version.o : .version
113
114 doc/bcachefs.5: doc/bcachefs.5.txt
115         a2x -f manpage doc/bcachefs.5.txt
116
117 .PHONY: install
118 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
119 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
120 install: bcachefs
121         $(INSTALL) -m0755 -D bcachefs      -t $(DESTDIR)$(ROOT_SBINDIR)
122         $(INSTALL) -m0755    fsck.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
123         $(INSTALL) -m0755    mkfs.bcachefs    $(DESTDIR)$(ROOT_SBINDIR)
124         $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
125         $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
126         $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
127         $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
128         sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
129         echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
130
131 .PHONY: clean
132 clean:
133         $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS)
134         $(RM) -rf mount/target
135
136 .PHONY: deb
137 deb: all
138 # --unsigned-source --unsigned-changes --no-pre-clean --build=binary
139 # --diff-ignore --tar-ignore
140         debuild -us -uc -nc -b -i -I
141
142 .PHONE: update-bcachefs-sources
143 update-bcachefs-sources:
144         git rm -rf --ignore-unmatch libbcachefs
145         test -d libbcachefs || mkdir libbcachefs
146         cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
147         git add libbcachefs/*.[ch]
148         cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
149         git add include/trace/events/bcachefs.h
150         cp $(LINUX_DIR)/kernel/locking/six.c linux/
151         git add linux/six.c
152         cp $(LINUX_DIR)/include/linux/six.h include/linux/
153         git add include/linux/six.h
154         cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
155         git add include/linux/list_nulls.h
156         cp $(LINUX_DIR)/include/linux/poison.h include/linux/
157         git add include/linux/poison.h
158         cp $(LINUX_DIR)/scripts/Kbuild.include ./
159         git add Kbuild.include
160         $(RM) libbcachefs/*.mod.c
161         git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
162         git add .bcachefs_revision
163
164 .PHONE: update-commit-bcachefs-sources
165 update-commit-bcachefs-sources: update-bcachefs-sources
166         git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"