#!/usr/bin/make -f

# instruct pybuild to run upstream's test suite using py.test
export PYBUILD_TEST_PYTEST=1

# determine upstream version to be used in other env vars
export DEB_UPSTREAM_VERSION = \
	$(shell dpkg-parsechangelog -SVersion | cut -d- -f1)

# setuptools-scm's heuristics fail to determine the package version
# which causes the build to fail, so just override it
export SETUPTOOLS_SCM_PRETEND_VERSION = ${DEB_UPSTREAM_VERSION}

# upstream's test suite is designed to run when OCRmyPDF is already
# installed, so we need to
# (1) provide the test suite with the OCRmyPDF.sh script; and
# (2) hardcode the current version as otherwise the ocrmypdf tries
#     to determine the installed version which can fail or can be
#     different from the version we want to test
export PYBUILD_BEFORE_TEST= \
	cp {dir}/OCRmyPDF.sh {build_dir} ; \
	sed -i -e "s/^VERSION = .*$$/VERSION = \"${DEB_UPSTREAM_VERSION}\"/" \
		{build_dir}/ocrmypdf/main.py
# ... and then remove OCRmyPDF.sh so it doesn't get installed in /usr
export PYBUILD_AFTER_TEST = rm {build_dir}/OCRmyPDF.sh

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

override_dh_installchangelogs:
	dh_installchangelogs RELEASE_NOTES.rst

# requires ocrmypdf already installed!
.PHONY: gen-man-page
gen-man-page:
	help2man ocrmypdf --no-info \
		-n "add an OCR text layer to PDF files" \
		> debian/ocrmypdf.1
