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

export DPKG_GENSYMBOLS_CHECK_LEVEL=4
export LOMIRI_CONTENT_HUB_TESTING=1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

%:
	dh $@ --with click

# Enable coverage reporting locally for introspecting test coverage
override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-qt6 -- \
		-DENABLE_COVERAGE=OFF \
		-DENABLE_DOC=OFF \
		-DENABLE_QT6=ON \
		-DENABLE_UBUNTU_COMPAT=OFF
	dh_auto_configure --builddirectory=build-qt5 -- \
		-DENABLE_COVERAGE=OFF \
		-DENABLE_DOC=$(if $(filter %-doc,$(shell dh_listpackages)),ON,OFF) \
		-DENABLE_QT6=OFF \
		-DENABLE_UBUNTU_COMPAT=OFF

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

override_dh_auto_test:
	dh_auto_test --builddirectory=build-qt6
	dh_auto_test --builddirectory=build-qt5

override_dh_auto_install:
	mkdir -p debian/lomiri-content-hub-testability
	dh_auto_install --builddirectory=build-qt6
	dh_auto_install --builddirectory=build-qt5
	dh_apparmor -plomiri-content-hub-testability --profile-name=lomiri-content-hub-testability
	mkdir -p debian/tmp/var/cache/lomiri-content-hub/peers

execute_before_dh_install-indep:
ifneq (,$(filter %-doc,$(shell dh_listpackages)))
	# remove duplicate files and symlink them instead
	rmdir debian/tmp/usr/share/doc/lomiri-content-hub/qml/html/images/
	cd debian/tmp/usr/share/doc/lomiri-content-hub/cpp/html/ && rdfind -makesymlinks true -makeresultsfile false .
	cd debian/tmp/usr/share/doc/lomiri-content-hub/cpp/html/ && symlinks -rc .
	cd debian/tmp/usr/share/doc/lomiri-content-hub/qml/html/ && rdfind -makesymlinks true -makeresultsfile false .
	cd debian/tmp/usr/share/doc/lomiri-content-hub/qml/html/ && symlinks -rc .
endif

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

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