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

export DPKG_GENSYMBOLS_CHECK_LEVEL=4
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/default.mk

export QT_SELECT := 5
# The home directory of user buildd does not exist on the builders
export XDG_DATA_HOME=/tmp

%:
	dh $@

# FIXME: This should say `--derives-from UBports`, but we haven't got time to
# make a dpkg vendor entry yet.
WITH_HYBRIS = $(shell \
	dpkg-vendor --derives-from Ubuntu \
		&& echo '-DWITH_HYBRIS=ON' \
		|| echo '-DWITH_HYBRIS=OFF')

override_dh_auto_configure:
	# DEB_TARGET_ARCH is to avoid running qml tests on powerpc
	dh_auto_configure --builddirectory=build-qt5 --buildsystem=cmake .. -- \
	                     -DDEB_TARGET_ARCH=$(DEB_TARGET_ARCH)	\
	                     -DENABLE_WERROR=ON				\
	                     -DENABLE_QT6=OFF				\
	                     $(WITH_HYBRIS)				\
	                     $(NULL)
	dh_auto_configure --builddirectory=build-qt6 --buildsystem=cmake .. -- \
	                     -DDEB_TARGET_ARCH=$(DEB_TARGET_ARCH)	\
	                     -DENABLE_WERROR=OFF			\
	                     -DENABLE_QT6=ON				\
	                     $(WITH_HYBRIS)				\
	                     $(NULL)

override_dh_auto_build:
	dh_auto_build --builddirectory=build-qt5 --buildsystem=cmake ..
	dh_auto_build --builddirectory=build-qt6 --buildsystem=cmake ..

override_dh_auto_test:
	# we have seen test failures when building with 8 cores instead of 4
	dh_auto_test --builddirectory=build-qt5 --buildsystem=cmake --no-parallel ..
	dh_auto_test --builddirectory=build-qt6 --buildsystem=cmake --no-parallel ..

override_dh_auto_install:
	dh_auto_install --builddirectory=build-qt6 --buildsystem=cmake ..
	dh_auto_install --builddirectory=build-qt5 --buildsystem=cmake ..

override_dh_auto_clean:
	dh_auto_clean --builddirectory=build-qt5 --buildsystem=cmake ..
	dh_auto_clean --builddirectory=build-qt6 --buildsystem=cmake ..
