#!/usr/bin/make -f

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

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

# QMF environment variables should be set
export QMF_INCLUDEDIR := /usr/include/qmfclient
export QMF_LIBDIR := /usr/lib

%:
	dh $@ --parallel --list-missing --dbg-package=qtmobility-dbg --with pkgkde_symbolshelper

override_dh_auto_configure:
	./configure \
	    -prefix "/usr" \
	    -headerdir "/usr/include" \
	    -libdir "/usr/lib/$(DEB_HOST_MULTIARCH)" \
	    -bindir "/usr/bin" \
	    -plugindir "/usr/lib/$(DEB_HOST_MULTIARCH)/qt4/plugins" \
	    -demosdir "/usr/lib/qtmobility/demos" \
	    -examplesdir "/usr/lib/qtmobility/examples" \
	    -languages "ar cs da de es fr he hu ja pl pt ru sk sl sv zh_CN zh_TW" \
	    -examples \
	    -demos \
	    -modules "location contacts multimedia publishsubscribe versit messaging systeminfo serviceframework sensors gallery organizer feedback connectivity"

override_dh_auto_install:
	dh_auto_install
	find $(CURDIR)/debian/tmp/usr/lib -type f -name '*.prl' \
		-exec sed -i -e "/^QMAKE_PRL_BUILD_DIR/d;s/\(QMAKE_PRL_LIBS =\).*/\1/" {} \;
	# Fix executable permissions
	find $(CURDIR)/debian/tmp/usr/lib/qtmobility -type f -perm /u+x,g+x,o+x \( -false \
		-o -name \*.png \
		-o -name \*.qml \
		-o -name \*.sci \
		-o -name \*.txt \
		-o -name qmldir \
		\) | xargs chmod -x

override_dh_auto_clean:
	dh_auto_clean
	rm -f \
	    .qmake.cache \
	    config.tests/networkmanager/networkmanager \
	    config.tests/qmf/qmf \
	    tools/tools.pro.user
	find \( -false \
	    -o -type f -name Makefile \
	    -o -type f -name \*.o \
	    -o -type f -name config.\* \
	    -o -type f -name mobility\*.prf \
	\) -delete
	rm -rf include lib
