#!/usr/bin/make -f

LIB2 := $(shell python  -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_purelib)")
LIB3 := $(shell python3 -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_purelib)")

%:
	dh $@ --with python2,python3

override_dh_auto_build:
	python  setup.py build
	python3 setup.py build

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	# tests/ dir is not copied, so we do that, else we cant run the tests in the build dir
	cp -r $(CURDIR)/tqdm/tests/ $(CURDIR)/$(LIB2)/tqdm/
	# run perf tests in a separate, non-failing, line
	nosetests -Itests_perf.py $(LIB2)/tqdm/
	-nosetests $(LIB2)/tqdm/tests/tests_perf.py
	rm -rf $(CURDIR)/$(LIB2)/tqdm/tests/

	cp -r $(CURDIR)/tqdm/tests/ $(CURDIR)/$(LIB3)/tqdm/
	# run perf tests in a separate, non-failing, line
	nosetests3 -Itests_perf.py $(LIB3)/tqdm/
	-nosetests3 $(LIB3)/tqdm/tests/tests_perf.py
	rm -rf $(CURDIR)/$(LIB3)/tqdm/tests/
endif

override_dh_auto_install:
	python  setup.py install --root=debian/python-tqdm  --install-layout=deb
	# cli tools are provided only by the py3k package
	rm -rf $(CURDIR)/debian/python-tqdm/usr/bin
	python3 setup.py install --root=debian/python3-tqdm --install-layout=deb

override_dh_installdocs:
	dh_installdocs -A CONTRIBUTING.md README.rst

override_dh_installexamples:
	dh_installexamples -A examples/*.py
