#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS
export NO_DOCS := no
export QMAKE_LIBDIR=/usr/lib
export DPKG_GENSYMBOLS_CHECK_LEVEL=4

# don't apply use_keyring patch on armhf, we have no keyring available
DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

override_dh_quilt_patch:
	dh_quilt_patch
	if test -r debian/patches/series.$(DEB_HOST_ARCH); then \
		pc=".pc.$(DEB_HOST_ARCH)"; \
		test -d "$(CURDIR)/$$pc" || mkdir "$(CURDIR)/$$pc"; \
		cp debian/patches/series.$(DEB_HOST_ARCH) $(CURDIR)/$$pc/series; \
		cd $(CURDIR); \
		QUILT_PC="$$pc" quilt upgrade || true; \
		QUILT_PC="$$pc" QUILT_PATCHES="debian/patches/" quilt push -a || true; \
	fi; \

override_dh_quilt_unpatch:
	if test -r debian/patches/series.$(DEB_HOST_ARCH); then \
		pc=".pc.$(DEB_HOST_ARCH)"; \
		cd $(CURDIR); \
		QUILT_PC="$$pc" QUILT_PATCHES="debian/patches/" quilt pop -a || true; \
	fi; \
	dh_quilt_unpatch
# end changes for dropping keyring patch for armhf

override_dh_auto_configure:
	mkdir -p build/qt4 build/qt5
	QT_SELECT=qt4 \
	dh_auto_configure -Bbuild/qt4 -- LIBDIR=/usr/lib \
		BUILD_DIR=build/qt4 \
		"QMAKE_CXXFLAGS=$(CFLAGS)" ../../signon.pro
	QT_SELECT=qt5 \
	dh_auto_configure -Bbuild/qt5 -- LIBDIR=/usr/lib \
		BUILD_DIR=build/qt5 \
		"QMAKE_CXXFLAGS=$(CFLAGS)" ../../signon.pro

override_dh_auto_build:
	QT_SELECT=qt4 dh_auto_build -Bbuild/qt4
	QT_SELECT=qt5 dh_auto_build -Bbuild/qt5

override_dh_auto_clean:
	dh_auto_clean -Bbuild/qt4
	dh_auto_clean -Bbuild/qt5

override_dh_auto_install:
	dh_auto_install -Bbuild/qt4 -plibsignon-qt1
	dh_auto_install -Bbuild/qt4 -plibsignon-qt-dev
	dh_auto_install -Bbuild/qt5

override_dh_install:
	rm -f debian/tmp/usr/include/signon-plugins/*example*.h
	rm -f debian/tmp/usr/include/signon-plugins/*test*.h
	rm -f debian/tmp/usr/lib/libsignon-qt*.*a
	rm -f debian/tmp/usr/lib/signon/libexampleplugin.so
	dh_install --fail-missing

%:
	dh $@ -Bbuild/qt5 --parallel --with migrations,quilt 
