+bcachefs: $(filter-out ./tests/%.o, $(OBJS))
+
+RUST_SRCS=$(shell find rust-src/ -type f -iname '*.rs')
+MOUNT_SRCS=$(filter %mount, $(RUST_SRCS))
+
+debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
+debug: bcachefs
+
+MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
+libbcachefs.so: LDFLAGS+=-shared
+libbcachefs.so: $(MOUNT_OBJ)
+ $(CC) $(LDFLAGS) $+ -o $@ $(LDLIBS)
+
+MOUNT_TOML=rust-src/mount/Cargo.toml
+mount.bcachefs: lib $(MOUNT_SRCS)
+ LIBBCACHEFS_LIB=$(CURDIR) \
+ LIBBCACHEFS_INCLUDE=$(CURDIR) \
+ $(CARGO_BUILD) --manifest-path $(MOUNT_TOML)
+
+ ln -f rust-src/mount/target/$(CARGO_PROFILE)/bcachefs-mount $@
+
+
+tests/test_helper: $(filter ./tests/%.o, $(OBJS))
+
+# If the version string differs from the last build, update the last version
+ifneq ($(VERSION),$(shell cat .version 2>/dev/null))
+.PHONY: .version
+endif
+.version:
+ echo '$(VERSION)' > $@
+
+# Rebuild the 'version' command any time the version string changes
+cmd_version.o : .version