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

include /usr/share/dpkg/architecture.mk

ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
# XXX: qtchooser is dead upstream (https://bugs.debian.org/1011935), so
# cross compilation under Qt6 will need something other than QT_SELECT.
export QT_SELECT=qt5-$(DEB_BUILD_MULTIARCH)-$(DEB_HOST_MULTIARCH)
endif

export PKG_CONFIG_PATH=/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

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

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-qt5 -- -DQT_MAJOR_VERSION=5
	dh_auto_configure --builddirectory=build-qt6 -- -DQT_MAJOR_VERSION=6

override_dh_auto_build:
	dh_auto_build --builddirectory=build-qt5
	dh_auto_build --builddirectory=build-qt6

override_dh_auto_install:
	dh_auto_install --builddirectory=build-qt5
	dh_auto_install --builddirectory=build-qt6
	sed -i 's#/opt/tests/libqofono-qt5/runtest.sh#/usr/libexec/libqofono-qt5/tests/runtest.sh#' debian/tmp/usr/libexec/libqofono-qt5/tests/tests.xml
	sed -i 's#/opt/tests/libqofono-qt5/runtest.sh#/usr/libexec/libqofono-qt6/tests/runtest.sh#' debian/tmp/usr/libexec/libqofono-qt6/tests/tests.xml

override_dh_auto_clean:
	dh_auto_clean --builddirectory=build-qt5
	dh_auto_clean --builddirectory=build-qt6

override_dh_missing:
	dh_missing --list-missing

override_dh_fixperms:
	dh_fixperms
	chmod a-x debian/libqofono-tests/usr/libexec/libqofono-qt*/tests/tests.xml

# FIXME: disable tests for now. These require ofono to be running and probably
#  need more love before they can be run during build-time (LP: #1334652)
override_dh_auto_test:
#	LD_LIBRARY_PATH=../../../src dh_auto_test

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
