#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

# from the top-level CMakeLists.txt
export KDEV_PLUGIN_VERSION=510

# The list of architectures (expanded, without wildcards) that do not use clang
no_clang_args = alpha hppa ia64 kfreebsd-amd64 kfreebsd-i386 m68k sh4 x32
ifeq (,$(filter $(DEB_HOST_ARCH), $(no_clang_args)))
# The clang-N used for the build by the unversioned clang
current_clang_pkg = $(shell dpkg -S "$(shell realpath $(shell env PATH=$$(echo "$$PATH" | sed -r -e 's|/usr/lib/ccache/?:||') which clang))" | cut -d: -f1)
# The upstream version of a package passed as parameter
upstream_version_of_pkg = $(shell dpkg-query -f '$${Version}' -W $(1) | sed -e 's/-[^-]*$$//')
# The clang dependency string
clang_dependency = $(current_clang_pkg) (>= $(call upstream_version_of_pkg,$(current_clang_pkg))~)
else
clang_dependency =
endif

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -Skf5 -- -DBUILD_TESTING=OFF

execute_after_dh_auto_install:
	# create this directory if not existing, so kdevelop-data.install
	# is the same, no matter whether clang is built
	mkdir -p debian/tmp/usr/share/kdevclangsupport/
	# not useful source documentation
	rm debian/tmp/usr/share/kdevqmljssupport/propertywidgets/README

override_dh_gencontrol:
	dh_gencontrol -- -V'kdevelop:clang=$(clang_dependency)'

.PHONY: override_dh_auto_test
