+ifeq ("$(origin V)", "command line")
+ BUILD_VERBOSE = $(V)
+endif
+ifndef BUILD_VERBOSE
+ BUILD_VERBOSE = 0
+endif
+
+ifeq ($(BUILD_VERBOSE),1)
+ Q =
+ CARGO_CLEAN_ARGS = --verbose
+else
+ Q = @
+ CARGO_CLEAN_ARGS = --quiet
+endif
+
+# Prevent recursive expansions of $(CFLAGS) to avoid repeatedly performing
+# compile tests
+CFLAGS:=$(CFLAGS)
+
+CFLAGS+=-std=gnu11 -O2 -g -MMD -Wall -fPIC \
+ -Wno-pointer-sign \
+ -Wno-deprecated-declarations \
+ -fno-strict-aliasing \
+ -fno-delete-null-pointer-checks \
+ -I. -Ic_src -Iinclude -Iraid \
+ -D_FILE_OFFSET_BITS=64 \
+ -D_GNU_SOURCE \
+ -D_LGPL_SOURCE \
+ -DRCU_MEMBARRIER \
+ -DZSTD_STATIC_LINKING_ONLY \
+ -DFUSE_USE_VERSION=35 \
+ -DNO_BCACHEFS_CHARDEV \
+ -DNO_BCACHEFS_FS \
+ -DNO_BCACHEFS_SYSFS \
+ -DVERSION_STRING='"$(VERSION)"' \
+ $(EXTRA_CFLAGS)
+
+# Intenionally not doing the above to $(LDFLAGS) because we rely on
+# recursive expansion here (CFLAGS is not yet completely built by this line)
+LDFLAGS+=$(CFLAGS) $(EXTRA_LDFLAGS)
+
+ifdef CARGO_TOOLCHAIN_VERSION
+ CARGO_TOOLCHAIN = +$(CARGO_TOOLCHAIN_VERSION)
+endif
+
+CARGO_ARGS=${CARGO_TOOLCHAIN}
+CARGO=cargo $(CARGO_ARGS)
+CARGO_PROFILE=release
+# CARGO_PROFILE=debug
+
+CARGO_BUILD_ARGS=--$(CARGO_PROFILE)
+CARGO_BUILD=$(CARGO) build $(CARGO_BUILD_ARGS)
+
+CARGO_CLEAN=$(CARGO) clean $(CARGO_CLEAN_ARGS)
+
+include Makefile.compiler
+
+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)
+CFLAGS+=$(call cc-disable-warning, gnu-variable-sized-type-not-at-end)
+
+PKGCONFIG_LIBS="blkid uuid liburcu libsodium zlib liblz4 libzstd libudev libkeyutils udev"
+ifdef BCACHEFS_FUSE
+ PKGCONFIG_LIBS+="fuse3 >= 3.7"
+ CFLAGS+=-DBCACHEFS_FUSE
+ export RUSTFLAGS=--cfg fuse
+endif
+
+PKGCONFIG_CFLAGS:=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
+ifeq (,$(PKGCONFIG_CFLAGS))
+ $(error pkg-config error, command: $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
+endif
+PKGCONFIG_LDLIBS:=$(shell $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
+ifeq (,$(PKGCONFIG_LDLIBS))
+ $(error pkg-config error, command: $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
+endif
+PKGCONFIG_UDEVDIR:=$(shell $(PKG_CONFIG) --variable=udevdir udev)
+ifeq (,$(PKGCONFIG_UDEVDIR))
+ $(error pkg-config error, command: $(PKG_CONFIG) --variable=udevdir udev)
+endif
+PKGCONFIG_UDEVRULESDIR:=$(PKGCONFIG_UDEVDIR)/rules.d
+
+CFLAGS+=$(PKGCONFIG_CFLAGS)
+LDLIBS+=$(PKGCONFIG_LDLIBS)
+LDLIBS+=-lm -lpthread -lrt -lkeyutils -laio -ldl
+LDLIBS+=$(EXTRA_LDLIBS)
+
+ifeq ($(PREFIX),/usr)
+ ROOT_SBINDIR?=/sbin
+ INITRAMFS_DIR=$(PREFIX)/share/initramfs-tools