#!/usr/bin/make -f
export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export PYBUILD_NAME = mailman3
export PYBUILD_DESTDIR = debian/mailman3

MM3_BIN_DIR=/usr/lib/mailman3/bin/
export PYBUILD_INSTALL_ARGS ?= \
	--install-scripts=${MM3_BIN_DIR}/

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

override_dh_auto_test:
	# Running the test suite at build time is not supported for now.
	# See upstream bug #400 for further information.
	#PYTHONPATH="." python3 -m nose2 --verbose

override_dh_auto_build:
	PYTHONPATH=. sphinx-build -b html -c ./ -E -N . build/sphinx/html
	dh_auto_build

override_dh_auto_install:
	dh_auto_install
	find debian/mailman3/usr/lib/ -type d -name "docs" -exec rm -rf {} \; -prune;
	# PYBUILD_INSTALL_ARGS no longer works with the new PDM build system
	# so we will have to move the files ourselves
	install -d debian/mailman3/$(MM3_BIN_DIR)
	mv debian/mailman3/usr/bin/* debian/mailman3/$(MM3_BIN_DIR)

override_dh_installinit:
	dh_installinit --error-handler=init_service_failed

override_dh_installchangelogs:
	dh_installchangelogs src/mailman/docs/NEWS.rst

override_dh_fixperms:
	dh_fixperms
	chown list:list debian/mailman3/var/lib/mailman3 \
	                debian/mailman3/var/log/mailman3
