#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export PYBUILD_TEST_PYTEST = 0

%:
	dh $@ --buildsystem=pybuild

# BuildStream ships with pre-complied Python GRPC protocols
# These are incompatible with Debian's outdated python3-protobuf version, so we
# need to recompile with that version
execute_before_dh_auto_build:
	python3 setup.py build_grpc

# Build the documentation
ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
execute_before_dh_install-indep:
	# Replace the symlink to CONTRIBUTING.rst with a copy so sphinxdoc doesn't get
	# confused in the build sandbox
	rm doc/source/CONTRIBUTING.rst
	cp CONTRIBUTING.rst doc/source/CONTRIBUTING.rst

	# Use upstream's script to build the documentation, which needs access to the
	# `buildstream` Python modules we have just built
	$(MAKE) -C doc html PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3.14/dist-packages:$(CURDIR)/debian/tmp/usr/lib/python3.14/dist-packages/buildstream/plugins:/usr/lib/python3/dist-packages
endif

# Ensure pyproject.toml doesn't get installed into /usr/lib/python3/dist-packages
execute_after_dh_auto_install:
	find debian/ -name pyproject.toml -print -delete

# The tests don't work in Debian. Not sure they're very useful for us.
override_dh_auto_test:
	-PYBUILD_SYSTEM=custom PYBUILD_TEST_ARGS="{interpreter} setup.py test" dh_auto_test
