#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

NULL =

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

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

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

include /usr/share/dpkg/default.mk

# Ignore test failures on less relevant architectures
testskip_architectures := s390x

%:
	dh $@

override_dh_install:
	rm -Rv debian/tmp/usr/lib/*/lomiri-location-service/examples/
	rm -Rv debian/tmp/usr/share/lomiri-location-service/examples/
	cd debian/tmp/usr/share/doc/lomiri-location-service/html/ && rdfind -makesymlinks true -makeresultsfile false .
	cd debian/tmp/usr/share/doc/lomiri-location-service/html/ && symlinks -rc .
	dh_install -Xlomiri-location-service.1

override_dh_auto_configure:
	# -dM -E do not compile anything but only generate lists of #define, no hardening flags are needed here
	@echo 'blhc: ignore-line-regexp: .*g\+\+.*-dM -E.*'
	if [ ! -e po/lomiri-location-service.pot.deb-bak ]; then cp po/lomiri-location-service.pot po/lomiri-location-service.pot.deb-bak; fi
	dh_auto_configure --builddirectory=build-qt5 -- \
	        -DCMAKE_INSTALL_LIBEXECDIR=/usr/lib/$(DEB_HOST_MULTIARCH)/lomiri-location-service \
	        -DCMAKE_C_COMPILER=$(CC) \
	        -DCMAKE_CXX_COMPILER=$(CXX) \
	        -DENABLE_TRUST_STORE=OFF \
	        -DLOCATION_SERVICE_ENABLE_GPS_PROVIDER=OFF \
	        -DLOCATION_SERVICE_ENABLE_GEOCLUE_PROVIDER=ON \
	        -DENABLE_QT6=OFF \
	        $(NULL)
	dh_auto_configure --builddirectory=build-qt6 -- \
	        -DCMAKE_INSTALL_LIBEXECDIR=/usr/lib/$(DEB_HOST_MULTIARCH)/lomiri-location-service \
	        -DCMAKE_C_COMPILER=$(CC) \
	        -DCMAKE_CXX_COMPILER=$(CXX) \
	        -DENABLE_TRUST_STORE=OFF \
	        -DLOCATION_SERVICE_ENABLE_GPS_PROVIDER=OFF \
	        -DLOCATION_SERVICE_ENABLE_GEOCLUE_PROVIDER=ON \
	        -DENABLE_QT6=ON \
	        $(NULL)

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

# Don't run tests in parallel as fake web servers all bind to same port
override_dh_auto_test:
ifeq (,$(filter $(DEB_HOST_ARCH),$(testskip_architectures)))
	dh_auto_test --builddirectory=build-qt5 --no-parallel -- ARGS+="-E '^(remote_providerd_test|delayed_service_test|daemon_and_cli_tests)'"
	dh_auto_test --builddirectory=build-qt6 --no-parallel -- ARGS+="-E '^(remote_providerd_test|delayed_service_test|daemon_and_cli_tests)'"
else
	dh_auto_test --builddirectory=build-qt5 --no-parallel -- ARGS+="-E '^(remote_providerd_test|delayed_service_test|daemon_and_cli_tests|acceptance_tests)'"
	dh_auto_test --builddirectory=build-qt6 --no-parallel -- ARGS+="-E '^(remote_providerd_test|delayed_service_test|daemon_and_cli_tests|acceptance_tests)'"
endif

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

execute_before_dh_clean:
	-mv po/lomiri-location-service.pot.deb-bak po/lomiri-location-service.pot

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