#!/usr/bin/make -f

#export DH_VERBOSE=1

# The command 'sphinx-build' refers to the python2 version;
# currently there is no easier way to refer to the python3 version.
SPHINXBUILD=/usr/share/sphinx/scripts/python3/sphinx-build

# Use buildflags for the Cython sources
# FIXME: Using hardeninge=+pie breaks the build.
export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow,+fortify

DPKG_EXPORT_BUILDFLAGS=1
include /usr/share/dpkg/buildflags.mk

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

# Set enviroment variables suitable for calling the upstream docs generator.
# upstream simply calls "borg", therefore we add the just-created usr/bin
# to PATH.
# the "borg" command will fail if it can't find its dist-package, therefore
# set PYTHONPATH.
# Calling "borg" will attempt to open files in BORG_KEYS_DIR and
# also in BORG_CACHE_DIR. These are by default in ~/.borg, but
# on a build daemon, $HOME might even be unset.
# We use temporary directories.
override_dh_auto_build-indep:
	$(MAKE) -C docs html SPHINXBUILD=$(SPHINXBUILD) \
		PATH=../debian/borgbackup/usr/bin/:$(PATH) \
		PYTHONPATH=../$(wildcard debian/borgbackup/usr/lib/python3.*/dist-packages/) \
		BORG_KEYS_DIR=$(shell mktemp -d) \
		BORG_CACHE_DIR=$(shell mktemp -d)

# Do not compress .ico file (affects html documentation)
override_dh_compress:
	dh_compress -X.ico
