#!/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

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_install:
	dh_auto_install
	
	# 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 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 make check QT_PLUGIN_PATH=$(CURDIR)/plugins LD_LIBRARY_PATH=$(CURDIR)/lib

override_dh_builddeb:
	dh_builddeb -- -Zxz

