#!/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 QT_SELECT := qt5
export LLVM_INSTALL_DIR := "/usr/lib/llvm-7"

# Upstream changelog
upstream_changes := $(wildcard dist/changes-*)

%:
	dh $@ --builddirectory=builddir

override_dh_auto_configure:
	dh_auto_configure -- \
		-recursive \
		QBS_INSTALL_DIR=/usr \
		USE_SYSTEM_BOTAN=1 \
		LLVM_INSTALL_DIR="$(LLVM_INSTALL_DIR)" \
		CONFIG+="disable_external_rpath use_system_botan" \
		$(CURDIR) IDE_LIBRARY_BASENAME=lib/$(DEB_HOST_MULTIARCH) IDE_PACKAGE_MODE=1 $(extra_configure_opts)

override_dh_auto_install:
ifneq (,$(filter qtcreator-doc, $(shell dh_listpackages)))
	dh_auto_build -- qch_docs
endif
	dh_auto_install --destdir=debian/tmp/usr
	dh_auto_build -- install_docs INSTALL_ROOT=$(CURDIR)/debian/tmp/usr

	# Do not install the file, we better symlink it.
	rm -vf debian/tmp/usr/share/qtcreator/debugger/LICENSE.LGPL

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

override_dh_missing:
	dh_missing --fail-missing

override_dh_installdocs:
	dh_installdocs -pqtcreator-data $(upstream_changes)
	dh_installdocs --remaining-packages

override_dh_shlibdeps:
	dh_shlibdeps -l$(CURDIR)/debian/qtcreator/usr/lib/$(DEB_HOST_MULTIARCH)/qtcreator:\
	$(CURDIR)/debian/qtcreator/usr/lib/$(DEB_HOST_MULTIARCH)/qtcreator/plugins/QtProject
