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

PYTHONS:=$(shell pyversions -vr)
PYTHON3S:=$(shell py3versions -vr)

export HOME=$(CURDIR)/build/test

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

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. sphinx-build -b html doc/source debian/python-git-doc/usr/share/doc/python-git-doc/html
	dh_sphinxdoc
endif

override_dh_auto_install:
	set -e ; for pyvers in $(PYTHONS); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python-git ; \
	done
	set -e ; for pyvers in $(PYTHON3S); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/python3-git ; \
	done
	rm -f $(CURDIR)/debian/python*/usr/lib/python*/dist-packages/*.pth

#override_dh_auto_test:
#	: # run tests only if we can fetch original sources repository
#	-mkdir -p build/test; cd build/test; \
#         git config --global http.sslVerify false; git config --global user.name "TESTING"; git config --global user.email "TESTING@example.com"; \
#         git clone git://github.com/gitpython-developers/GitPython; \
#         cd GitPython; git submodule update --init --recursive; \
#          for i in `seq 4`; do git reset --hard HEAD~1; done; git reset --hard origin/master; touch ../go
#	[ ! -e build/test/go ] || \
#     LC_ALL=C.UTF-8 \
#     GIT_PYTHON_TEST_GIT_REPO_BASE=$(CURDIR)/build/test/GitPython \
#	 nosetests -s -v git/test

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build

DOC_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p' | sed 's/~.*//')
UPSTREAM=$(shell dpkg-parsechangelog | sed -nr 's/Version: (.*)-[^-]*/\1/p')
get-orig-source:
	uscan --download-current-version
	wget -P get-orig-source http://packages.python.org/GitPython/$(DOC_VERSION)/docs_$(DOC_VERSION).zip
	mkdir get-orig-source/doc
	unzip -d get-orig-source/doc get-orig-source/docs_$(DOC_VERSION).zip
	tar -C get-orig-source -czvf python-git_$(UPSTREAM).orig-doc.tar.gz doc/
	rm -rf get-orig-source

