#!/usr/bin/make -f
#export DH_VERBOSE=1

export PYBUILD_NAME=yt
export http_proxy=127.0.0.1:9
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export HOME=$(CURDIR)/debian/home

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

override_dh_clean:
	dh_clean
	rm -rf .eggs/

override_dh_auto_install:
	dh_auto_install
	rm $(CURDIR)/debian/python-yt/usr/lib/python*/dist-packages/yt/extern/tqdm/LICENSE
	rm $(CURDIR)/debian/python3-yt/usr/lib/python*/dist-packages/yt/extern/tqdm/LICENSE
	rm $(CURDIR)/debian/python-yt/usr/lib/python*/dist-packages/yt/frontends/artio/artio_headers/LICENSE
	rm $(CURDIR)/debian/python3-yt/usr/lib/python*/dist-packages/yt/frontends/artio/artio_headers/LICENSE
	mv $(CURDIR)/debian/python-yt/usr/bin/yt $(CURDIR)/debian/python-yt/usr/bin/yt2
	mv $(CURDIR)/debian/python-yt/usr/bin/iyt $(CURDIR)/debian/python-yt/usr/bin/iyt2
	mkdir -p $(CURDIR)/debian/python-yt/usr/share/doc/python-yt/
	mkdir -p $(CURDIR)/debian/python3-yt/usr/share/doc/python3-yt/
	gzip -9 -c doc/source/reference/changelog.rst > $(CURDIR)/debian/python-yt/usr/share/doc/python-yt/changelog.gz
	gzip -9 -c doc/source/reference/changelog.rst > $(CURDIR)/debian/python3-yt/usr/share/doc/python3-yt/changelog.gz

override_dh_installman:
	cp doc/yt.1 doc/yt2.1
	cp doc/iyt.1 doc/iyt2.1
	cp doc/yt_lodgeit.1 doc/yt_lodgeit2.1
	dh_installman

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	mkdir -p $(HOME)
	python setup.py build_ext -i && nosetests
endif
