#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/default.mk

export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

ENABLE_TESTS = ON
ifneq (,$(filter $(DEB_HOST_ARCH),s390x powerpc ppc64el))
        ENABLE_TESTS = OFF
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-qt6 --buildsystem=cmake .. -- \
		-DENABLE_TESTS=OFF \
		-DENABLE_UBUNTU_COMPAT=OFF \
		-DENABLE_QT6=ON \
		-DBUILD_LIBCONNECTIVITY_ONLY=ON
	dh_auto_configure --builddirectory=build-qt5 --buildsystem=cmake .. -- \
		-DENABLE_MECHANICD=ON \
		-DENABLE_TESTS=${ENABLE_TESTS} \
		-DENABLE_UBUNTU_COMPAT=ON \
		-DENABLE_QT6=OFF \
		-DBUILD_LIBCONNECTIVITY_ONLY=OFF

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

override_dh_auto_test:
	dh_auto_build --no-parallel --builddirectory=build-qt6 --buildsystem=cmake ..
	dh_auto_build --no-parallel --builddirectory=build-qt5 --buildsystem=cmake ..

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

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

override_dh_gencontrol:
	dh_gencontrol -- $(SUBST_VAR)

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