#!/usr/bin/make -f

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

NULL =

export DPKG_GENSYMBOLS_CHECK_LEVEL=1

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

include /usr/share/dpkg/architecture.mk

%:
	dh $@ --with pkgkde_symbolshelper

execute_after_dh_auto_clean:
	rm -f plugins/*/*.so
	rm -f qml/*/*.so

override_dh_auto_configure:
	dh_auto_configure -- -DQT_BUILD_TESTS=ON -DQT_BUILD_DOCS=ON

execute_after_dh_auto_build-indep:
	cd obj-$(DEB_HOST_GNU_TYPE) && $(MAKE) docs

execute_after_dh_auto_install:
ifneq (,$(filter %-doc, $(shell dh_listpackages)))
	cd obj-$(DEB_HOST_GNU_TYPE) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install_docs
endif

	mkdir -p debian/tmp/usr/share/doc/qtpim6-examples/examples/organizer/
	cp -av examples/organizer/qmlorganizerlistview/ debian/tmp/usr/share/doc/qtpim6-examples/examples/organizer/
	cp -av examples/contacts/ debian/tmp/usr/share/doc/qtpim6-examples/examples/

	# Don't install the skeleton plugin
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt6/plugins/organizer/libqtorganizer_skeleton.so \
	    debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/qt6Organizer/qt6Organizer_QSkeletonOrganizerPlugin.cmake

ifneq (,$(filter %-doc, $(shell dh_listpackages)))
	mkdir -p debian/tmp/usr/share/doc/qtpim-doc-html/
	mv debian/tmp/usr/share/qt6/doc/qtcontacts debian/tmp/usr/share/doc/qtpim-doc-html/
	mv debian/tmp/usr/share/qt6/doc/qtorganizer debian/tmp/usr/share/doc/qtpim-doc-html/
	mv debian/tmp/usr/share/qt6/doc/qtversit debian/tmp/usr/share/doc/qtpim-doc-html/
	ln -s ../../doc/qtpim-doc-html/qtcontacts debian/tmp/usr/share/qt6/doc/qtcontacts
	ln -s ../../doc/qtpim-doc-html/qtorganizer debian/tmp/usr/share/qt6/doc/qtorganizer
	ln -s ../../doc/qtpim-doc-html/qtversit debian/tmp/usr/share/qt6/doc/qtversit
	cd debian/tmp/usr/share/doc/qtpim-doc-html/ && rdfind -makeresultsfile false -makesymlinks true . && cd - 1>/dev/null
	cd debian/tmp/usr/share/doc/qtpim-doc-html/ && symlinks -v -c -r . && cd - 1>/dev/null
endif

override_dh_auto_test:
	# The tests add LFs to the test .vcard and .ical files, which dpkg-source doesn't like.
	for f in tests/auto/organizer/qmlorganizer/testcases/*.ical tests/auto/contacts/qmlcontacts/testcases/*.vcard; do cp $${f} $${f}.bak; done
	xvfb-run -a dh_auto_test --no-parallel -- LC_ALL=en_US.UTF-8 QML2_IMPORT_PATH=$(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)/lib/$(DEB_HOST_MULTIARCH)/qt6/qml QT_PLUGIN_PATH=$(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)/lib/$(DEB_HOST_MULTIARCH)/qt6/plugins LD_LIBRARY_PATH=$(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)/lib
	for f in tests/auto/organizer/qmlorganizer/testcases/*.ical tests/auto/contacts/qmlcontacts/testcases/*.vcard; do mv $${f}.bak $${f}; done

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