#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

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

# Prevent pip from using the cache directory, which can cause issues in some
# CI environments and is not needed for building the package.
export PIP_NO_CACHE_DIR=1
export XDG_CACHE_HOME=$(CURDIR)/.cache

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

override_dh_installman:
	help2man --no-info --name="a GUI to produce PDFs or DjVus from scanned documents" --version-string=$(DEB_VERSION_UPSTREAM) --output=$(CURDIR)/debian/scantpaper.1 "python3 scantpaper/app.py"
	sed -i -e 's/APP.PY/SCANTPAPER/' -e 's/app.py/scantpaper/' $(CURDIR)/debian/scantpaper.1
	dh_installman

override_dh_auto_install:
	python3 -m pip install --no-deps --no-build-isolation --root=$(CURDIR)/debian/scantpaper --prefix=/usr .
	# dh_auto_install will still place any additional files; ensure dh runs
	dh_auto_install --destdir=$(CURDIR)/debian/scantpaper || true
	rm -rf $(CURDIR)/debian/scantpaper/usr/local || true # FIXME: there has to be a better way to prevent pip from installing to /usr/local
	# install locale files
	# can't directly install to /usr/share/locale since pybuild seems to delete them
	python3 $(CURDIR)/dev/compile_mo.py --src $(CURDIR)/po --out $(CURDIR)/locale --domain scantpaper || true
	mkdir -p $(CURDIR)/debian/scantpaper/usr/share
	cp -a $(CURDIR)/locale $(CURDIR)/debian/scantpaper/usr/share/

# https://people.debian.org/~eriberto/README.package-tests.html
override_dh_auto_test: ;
