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

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

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

%:
	dh $@ --buildsystem=qmake

override_dh_auto_configure:
	dh_auto_configure --builddirectory=build-qt6 --buildsystem=cmake
	./configure -tests -icu -prefix /usr -libdir /usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_auto_build:
	dh_auto_build --builddirectory=build-qt6 --buildsystem=cmake
	 /usr/lib/qt5/bin/qmake -o Makefile src/src.pro QMAKE_CXXFLAGS="${CPPFLAGS} ${CXXFLAGS}" QMAKE_CFLAGS="${CPPFLAGS} ${CFLAGS}" QMAKE_LFLAGS="${LDFLAGS}"
	dh_auto_build --buildsystem=qmake

override_dh_auto_test:
	mkdir -p debian/test-home/.local/share
	# Qt 6 variant's unit tests
	HOME=$(shell pwd)/debian/test-home xvfb-run -a dh_auto_test --builddirectory=build-qt6 --buildsystem=cmake
	# Qt 5 variant's unit tests
	# Nasty hack: the 'check' target expects libsrc.so.0.1.1 instead of libmlocale5.so.0.1.1.
	# Tststs... let's fulfill that expectation...
	ln -s libmlocale5.so.0.1.1 lib/libsrc.so.0.1.1
	HOME=$(shell pwd)/debian/test-home xvfb-run -a dh_auto_test --no-parallel

override_dh_auto_install:
	dh_auto_install --builddirectory=build-qt6 --buildsystem=cmake
	dh_auto_install --buildsystem=qmake

override_dh_auto_clean:
	dh_auto_clean --builddirectory=build-qt6 --buildsystem=cmake
	dh_auto_clean --buildsystem=qmake

execute_after_dh_clean:
	rm -fR debian/test-home/
	rm -f  .qmake.cache
	rm -f  benchmarks/tests.xml
	rm -f  mkspecs/features/mlocale_defines.prf
	rm -f  mkspecs/mlocaleconfig.pri
	rm -f  src/data/mlocale5.pc
	rm -f  tests/tests.xml
	rm -f  lib/libsrc.so.0.1.1

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