#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.

include /usr/share/dpkg/architecture.mk

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

# The list of architectures (expanded, without wildcards) that do not use clang
no_clang_args = alpha hppa ia64 loong64 m68k sh4 sparc64 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

#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

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