#!/usr/bin/make -f

# Manpages use SOURCE_DATE_EPOCH to determine what date to write.
# Generally, this is sane. However, for binNMUs the source date is set
# to buildd's build start time. In effect, as rebuilds can span
# multiple days, the resulting manpages differ in file contents.
# This causes a file conflict for M-A:same.
#
# To ensure manpages match across binNMUs, we must set a custom
# revision date on AsciiDoc documents. We copy ${source:Version} logic
# of stripping the `+bN` suffix for this.
MANPAGE_VERSION := $(shell dpkg-parsechangelog -SVersion | sed -E 's/\+b[0-9]+$$//')
MANPAGE_TIMESTAMP := $(shell dpkg-parsechangelog -STimestamp --to $(MANPAGE_VERSION))
MANPAGE_DATE := $(shell date -u -d @$(MANPAGE_TIMESTAMP) +%Y-%m-%d)

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export PYBUILD_SYSTEM=custom
export PYBUILD_CLEAN_ARGS=dh_auto_clean
export PYBUILD_CONFIGURE_ARGS=intltoolize --force --automake; \
	PYTHON={interpreter} dh_auto_configure -- \
	ASCIIDOC="asciidoc -a revdate=$(MANPAGE_DATE)" \
	--disable-perl
export PYBUILD_BUILD_ARGS=dh_auto_build
export PYBUILD_INSTALL_ARGS=dh_auto_install --destdir={destdir}; \
	mkdir -p {destdir}/usr/lib/python{version}/dist-packages; \
	mv {destdir}/usr/lib/python3/dist-packages/_location.so {destdir}/usr/lib/python{version}/dist-packages/_location.so; \
	rm -f {destdir}/usr/lib/python3/dist-packages/_location.la {destdir}/usr/lib/*/libloc.la
export PYBUILD_TEST_ARGS=dh_auto_test

%:
	dh $@ --buildsystem=pybuild
