#!/usr/bin/make -f

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

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

override_dh_auto_clean:
	dh_auto_clean

	rm -rf $(CURDIR)/cycler.egg-info/

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

	LIB=$$(python -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_purelib)")
	PYTHONPATH=$(CURDIR)/$$LIB $(MAKE) -C doc html

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	# run tests
	for python in $(PY2VERS) $(PY3VERS); do \
		echo "running tests on "$$python ; \
	        LIB=$$($$python -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_purelib)") ; \
	        PYTHONPATH=$(CURDIR)/$$LIB $$python /usr/bin/nosetests . ; \
	done
endif

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

override_dh_installdocs:
	dh_installdocs
	ln -s /usr/share/javascript/mathjax/MathJax.js $(CURDIR)/doc/build/html/_static/MathJax.js
	find doc/build/html -name "*.html" -exec sed -i "s|https://cdn.mathjax.org/mathjax/latest/MathJax.js|_static/MathJax.js|" {} \;
	dh_installdocs -ppython-cycler-doc doc/build/html
