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

PY2VERS := $(shell pyversions -s)
PY3VERS := $(shell py3versions -s)

%:
	dh $@ --with=python2,python3

override_dh_auto_build:
	set -e ; \
	for python in $(PY2VERS) $(PY3VERS); do \
		cd core ; $$python setup.py build ; cd .. ; \
	done

	$(MAKE) docs

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	-for python in $(PY2VERS) $(PY3VERS); do \
		# retrive the lib path \
		LIB=$$($$python -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print (b.build_purelib)") ; \
		$(MAKE) tests PYTHON=$$python PYTHONPATH=../core/$$LIB ; \
	done
endif

override_dh_auto_install:
	set -e ; \
	for python in $(PY2VERS); do \
		cd core ; $$python setup.py install --root=$(CURDIR)/debian/python-pygraph --install-layout=deb ; cd .. ; \
		cd dot  ; $$python setup.py install --root=$(CURDIR)/debian/python-pygraph --install-layout=deb ; cd .. ; \
	done
	set -e ; \
	for python in $(PY3VERS); do \
		cd core ; $$python setup.py install --root=$(CURDIR)/debian/python3-pygraph --install-layout=deb ; cd .. ; \
		cd dot  ; $$python setup.py install --root=$(CURDIR)/debian/python3-pygraph --install-layout=deb ; cd .. ; \
	done

	# clean up __pycache__ dirs, generated when running tests on the build dir
	find $(CURDIR)/debian/python3-pygraph -type d -name "__pycache__" | xargs rm -rf

override_dh_installdocs:
	dh_installdocs		docs

override_dh_installexamples:
	dh_installexamples	tests/*.py

override_dh_python2:
	dh_python2 --no-guessing-deps
