#!/usr/bin/make -f
# -*- makefile -*-

%:
	dh $@ $(DH_ADDONS)
build binary %-indep: DH_ADDONS=--with=python3

DOPACKAGES := $(shell dh_listpackages)
ifeq ($(filter python3-louis,$(DOPACKAGES)),)
PY3VERS :=
else
PY3VERS := $(shell py3versions -r)
endif

ASSUME_NEW = \
	--assume-new=lou_allround.1 \
	--assume-new=lou_checkhyphens.1 \
	--assume-new=lou_checktable.1 \
	--assume-new=lou_debug.1 \
	--assume-new=lou_translate.1 \
	--assume-new=lou_trace.1 \
	--assume-new=lou_checkyaml.1 \
	--assume-new=lou_tableinfo.1

override_dh_auto_configure-arch:
ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	dpkg-architecture -f -a$(DEB_BUILD_ARCH) -c dh_auto_configure --reload-all-buildenv-variables -- --enable-ucs4
	dpkg-architecture -f -a$(DEB_BUILD_ARCH) -c dh_auto_build
	dh_auto_clean
endif
	dh_auto_configure -- --enable-ucs4
override_dh_auto_configure-indep: override_dh_auto_configure-arch
	pybuild --configure

override_dh_auto_build-arch:
	dh_auto_build -- $(ASSUME_NEW)
override_dh_auto_build-indep: override_dh_auto_build-arch
	pybuild -d python --build

override_dh_auto_clean-arch:
	dh_auto_clean
	rm -fr doc/liblouis.info doc/stamp-vti doc/version.texi .pybuild
override_dh_auto_clean-indep: override_dh_auto_clean-arch
	-pybuild -d python --clean

override_dh_auto_test-arch:
	dh_auto_test
override_dh_auto_test-indep:
	cd python ; \
	  for py in $(PY3VERS); do \
	    LOUIS_TABLEPATH=$(CURDIR)/tables LD_LIBRARY_PATH=$(CURDIR)/liblouis/.libs$${LD_LIBRARY_PATH+:$$LD_LIBRARY_PATH} $$py -m pytest tests/ ; \
	  done

override_dh_auto_install-arch:
	dh_auto_install -- $(ASSUME_NEW)
	rm -fr $(CURDIR)/debian/tmp/usr/bin/lou_maketable*
override_dh_auto_install-indep: override_dh_auto_install-arch
	pybuild -d python --install
