#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow
export SED = /bin/sed
export GREP = /bin/grep
export EGREP = /bin/grep -E
export FGREP = /bin/grep -F

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

# COMMON_CONF_FLAGS = --with-uuid --with-selinux --enable-lzma
# lzma_microlzma_encoder is not support in uos, so disable it.
# uos1070 ships libdeflate without pkg-config metadata, so skip it here.
COMMON_CONF_FLAGS = --with-uuid --with-selinux \
	--with-zlib ${EXTRA_CONF_FLAGS}

ifneq ($(SKIP_FUSE2FS),)
COMMON_CONF_FLAGS +=  --disable-fuse
else
COMMON_CONF_FLAGS +=  --enable-fuse --enable-static-fuse
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:
	dh_auto_install
	/bin/bash ./libtool --finish $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/

	rm -r $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/liberofsfuse.la
	rm -r $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/liberofsfuse.so*

override_dh_missing:
	dh_missing --fail-missing
