#!/usr/bin/make -f

export PYBUILD_NAME = stegx
export PYBUILD_SYSTEM = pyproject

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

override_dh_auto_configure:
	# Relax pyproject.toml dependency pins to versions actually available
	# in Debian trixie. Distro maintainers handle CVE backports separately
	# from the upstream version pins we keep in the PyPI sdist.
	cp pyproject.toml pyproject.toml.deborig
	sed -i \
	    -e 's|"Pillow>=10\.3\.0"|"Pillow>=10.0.0"|' \
	    -e 's|"cryptography>=44\.0\.1,<46"|"cryptography>=41.0.0,<46"|' \
	    -e 's|"argon2-cffi>=23\.1\.0"|"argon2-cffi>=21.3.0"|' \
	    pyproject.toml
	dh_auto_configure

override_dh_auto_test:
	PYTHONPATH=src python3 -m pytest tests --ignore=tests/performance --ignore=tests/fuzz -q -x

override_dh_auto_install:
	dh_auto_install
	install -D -m 0644 debian/stegx.1 debian/stegx/usr/share/man/man1/stegx.1
	if [ -f completions/stegx.bash ]; then \
	    install -D -m 0644 completions/stegx.bash debian/stegx/usr/share/bash-completion/completions/stegx ; \
	fi
	if [ -f completions/_stegx ]; then \
	    install -D -m 0644 completions/_stegx debian/stegx/usr/share/zsh/vendor-completions/_stegx ; \
	fi
	if [ -f completions/stegx.fish ]; then \
	    install -D -m 0644 completions/stegx.fish debian/stegx/usr/share/fish/vendor_completions.d/stegx.fish ; \
	fi

override_dh_auto_clean:
	# Restore the original pyproject.toml so source trees are not left modified.
	if [ -f pyproject.toml.deborig ]; then \
	    mv pyproject.toml.deborig pyproject.toml ; \
	fi
	dh_auto_clean
	rm -rf build dist src/stegx.egg-info src/*.egg-info
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
