#!/usr/bin/make -f
# -*- makefile -*-
# Debian build rules for confget, the configuration variable extractor

include /usr/share/dpkg/default.mk

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
NO_DOC_BUILD=
else
export NO_DOC_BUILD=1
endif

D=	${CURDIR}/debian
DTMP=	$D/tmp
PY=	${CURDIR}/python

D_EX=	$D/confget/usr/share/doc/confget/examples/tests

export TESTDIR=${CURDIR}/t

export PYBUILD_NAME=confget
export PYBUILD_DIR=${PY}
export PYBUILD_TEST_PYTEST=1

# OK, so this is not the best way to set this, but oh well
export PYTEST_ADDOPTS=${PY}/unit_tests

override_dh_auto_configure-arch:
	mkdir -p -- rust/.cargo
	install -m 644 -- '$D/cargo-config.toml' rust/.cargo/config.toml

override_dh_auto_build-arch:
	{ \
		set -e; \
		cd rust; \
		cargo build --release; \
	}

override_dh_auto_build-indep:
	dh_auto_build --buildsystem pybuild

override_dh_auto_install-arch:

override_dh_auto_install-indep:
	dh_auto_install --buildsystem pybuild

override_dh_auto_test-arch:
	{ \
		set -e; \
		cd rust; \
		cargo test --release; \
	}
	env CONFGET="${CURDIR}/rust/target/release/confget" prove t

override_dh_auto_test-indep:
	env PYTHONPATH='${PY}/src' '$D/tests/tap-python.sh'
	dh_auto_test --buildsystem pybuild

override_dh_installchangelogs:
	dh_installchangelogs -X CHANGES
	set -e; for pkg in $$(dh_listpackages); do \
		install -m 644 CHANGES "debian/$$pkg/usr/share/doc/$$pkg/NEWS"; \
	done

override_dh_installexamples:
	mkdir -p -- '${D_EX}'
	install -m 644 -- t/*.ini t/*.t '${D_EX}/'

execute_after_dh_auto_clean-indep:
	if dpkg-query -W -f '$${Package}\n' | fgrep -qxe python3-setuptools; then \
		dh_auto_clean --buildsystem pybuild; \
	fi

%:
	dh '$@'
