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

NULL =

export DEB_BUILD_MAINT_OPTIONS = hardening=+all optimize=+lto

# makes the tests pass in Ubuntu
ifeq ($(shell dpkg-vendor --is Ubuntu && echo yes),yes)
export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions
endif

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

%:
	dh $@ --

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-qt6 --buildsystem=cmake -- \
		-DBUILD_WITH_QT6=ON  -Denable-glib=OFF -Denable_examples=ON ..
	dh_auto_configure --builddirectory=build-qt5 --buildsystem=cmake -- \
		-DBUILD_WITH_QT6=OFF -Denable-glib=ON  -Denable_examples=ON ..

override_dh_auto_build:
	dh_auto_build --builddirectory=build-qt6 --buildsystem=cmake ..
	dh_auto_build --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 ..

override_dh_install:
	# drop duplicate files from Qt6 variant build
	rm -rf debian/tmp/usr/share/doc/maliit6-framework-doc

	# re-arrange files in doc:pkg
	mv debian/tmp/usr/share/doc/maliit-framework-doc debian/tmp/usr/share/doc/maliit-framework/html
	rm debian/tmp/usr/share/doc/maliit-framework/LICENSE.LGPL*

	# drop build path from generated .html files
	cd debian/tmp/usr/share/doc/maliit-framework/html && \
	    find . -type f | while read file; do \
	        sed -r -e 's@$(CURDIR)@@g' -i $$file; \
	    done

	# finally, run dh_install
	dh_install

override_dh_installexamples:
	dh_installexamples

	# drop Vcs control files from doc:pkg
	-find debian/maliit-framework-doc/ -name .gitignore -delete

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq (,$(filter $(DEB_HOST_ARCH),$(TESTSKIP_ARCHITECTURES_QT6)))
	xvfb-run -a dh_auto_test --builddirectory=build-qt6 --buildsystem=cmake --no-parallel ..
endif
ifeq (,$(filter $(DEB_HOST_ARCH),$(TESTSKIP_ARCHITECTURES_QT5)))
	xvfb-run -a dh_auto_test --builddirectory=build-qt5 --buildsystem=cmake --no-parallel ..
endif
endif

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

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