#!/usr/bin/make -f

DOCS = $(patsubst %.rst,%.html, $(wildcard doc/*.rst))
PYTHON2_VERSIONS := $(shell pyversions -sv)
PYTHON3_VERSIONS := $(shell py3versions -sv)

%:
	dh $@ --with python3,python2

clean:
	rm -f doc/*.html

doc/%.html: doc/%.rst
	rst2html $< > $@

override_dh_auto_build: $(DOCS)
	dh_auto_build -- V=1
	cd bindings/python \
	set -e && for i in $(PYTHON2_VERSIONS); do \
	  python$$i ./setup.py build; \
	done
	cd bindings/python \
	set -e && for i in $(PYTHON3_VERSIONS); do \
	  python$$i ./setup.py build; \
	done

override_dh_auto_test:
	dh_auto_test -- V=1 LC_ALL=C

override_dh_auto_install:
	make install PREFIX=$(CURDIR)/debian/tmp/usr DESTDIR=/usr PLIBPATH=/usr/lib/fiu
	cd bindings/python \
	set -e && for i in $(PYTHON2_VERSIONS); do \
	  python$$i ./setup.py install --root=$(CURDIR)/debian/python-fiu --no-compile -O0 --install-layout=deb; \
	done
	cd bindings/python \
	set -e && for i in $(PYTHON3_VERSIONS); do \
	  python$$i ./setup.py install --root=$(CURDIR)/debian/python3-fiu --no-compile -O0 --install-layout=deb; \
	done

override_dh_compress:
	dh_compress -X.rst
