#!/usr/bin/make -f

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

include /usr/share/dpkg/default.mk

# Adjust the version of the flatpak-builder packages so that the version
# currently waiting in NEW will be considered an upgrade
flatpak_builder_version := $(shell echo $(DEB_VERSION) \
	| perl -pe 's/(.*)~builder(.*?)-(.*)/$$2~flatpak$$1-$$3/')

%:
	dh $@ --with=gir

override_dh_autoreconf:
	dh_autoreconf \
		--as-needed \
		debian/autogen.sh \
		-- \
		$(NULL)

override_dh_auto_clean:
	dh_auto_clean
	dh_auto_clean --sourcedirectory=builder

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-silent-rules \
		--enable-docbook-docs \
		--enable-gtk-doc \
		--enable-installed-tests \
		--libexecdir=/usr/lib/flatpak \
		--with-priv-mode=none \
		--with-html-dir=/usr/share/doc/libflatpak-doc \
		--with-privileged-group=sudo \
		--with-system-bubblewrap=bwrap \
		--with-systemdsystemunitdir=/lib/systemd/system \
		$(NULL)
	PATH=$(CURDIR)/debian/PATH:$(PATH) \
	dh_auto_configure --sourcedirectory=builder -- \
		--disable-silent-rules \
		--enable-docbook-docs \
		--enable-installed-tests \
		--libexecdir=/usr/lib/flatpak \
		--with-html-dir=/usr/share/doc/flatpak-builder \
		FLATPAK=flatpak \
		$(NULL)

override_dh_auto_build:
	dh_auto_build
	PATH=$(CURDIR)/debian/PATH:$(PATH) \
	dh_auto_build --sourcedirectory=builder

override_dh_auto_install:
	dh_auto_install
	dh_auto_install --sourcedirectory=builder

override_dh_install:
	install -d debian/tmp/etc/X11/Xsession.d
	install -m644 debian/tmp/etc/profile.d/flatpak.sh \
		debian/tmp/etc/X11/Xsession.d/20flatpak
	rm -f debian/tmp/usr/lib/*/*.la
	dh_install

override_dh_missing:
	dh_missing --fail-missing

override_dh_gencontrol:
	dh_gencontrol -pflatpak-builder -- -v$(flatpak_builder_version)
	dh_gencontrol --remaining-packages

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	debian/test.sh
	PATH=$(CURDIR)/debian/PATH:$(PATH) \
	debian/test-builder.sh
endif
