5 CFLAGS+=-std=gnu89 -O2 -g -MMD -Wall \
8 -fno-delete-null-pointer-checks \
10 -D_FILE_OFFSET_BITS=64 \
14 -DZSTD_STATIC_LINKING_ONLY \
15 -DFUSE_USE_VERSION=32 \
16 -DNO_BCACHEFS_CHARDEV \
19 -DVERSION_STRING='"$(VERSION)"' \
21 LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
23 VERSION?=$(shell git describe --dirty=+ 2>/dev/null || echo v0.1-nogit)
25 include Makefile.compiler
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)
35 PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev"
37 PKGCONFIG_LIBS+="fuse3 >= 3.7"
38 CFLAGS+=-DBCACHEFS_FUSE
41 PKGCONFIG_CFLAGS:=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
42 ifeq (,$(PKGCONFIG_CFLAGS))
43 $(error pkg-config error, command: $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
45 PKGCONFIG_LDLIBS:=$(shell $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
46 ifeq (,$(PKGCONFIG_LDLIBS))
47 $(error pkg-config error, command: $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
50 CFLAGS+=$(PKGCONFIG_CFLAGS)
51 LDLIBS+=$(PKGCONFIG_LDLIBS)
53 LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio -ldl
54 LDLIBS+=$(EXTRA_LDLIBS)
58 INITRAMFS_DIR=$(PREFIX)/share/initramfs-tools
60 ROOT_SBINDIR=$(PREFIX)/sbin
61 INITRAMFS_DIR=/etc/initramfs-tools
64 STATUS:=$(shell rst2man -V 2>/dev/null; echo $$?)
69 STATUS:=$(shell rst2man.py -V 2>/dev/null; echo $$?)
75 all: bcachefs bcachefs.5
78 tests: tests/test_helper
91 DOCSRC := opts_macro.h bcachefs.5.rst.tmpl
92 DOCGENERATED := bcachefs.5 doc/bcachefs.5.rst
93 DOCDEPS := $(addprefix ./doc/,$(DOCSRC))
94 bcachefs.5: $(DOCDEPS) libbcachefs/opts.h
96 $(CC) doc/opts_macro.h -I libbcachefs -I include -E 2>/dev/null \
98 $(RST2MAN) doc/bcachefs.5.rst bcachefs.5
100 @echo "WARNING: no rst2man found! Man page not generated."
103 SRCS=$(shell find . -type f -iname '*.c')
108 bcachefs: $(filter-out ./tests/%.o, $(OBJS))
110 MOUNT_SRCS=$(shell find mount/src -type f -iname '*.rs') \
111 mount/Cargo.toml mount/Cargo.lock mount/build.rs
113 debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
116 libbcachefs_mount.a: $(MOUNT_SRCS)
117 LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
118 cp mount/target/release/libbcachefs_mount.a $@
120 MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
121 mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
122 $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
124 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
126 # If the version string differs from the last build, update the last version
127 ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
131 echo '$(VERSION)' > $@
133 # Rebuild the 'version' command any time the version string changes
134 cmd_version.o : .version
137 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
138 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
140 $(INSTALL) -m0755 -D bcachefs -t $(DESTDIR)$(ROOT_SBINDIR)
141 $(INSTALL) -m0755 fsck.bcachefs $(DESTDIR)$(ROOT_SBINDIR)
142 $(INSTALL) -m0755 mkfs.bcachefs $(DESTDIR)$(ROOT_SBINDIR)
143 $(INSTALL) -m0644 -D bcachefs.8 -t $(DESTDIR)$(PREFIX)/share/man/man8/
144 $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
145 $(INSTALL) -m0755 -D initramfs/hook $(DESTDIR)$(INITRAMFS_HOOK)
146 $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
147 sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
148 echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
152 $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS) $(DOCGENERATED)
153 $(RM) -rf mount/target
157 debuild -us -uc -nc -b -i -I
159 .PHONY: update-bcachefs-sources
160 update-bcachefs-sources:
161 git rm -rf --ignore-unmatch libbcachefs
162 test -d libbcachefs || mkdir libbcachefs
163 cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
164 git add libbcachefs/*.[ch]
165 cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
166 git add include/trace/events/bcachefs.h
167 cp $(LINUX_DIR)/include/linux/xxhash.h include/linux/
168 git add include/linux/xxhash.h
169 cp $(LINUX_DIR)/lib/xxhash.c linux/
170 git add linux/xxhash.c
171 cp $(LINUX_DIR)/kernel/locking/six.c linux/
173 cp $(LINUX_DIR)/include/linux/six.h include/linux/
174 git add include/linux/six.h
175 cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
176 git add include/linux/list_nulls.h
177 cp $(LINUX_DIR)/include/linux/poison.h include/linux/
178 git add include/linux/poison.h
179 cp $(LINUX_DIR)/scripts/Makefile.compiler ./
180 git add Makefile.compiler
181 $(RM) libbcachefs/*.mod.c
182 git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
183 git add .bcachefs_revision
185 .PHONY: update-commit-bcachefs-sources
186 update-commit-bcachefs-sources: update-bcachefs-sources
187 git commit -m "Update bcachefs sources to $(shell git -C $(LINUX_DIR) show --oneline --no-patch)"