#!/usr/bin/make -f
DH_VERBOSE = 1
# upstream version part in debian/changelog is generate with:
# $ git describe --tags COMMIT_FOR_RELEASE | sed -e 's,^v,,' -e 's,-,+,g'
# where COMMIT_FOR_RELEASE is the commit put in prinstine-tar branch
# we need to maintain up-to-date pristine-tar branch
orig_version=$(shell dpkg-parsechangelog | grep ^Version | cut -d' ' -f2 | cut -d- -f1)
pkgname=$(shell dpkg-parsechangelog | grep ^Source | cut -d' ' -f2)
# If we are w/o .git dir try to wget orig source.
# this is to maintain up-to-date, this is not a good solution
upstream_commit_release="d58c489797405db348b30dec6103dcfff73160ec"
upstream_base_url="https://github.com/jsocol/django-ratelimit/archive"

%:
	dh $@ --with python2,sphinxdoc

override_dh_auto_build:
	dh_testdir
	$(MAKE) -C docs html
	dh_auto_build

override_dh_clean:
	$(MAKE) -C docs clean
	rm -rf docs/_build *.egg-info
	dh_clean

get-orig-source:
	dh_testdir
	if test -d .git ; then \
	 pristine-tar checkout ../$(pkgname)_$(orig_version).orig.tar.gz ; \
	else \
	 wget -O ../$(pkgname)_$(orig_version).orig.tar.gz \
	 "$(upstream_base_url)/$(upstream_commit_release).tar.gz" ; \
	fi
