#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
export DEB_VERSION_UPSTREAM

# needed as we have more than one binary package
export PYBUILD_DESTDIR=debian/ocrmypdf

# deal with unicode encoding/decoding errors throughout the package
# build, and especially the test suite.  This isn't needed in
# d/tests/test-suite because autopkgtest sets LANG=C.UTF-8 (see
# locale(7) for the difference between LC_ALL and LANG; using LC_ALL
# here makes the package build more robust because LC_ALL overrides
# all other locale variables, whereas LANG does not)
export LC_ALL=C.UTF-8

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

override_dh_installchangelogs:
	dh_installchangelogs docs/release_notes.rst

override_dh_auto_build:
# disabled pending updates to debhelper for 'nodoc' / compat 11
#ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	PYTHONPATH=debian/.debhelper sphinx-build docs html
#endif
	dh_auto_build -O--buildsystem=pybuild

# don't install installation instructions
override_dh_install:
	dh_install -Xinstallation
override_dh_sphinxdoc:
	dh_sphinxdoc -Xinstallation

# The test suite takes longer and longer to run, so we have disabled
# it at package build time and are relying on autopkgtest.  This also
# eases backporting ocrmypdf
override_dh_auto_test:

# # this override is needed because the pybuild build system does not
# # yet support running py.test tests with pytest-runner (pytest-runner
# # is necessary to run the test suite in advance of ocrmypdf being
# # installed)
# override_dh_auto_test:
# ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
# 	python3 setup.py test
# endif

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