#!/usr/bin/make -f

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

include /usr/share/dpkg/architecture.mk

# Do not build the HelloWorld plugin, as it is not needed
export QTC_BUILD_PLUGIN_HELLOWORLD=FALSE

# The upstream version of a package passed as parameter
upstream_version_of_pkg = $(shell dpkg-query -f '$${Version}' -W $(1) | sed -e 's/-[^-]*$$//')

%:
	dh $@ --builddirectory=builddir

override_dh_auto_configure:
	dh_auto_configure --buildsystem=cmake -- \
		-DBUILD_QBS=OFF \
		-DWITH_TESTS=OFF \
		-DBUILD_TESTING=OFF \
		-DCLANGTOOLING_LINK_CLANG_DYLIB=ON \
		-DBUILD_EXECUTABLE_CMDBRIDGE=OFF \
		-DQTC_USE_INTERNAL_TASKTREE=OFF \
		-DWITH_DOCS=$(if $(filter qtcreator-doc, $(shell dh_listpackages)),ON,OFF) \
		$(EXTRA_CMAKE_ARGS)

execute_after_dh_auto_build-indep:
	dh_auto_build -- docs

execute_after_dh_auto_install:
ifneq (,$(filter qtcreator-doc, $(shell dh_listpackages)))
	DESTDIR=$(CURDIR)/debian/tmp cmake --install $(CURDIR)/builddir --component qch_docs
	DESTDIR=$(CURDIR)/debian/tmp cmake --install $(CURDIR)/builddir --component html_docs
endif

	# Not needed
	rm debian/tmp/usr/bin/qtcreator.sh

	# License files of the embedded copy of KSyntaxHighlighting
	rm -rf debian/tmp/usr/share/qtcreator/generic-highlighter/syntax/licenses/

execute_after_dh_install:
	# Copied in qtcreator-doc already
	rm -rf debian/qtcreator-data/usr/share/qtcreator/doc/

override_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/$(DEB_HOST_MULTIARCH)/qtcreator/

override_dh_shlibdeps:
	echo 'libQt6DesignerComponents 6 libqt6designercomponents6 (>= $(call upstream_version_of_pkg,libqt6designercomponents6)~)' > debian/shlibs.local
	dh_shlibdeps -l$(CURDIR)/debian/qtcreator/usr/lib/$(DEB_HOST_MULTIARCH)/qtcreator
	rm debian/shlibs.local

override_dh_strip:
	dh_strip -Xusr/libexec/qtcreator/cmdbridge
