#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

ifneq ($(DEB_TARGET_ARCH_OS),linux)
SKIP_FUSE2FS=yes
SKIP_SELINUX=yes
endif

ifneq ($(filter pkg.erofs-utils.no-erofsfuse,$(DEB_BUILD_PROFILES)),)
SKIP_FUSE2FS=yes
endif

COMMON_CONF_FLAGS = --enable-lzma --enable-multithreading --with-uuid \
	--with-zlib --with-libdeflate --with-libzstd \
	--with-xxhash ${EXTRA_CONF_FLAGS}

ifneq ($(SKIP_FUSE2FS),)
COMMON_CONF_FLAGS +=  --disable-fuse
else
COMMON_CONF_FLAGS +=  --enable-fuse
endif

ifneq ($(SKIP_SELINUX),)
COMMON_CONF_FLAGS +=  --without-selinux
else
COMMON_CONF_FLAGS +=  --with-selinux
endif

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
		--with-root-libdir=/lib/$(DEB_HOST_MULTIARCH) \
		${COMMON_CONF_FLAGS}

override_dh_auto_install:
	find $(CURDIR) -name "*.la" -delete
	dh_auto_install --