#!/usr/bin/make -f

LIB_PKG := $(shell sed -rn 's/^Package:[[:space:]]*(libvte-[0-9\.-]+)[[:space:]]*$$/\1/p' debian/control)
UDEB_PKG := $(LIB_PKG)-udeb

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

%:
	dh $@ --with gnome,gir

override_dh_autoreconf:
	dh_autoreconf --as-needed

CONFFLAGS_deb = \
	--enable-glade-catalogue \
	--enable-gtk-doc \
	--enable-introspection \
	--with-gnutls

CONFFLAGS_udeb = \
	--disable-gtk-doc \
	--without-gnutls

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-deb -- $(CONFFLAGS_deb)
	dh_auto_configure --builddirectory=build-udeb -- $(CONFFLAGS_udeb)

override_dh_auto_build:
	dh_auto_build --builddirectory=build-deb
	dh_auto_build --builddirectory=build-udeb

override_dh_auto_install:
	dh_auto_install --builddirectory=build-deb \
		--destdir=debian/tmp/deb
	dh_auto_install --builddirectory=build-udeb \
		--destdir=debian/tmp/udeb
	mv debian/tmp/deb/etc/profile.d/vte.sh \
		debian/tmp/deb/etc/profile.d/vte-2.91.sh

override_dh_auto_clean:
	dh_auto_clean --builddirectory=build-deb
	dh_auto_clean --builddirectory=build-udeb

override_dh_clean:
	dh_clean
	rm -f src/app.c

override_dh_auto_test:
	dh_auto_test --builddirectory=build-deb

override_dh_makeshlibs:
	dh_makeshlibs -p$(LIB_PKG) --add-udeb=$(UDEB_PKG) -V -- -c4
	dh_makeshlibs --remaining-packages

override_dh_install:
	find debian/tmp -name '*.la' -print -delete
	dh_install -p$(UDEB_PKG) --sourcedir=debian/tmp/udeb
	dh_install --remaining --sourcedir=debian/tmp/deb

override_dh_missing:
	dh_missing --list-missing
