#!/usr/bin/make -f
# -*- makefile -*-

export DH_VERBOSE=1
export PYBUILD_NAME=pyfuse3
export PYBUILD_TEST_PYTEST=1
export PYBUILD_TEST_ARGS=--installed "{dir}/test/"

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

ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
execute_after_dh_auto_build:
	# The compiled extension is built by the upstream pyproject backend;
	# point sphinx autodoc at the pybuild build dir so it can import it.
	PYTHONPATH="$(firstword $(wildcard $(CURDIR)/.pybuild/cpython3_*/build))" \
		sphinx-build -b html rst doc/html
endif

execute_after_dh_auto_install:
	# Drop the Cython-generated C sources - it is a build artifact which differs
	# between Python versions and must not be shipped.
	find debian/python3-pyfuse3 -name '__init__.c' -delete

execute_before_dh_auto_clean:
	# Remove documentation and cython output
	rm -rf build_cython build_sphinx doc/
	rm -rf src/pyfuse3/*.so test/.pytest_cache/
