#!/usr/bin/make -f

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

export CFLAGS := $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed
export QT_SELECT := qt5

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

%:
	dh $@ --fail-missing --parallel --with pkgkde_symbolshelper --dbg-package=qtpim5-dbg

override_dh_auto_clean:
	dh_auto_clean
	rm -f plugins/*/*.so
	rm -f qml/*/*.so

override_dh_auto_configure:
	mkdir .git
	qmake QT_BUILD_PARTS+=tests

override_dh_auto_build-indep:
	dh_auto_build -Smakefile -- docs

override_dh_auto_install:
	dh_auto_install
	$(MAKE) INSTALL_ROOT=$(CURDIR)/debian/tmp install_docs
	
	# Remove private stuff
	rm -rfv debian/tmp/usr/include/*/qt5/QtContacts/*/QtContacts/private/
	rm -rfv debian/tmp/usr/include/*/qt5/QtOrganizer/*/QtOrganizer/private/
	rm -rfv debian/tmp/usr/include/*/qt5/QtVersit/*/QtVersit/private/
	rm -rfv debian/tmp/usr/include/*/qt5/QtVersitOrganizer/*/QtVersitOrganizer/private/
	rm -fv $(CURDIR)/debian/tmp/usr/lib/*/qt5/mkspecs/modules/qt_lib_*_private.pri
	
	# Remove examples
	rm -rf debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/examples
	# Remove libtool-like files
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.la
	# Don't install the skeleton plugin
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/plugins/organizer/libqtorganizer_skeleton.so

override_dh_auto_test:
	xvfb-run -a dh_auto_test -- QT_PLUGIN_PATH=$(CURDIR)/plugins LD_LIBRARY_PATH=$(CURDIR)/lib QT_LOGGING_RULES="default.debug=true"
