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

# We cannot use lto due to biometryds plugin system will fail
export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=-lto
include /usr/share/dpkg/default.mk

# Only build hybris support if this is an Ubuntu build with "native" packaging
SOURCE_FORMAT = $(shell dpkg-source --print-format . | tr -d "3.0() ")
BUILD_FOR_UBUNTU = $(shell dpkg-vendor --derives-from Ubuntu)

ifeq ($(BUILDTYPE), quilt)
	BUILD_HYBRIS=OFF
else ifeq ($(shell dpkg-vendor --query vendor),Ubuntu)
	BUILD_HYBRIS=ON
else
	BUILD_HYBRIS=OFF
endif

%:
	dh $@

override_dh_auto_configure:
	# DEB_TARGET_ARCH is to avoid running qml tests on powerpc
	dh_auto_configure --builddirectory=build-qt5 -- \
	                     -DDEB_TARGET_ARCH=$(DEB_TARGET_ARCH)	\
	                     -DENABLE_QT6=OFF				\
	                     -DENABLE_WERROR=$(if $(filter native,$(SOURCE_FORMAT)),ON,OFF) \
	                     -DWITH_HYBRIS=$(BUILD_HYBRIS)		\
	                     $(NULL)
	dh_auto_configure --builddirectory=build-qt6 -- \
	                     -DDEB_TARGET_ARCH=$(DEB_TARGET_ARCH)	\
	                     -DENABLE_QT6=ON				\
	                     -DENABLE_WERROR=$(if $(filter native,$(SOURCE_FORMAT)),ON,OFF) \
	                     -DWITH_HYBRIS=$(BUILD_HYBRIS)		\
	                     $(NULL)

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

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

override_dh_auto_install:
	dh_auto_install --builddirectory=build-qt6
	dh_auto_install --builddirectory=build-qt5

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

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