#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  CC := $(DEB_HOST_GNU_TYPE)-gcc
else
  CC := gcc
endif

SHELL := sh -e

CFLAGS := $(shell dpkg-buildflags --get CFLAGS)
CFLAGS := $(patsubst -O2,-Os,$(CFLAGS))

ZSTD := $(shell grep '^udeb: ' /var/lib/dpkg/info/libzstd*.shlibs)

%:
	dh ${@} --with bash-completion,python3

override_dh_autoreconf:
	dh_autoreconf ./autogen.sh

override_dh_auto_configure:
ifneq (,$(ZSTD))
	dh_auto_configure -- --bindir=/bin --disable-convert --enable-zstd
else
	dh_auto_configure -- --bindir=/bin --disable-convert --disable-zstd
endif

override_dh_auto_build:
	dh_auto_build -- V=1

override_dh_auto_install:
	dh_auto_install -- install install_python

	# Adding initramfs-tools integration
	install -D -m 0755 debian/local/btrfs.hook debian/btrfs-progs/usr/share/initramfs-tools/hooks/btrfs
	install -D -m 0755 debian/local/btrfs.local-premount debian/btrfs-progs/usr/share/initramfs-tools/scripts/local-premount/btrfs

# Needs autopkgtest
override_dh_auto_test:

override_dh_install:
	dh_install
	dh_missing --list-missing

override_dh_strip:
	dh_strip --dbgsym-migration='btrfs-progs (<< 4.11.1+dfsg-1~)'

override_dh_auto_clean:
	if test -f Makefile.inc; then \
		dh_auto_clean; \
	fi
