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

#export DH_VERBOSE=1

NUMJOBS = 1
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

build3vers := $(shell py3versions -sv)

# This has to be exported to make some magic below work.
export DH_OPTIONS

%:
	dh $@ --fail-missing --parallel --with autoreconf,python2,python3

override_dh_auto_configure:
	dh_auto_configure -- --disable-static --with-unicode-handler=ICU --enable-all-tools

override_dh_auto_build:
	$(MAKE) -j$(NUMJOBS) || $(MAKE) -j$(NUMJOBS) || $(MAKE)
	set -e && for i in $(build3vers); do \
		cd $(CURDIR)/python && python$$i setup.py build_ext && strip --strip-unneeded build/*/*.so; \
	done

override_dh_auto_test:
	make -j1 check

override_dh_auto_install:
	dh_auto_install
	set -e && for i in $(build3vers); do \
		cd $(CURDIR)/python && python$$i setup.py install --no-compile --prefix /usr --install-layout deb --root $(CURDIR)/debian/tmp; \
	done
	find $(CURDIR) -type f -name '*.pyc' -exec rm -f '{}' \;
	find $(CURDIR) -type f -name '*.pyo' -exec rm -f '{}' \;
	find $(CURDIR) -type f -name '*.la' -exec rm -f '{}' \;
