]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - Makefile
Cleanup Makefile for better compatibility + enable "make debug"
[bcachefs-tools-debian] / Makefile
index 2f6531b6289691cfbc9d6215aae7fe5c913632e5..6424433b9acdb91ac84e2ea158ae23b2557a2c6e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,3 @@
-
 PREFIX?=/usr/local
 PKG_CONFIG?=pkg-config
 INSTALL=install
@@ -23,23 +22,17 @@ LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
 
 VERSION?=$(shell git describe --dirty=+ 2>/dev/null || echo v0.1-nogit)
 
-CC_VERSION=$(shell $(CC) -v 2>&1|grep -E '(gcc|clang) version')
-
-ifneq (,$(findstring gcc,$(CC_VERSION)))
-       CFLAGS+=-Wno-unused-but-set-variable
-endif
-
-ifneq (,$(findstring clang,$(CC_VERSION)))
-       CFLAGS+=-Wno-missing-braces
-endif
+include Kbuild.include
 
-ifdef D
-       CFLAGS+=-Werror
-       CFLAGS+=-DCONFIG_BCACHEFS_DEBUG=y
-       CFLAGS+=-DCONFIG_VALGRIND=y
-endif
+CFLAGS+=$(call cc-disable-warning, unused-but-set-variable)
+CFLAGS+=$(call cc-disable-warning, stringop-overflow)
+CFLAGS+=$(call cc-disable-warning, zero-length-bounds)
+CFLAGS+=$(call cc-disable-warning, missing-braces)
+CFLAGS+=$(call cc-disable-warning, zero-length-array)
+CFLAGS+=$(call cc-disable-warning, shift-overflow)
+CFLAGS+=$(call cc-disable-warning, enum-conversion)
 
-PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd"
+PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev"
 ifdef BCACHEFS_FUSE
        PKGCONFIG_LIBS+="fuse3 >= 3.7"
        CFLAGS+=-DBCACHEFS_FUSE
@@ -57,7 +50,7 @@ endif
 CFLAGS+=$(PKGCONFIG_CFLAGS)
 LDLIBS+=$(PKGCONFIG_LDLIBS)
 
-LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio
+LDLIBS+=-lm -lpthread -lrt -lscrypt -lkeyutils -laio -ldl
 LDLIBS+=$(EXTRA_LDLIBS)
 
 ifeq ($(PREFIX),/usr)
@@ -71,8 +64,11 @@ endif
 .PHONY: all
 all: bcachefs
 
+.PHONY: tests
+tests: tests/test_helper
+
 .PHONY: check
-check: tests/test_helper bcachefs
+check: tests bcachefs
        cd tests; $(PYTEST)
 
 .PHONY: TAGS tags
@@ -89,6 +85,20 @@ DEPS=$(SRCS:.c=.d)
 OBJS=$(SRCS:.c=.o)
 bcachefs: $(filter-out ./tests/%.o, $(OBJS))
 
+MOUNT_SRCS=$(shell find mount/src -type f -iname '*.rs') \
+    mount/Cargo.toml mount/Cargo.lock mount/build.rs
+
+debug: CFLAGS+=-Werror -DCONFIG_BCACHEFS_DEBUG=y -DCONFIG_VALGRIND=y
+debug: bcachefs
+
+libbcachefs_mount.a: $(MOUNT_SRCS)
+       LIBBCACHEFS_INCLUDE=$(CURDIR) cargo build --manifest-path mount/Cargo.toml --release
+       cp mount/target/release/libbcachefs_mount.a $@
+
+MOUNT_OBJ=$(filter-out ./bcachefs.o ./tests/%.o ./cmd_%.o , $(OBJS))
+mount.bcachefs: libbcachefs_mount.a $(MOUNT_OBJ)
+       $(CC) -Wl,--gc-sections libbcachefs_mount.a $(MOUNT_OBJ) -o $@ $(LDLIBS)
+
 tests/test_helper: $(filter ./tests/%.o, $(OBJS))
 
 # If the version string differs from the last build, update the last version
@@ -101,6 +111,9 @@ endif
 # Rebuild the 'version' command any time the version string changes
 cmd_version.o : .version
 
+doc/bcachefs.5: doc/bcachefs.5.txt
+       a2x -f manpage doc/bcachefs.5.txt
+
 .PHONY: install
 install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
 install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
@@ -111,12 +124,14 @@ install: bcachefs
        $(INSTALL) -m0644 -D bcachefs.8    -t $(DESTDIR)$(PREFIX)/share/man/man8/
        $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
        $(INSTALL) -m0755 -D initramfs/hook   $(DESTDIR)$(INITRAMFS_HOOK)
+       $(INSTALL) -m0755 -D mount.bcachefs.sh $(DESTDIR)$(ROOT_SBINDIR)
        sed -i '/^# Note: make install replaces/,$$d' $(DESTDIR)$(INITRAMFS_HOOK)
        echo "copy_exec $(ROOT_SBINDIR)/bcachefs /sbin/bcachefs" >> $(DESTDIR)$(INITRAMFS_HOOK)
 
 .PHONY: clean
 clean:
-       $(RM) bcachefs tests/test_helper .version $(OBJS) $(DEPS)
+       $(RM) bcachefs mount.bcachefs libbcachefs_mount.a tests/test_helper .version $(OBJS) $(DEPS)
+       $(RM) -rf mount/target
 
 .PHONY: deb
 deb: all
@@ -129,10 +144,22 @@ update-bcachefs-sources:
        git rm -rf --ignore-unmatch libbcachefs
        test -d libbcachefs || mkdir libbcachefs
        cp $(LINUX_DIR)/fs/bcachefs/*.[ch] libbcachefs/
+       git add libbcachefs/*.[ch]
        cp $(LINUX_DIR)/include/trace/events/bcachefs.h include/trace/events/
+       git add include/trace/events/bcachefs.h
+       cp $(LINUX_DIR)/kernel/locking/six.c linux/
+       git add linux/six.c
+       cp $(LINUX_DIR)/include/linux/six.h include/linux/
+       git add include/linux/six.h
+       cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
+       git add include/linux/list_nulls.h
+       cp $(LINUX_DIR)/include/linux/poison.h include/linux/
+       git add include/linux/poison.h
+       cp $(LINUX_DIR)/scripts/Kbuild.include ./
+       git add Kbuild.include
        $(RM) libbcachefs/*.mod.c
        git -C $(LINUX_DIR) rev-parse HEAD | tee .bcachefs_revision
-       git add libbcachefs/*.[ch] include/trace/events/bcachefs.h .bcachefs_revision
+       git add .bcachefs_revision
 
 .PHONE: update-commit-bcachefs-sources
 update-commit-bcachefs-sources: update-bcachefs-sources