#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@ --parallel --with=autoreconf,gir,systemd

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-silent-rules \
		--enable-installed-tests \
		--libexecdir=/usr/lib/flatpak \
		--with-priv-mode=none \
		--with-html-dir=/usr/share/doc/libflatpak-doc \
		--with-systemdsystemunitdir=/lib/systemd/system \
		--enable-gtk-doc \
		$(NULL)

override_dh_install:
	rm -f debian/tmp/usr/lib/*/*.la
	if dpkg-vendor --derives-from Ubuntu; then \
		sed -i \
			-e 's,subject\.isInGroup("sudo"),(subject.isInGroup("sudo") || subject.isInGroup("admin")),g' \
			debian/tmp/usr/share/polkit-1/rules.d/org.freedesktop.Flatpak.rules; \
	fi
	dh_install --fail-missing

# On Debian, unprivileged user namespaces are not available by default,
# so install bwrap setuid. On Ubuntu, they're available by default, so
# don't install it setuid. Assume that derivatives are like Debian, since
# that will make Flatpak work regardless.
override_dh_fixperms-arch:
	dh_fixperms -a
	if ! dpkg-vendor --is Ubuntu; then \
		chmod 4755 debian/flatpak/usr/lib/*/flatpak/bwrap; \
	fi

override_dh_auto_test:
	VERBOSE=1 dh_auto_test
