#!/usr/bin/make -f

%:
	dh $@ --with python2

override_dh_auto_build:
	dh_auto_build
	$(MAKE) -C doc

override_dh_auto_clean:
	dh_auto_clean
	$(MAKE) -C doc clean || rm -rf doc

GIT_REPO ?= https://github.com/termie/git-bzr-ng
RDATE=$(shell dpkg-parsechangelog | sed -rne 's,^Version: .*\+git([0-9]+).*,\1,p')
FDATE=$(shell echo $(RDATE) | sed -r 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/')
VER=$(shell dpkg-parsechangelog | sed -rne 's,^Version: (.+)-.*,\1,p')

get-packaged-orig-source:
	@echo "You can build this from a local repo by supplying the GIT_REPO variable"
	rm -rf git-bzr-ng-$(VER).orig
	git clone $(GIT_REPO) git-bzr-ng-$(VER).orig
ifeq (,$(RDATE))
	cd git-bzr-ng-$(VER).orig && git checkout $(VER)
else
	set -e; \
	cd git-bzr-ng-$(VER).orig; \
	git checkout $$(git rev-list --date-order --until=$(FDATE) master | head -n1)
endif
	rm -rf git-bzr-ng-$(VER).orig/.git*
	GZIP=--best tar -cz --owner root --group root --mode a+rX \
	-f git-bzr-ng_$(VER).orig.tar.gz git-bzr-ng-$(VER).orig
	rm -rf git-bzr-ng-$(VER).orig
