#!/usr/bin/make -f

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

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

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

%:
	dh $@ --with pkgkde_symbolshelper --parallel

override_dh_auto_configure:
	qmake

override_dh_auto_build-indep:
	dh_auto_build -- docs

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

override_dh_auto_install-arch:
	dh_auto_install

	# libQt5WaylandClient library has no public API, do not ship development files for it
	rm -rfv debian/tmp/usr/include/$(DEB_HOST_MULTIARCH)/qt5/QtWaylandClient/
	rm -rfv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5WaylandClient/
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libQt5WaylandClient.la
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libQt5WaylandClient.prl
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libQt5WaylandClient.so
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/Qt5WaylandClient.pc
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/mkspecs/modules/qt_lib_waylandclient.pri

	# Remove libtool-like file
	rm -vf debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libQt5WaylandCompositor.la

	# Remove private elements.
	rm -rvf debian/tmp/usr/include/$(DEB_HOST_MULTIARCH)/qt5/QtWaylandCompositor/*/QtWaylandCompositor/private
	rm -fv debian/tmp/usr/lib/*/qt5/mkspecs/modules/qt_lib_*_private.pri

	# Hack away weird defunct artifact created by build.
	rm -vf debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5Gui/Qt5Gui_.cmake

override_dh_install:
	dh_install --fail-missing

override_dh_strip:
	dh_strip --dbgsym-migration='qtwayland5-dbg (<< 5.7.0-1~)'
