#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
include /usr/share/dpkg/default.mk

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

VERSION_CLEAN_UPSTREAM = $(call dpkg_late_eval,VERSION_CLEAN_UPSTREAM,echo '$(DEB_VERSION_UPSTREAM)' | sed -e 's/~.*//')

%:
	dh $@ --with pkgkde_symbolshelper

override_dh_clean:
	dh_clean

	rm -rf doc
	rm -f src/webview/QtWebView.version.in
	rm -f qml/QtWebView/qmldir
	rm -f src/imports/qmldir
	rm -f src/webview/codeattributions.qdoc
	rm -f qml/QtWebView/plugins.qmltypes

override_dh_auto_configure:
	qmake QT_BUILD_PARTS+=" tests"

override_dh_auto_build-indep:
	dh_auto_build -- docs

override_dh_auto_install-arch:
	dh_auto_install

	# Remove private headers
	rm -rfv debian/tmp/usr/include/$(DEB_HOST_MULTIARCH)/qt5/QtWebView/$(VERSION_CLEAN_UPSTREAM)
	# And associated files
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/mkspecs/modules/qt_lib_webview_private.pri

	# Remove example with privacy breaks (remote scripts and styles)
	rm -rfv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/examples/webchannel/chatclient-html/

	# Remove libtool-like files
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.la

override_dh_auto_test:
	# Tests work only with native backends, see tests/tests.pro.

override_dh_auto_install-indep:
	make INSTALL_ROOT=$(CURDIR)/debian/tmp install_docs

override_dh_missing:
	dh_missing --fail-missing
