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

# Archs that do not build depend on QtWebkit do not ship qwebview.
no_qwebview_archs := sh4 m68k

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

# We override qmake until https://bugreports.qt.io/browse/QTBUG-30735
# gets solved (FTBFS with -nocache).
override_dh_auto_configure:
	qmake 

override_dh_auto_clean:
	dh_auto_clean
	rm -fv .qmake.cache
	rm -fv debian/qttools5-dev-tools.install

override_dh_auto_build-indep:
	cd src; qmake
	dh_auto_build -- -Csrc sub-qdoc
	cd src/assistant; qmake
	dh_auto_build -- -Csrc/assistant sub-qhelpgenerator
	cd src/qdoc; qmake
	cd src/assistant/help; qmake
	dh_auto_build -- docs

override_dh_auto_install-arch:
	dh_auto_install
	
	# Remove libtool-like files
	rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.la

	# Remove CMake files for plugins.
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5Designer/*Plugin.cmake

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

override_dh_install:
ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(no_qwebview_archs)))
	grep -v qwebview debian/qttools5-dev-tools.install.in >> debian/qttools5-dev-tools.install
else
	cp debian/qttools5-dev-tools.install.in debian/qttools5-dev-tools.install
endif
	dh_install --fail-missing

override_dh_strip:
	dh_strip -pqttools5-examples --dbgsym-migration='qttools5-examples-dbg (<< 5.7.1-1~)'
	dh_strip --remaining-packages --dbgsym-migration='qttools5-dbg (<< 5.7.1-1~)'

override_dh_auto_test-indep:
