#! /usr/bin/make -f
#
# debian/rules
# Part of Debian ‘towncrier’ package.
#
# This is free software, and you are welcome to redistribute it under
# certain conditions; see the end of this file for copyright
# information, grant of license, and disclaimer of warranty.

PACKAGE_NAME = towncrier

MAIN_PYTHON_PACKAGE = towncrier

LIBRARY_PACKAGE_NAME = python3-${MAIN_PYTHON_PACKAGE}
DOC_PACKAGE_NAME = ${PACKAGE_NAME}-doc
DOC_DIR = docs

# Send HTTP traffic to the “discard” service during packaging actions.
export http_proxy = http://127.0.1.1:9/
export https_proxy = ${http_proxy}

export PYBUILD_SYSTEM := pyproject
export PYBUILD_NAME = ${MAIN_PYTHON_PACKAGE}

pybuild_computed_home_dir = $(shell \
	pybuild --print home_dir \
		| cut -d ':' -f 2 \
		| sed -e 's/^[[:space:]]*//' \
	)
pybuild_computed_build_dir = $(shell \
	pybuild --print build_dir \
		| cut -d ':' -f 2 \
		| sed -e 's/^[[:space:]]*//' \
	)

export PYBUILD_INSTALL_ARGS ?= \
	--install-option="--install-layout=deb"

export PYBUILD_TEST_ARGS = "{dir}"/src/

# Twisted Trial creates temporary Python modules and doesn't clean up.
twisted_trial_cruft = ${MAIN_PYTHON_PACKAGE}.test.*
export PYBUILD_AFTER_TEST = $(RM) -r "{build_dir}"/${twisted_trial_cruft}

# The library package should not install binaries to the default location.
private_bin_dir = $(CURDIR)/usr/share/towncrier/bin
export PYBUILD_AFTER_BUILD = \
	mv "{home_dir}/scripts"/* "${private_bin_dir}"/.

export MAKE ?= make
export RM ?= rm -f
export MKDIR ?= mkdir --parents

export PYTHON ?= python3
export SPHINXBUILD ?= $(PYTHON) -m sphinx
SPHINX_MAKE_OPTS ?= SPHINXBUILD="$(SPHINXBUILD)" --directory "${DOC_DIR}"

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


override_dh_auto_clean:
	dh_auto_clean
	$(MAKE) ${SPHINX_MAKE_OPTS} clean


override_dh_auto_build: ${private_bin_dir}
	dh_link -p "${LIBRARY_PACKAGE_NAME}" \
		usr/share/doc/"${LIBRARY_PACKAGE_NAME}" \
		usr/share/doc/"${PACKAGE_NAME}"
	dh_link -p "${DOC_PACKAGE_NAME}" \
		usr/share/doc/"${DOC_PACKAGE_NAME}" \
		usr/share/doc/"${PACKAGE_NAME}"
	dh_auto_build
	$(MAKE) \
		PYTHONPATH="${pybuild_computed_build_dir}" \
		${SPHINX_MAKE_OPTS} \
		html man

${private_bin_dir}:
	$(MKDIR) "$@"


override_dh_installchangelogs:
	dh_installchangelogs NEWS.rst


override_dh_installdocs:
	dh_installdocs \
		-p "${DOC_PACKAGE_NAME}" \
		--doc-main-package="${PACKAGE_NAME}"
	dh_installdocs


# Copyright © 2010–2026 Ben Finney <bignose@debian.org>
#
# This is free software: you may copy, modify, and/or distribute this work
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 3 of that license or any later version.
# No warranty expressed or implied.


# Local variables:
# coding: utf-8
# mode: gnumakefile
# End:
# vim: fileencoding=utf-8 filetype=make :
