#!/usr/bin/make -f
# -*- makefile -*-
#export DH_VERBOSE=1

built_binaries := $(shell dh_listpackages)

ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armel armhf i386 loong64 mips64el mipsel ppc64el s390x powerpc ppc64 riscv64 sparc64 x32))
	ENABLE_COMPOSE=true
else
	ENABLE_COMPOSE=false
endif

AS_CONFIGURE_ARGS = -Dapt-support=true \
		-Dcompose=$(ENABLE_COMPOSE) \
		-Dvapi=true \
		-Dqt=true \
		-Dqt-versions=5,6

ifneq ($(DEB_HOST_ARCH_OS), linux)
	AS_CONFIGURE_ARGS += -Dsystemd=false
endif

ifeq ($(filter %-doc,$(built_binaries)),)
	AS_CONFIGURE_ARGS += -Dapidocs=false
else
	AS_CONFIGURE_ARGS += -Dapidocs=true
endif

%:
	dh $@

override_dh_auto_configure:
	@SETUPTOOLS_DISTUTILS=$$(python3 -c "import os, setuptools; print(os.path.join(os.path.dirname(setuptools.__file__), '_distutils'))" 2>/dev/null); \
	if [ -d "$$SETUPTOOLS_DISTUTILS" ]; then \
		echo "Injecting shim into setuptools vendored path: $$SETUPTOOLS_DISTUTILS"; \
		echo "class MSVCCompiler: pass" > "$$SETUPTOOLS_DISTUTILS/msvccompiler.py"; \
	fi

	dh_auto_configure -- $(AS_CONFIGURE_ARGS)

override_dh_missing:
	dh_missing --fail-missing
