#!/usr/bin/make -f

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

export PYBUILD_NAME=jack
# keep __pycache__ out of the source tree during the build
export PYTHONDONTWRITEBYTECODE=1
export SETUPTOOLS_SCM_PRETEND_VERSION:=$(shell dpkg-parsechangelog -S version | sed -e 's/^[0-9]*://' -e 's/-.*//' -e 's/~/.0+/g')

%:
	dh $@ --with=python3 --buildsystem=pybuild

override_dh_auto_build:
	@echo "jack version for setuptools-scm: $(SETUPTOOLS_SCM_PRETEND_VERSION)"
	python3 -c 'import os; from packaging.version import Version; Version(os.environ["SETUPTOOLS_SCM_PRETEND_VERSION"])'
	dh_auto_build

# pybuild runs unittest discovery in its build directory, where the upstream
# tests/ are not copied, so it finds no tests at all. Run the real suite from
# the source tree; it only writes to temporary directories.
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	python3 -m unittest discover -v -s tests
endif

# setuptools builds in the source tree and leaves these behind; clean them so
# they cannot end up in the source package of a rebuild.
override_dh_auto_clean:
	dh_auto_clean
	rm -rf build jack.egg-info
