#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@ --with python2

override_dh_clean:
	dh_clean
	$(RM) -r build
	find scripts -mindepth 1 -regex '[^.]*' -delete -printf 'removing %p\n'

override_dh_auto_install:
	dh_auto_install -- --skip-profile
	# generate man pages
	python setup.py build_man

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e ;\
	for python in $(shell pyversions -r); do \
	    $$python check.py ;\
	done
endif

override_dh_builddeb:
	dh_builddeb -- -Zxz

PKD  = $(abspath $(dir $(MAKEFILE_LIST)))
PKG  = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))
VER ?= $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{Version:\s*([\d\.+git]+)}')
## get-orig-source
#VER := $(shell dpkg-parsechangelog | perl -ne 'print $$1 if m/Version:\s*([\d\.]+)/')
get-orig-source: $(PKG)-$(VER)
	@echo "Cleaning and Packing..."
	$(RM) -r $(PKG)-$(VER)/.bzr*
	tar -caf "$(PKG)_$(VER).orig.tar.xz" "$(PKG)-$(VER)" \
	&& $(RM) -r "$(PKG)-$(VER)"

$(PKG)-$(VER):
	bzr checkout --hardlink --lightweight --revision=tag:release-$(VER) \
        https://code.launchpad.net/~mysql/mysql-utilities/trunk $(PKG)-$(VER) \
	|| $(RM) -r $(PKG)-$(VER)
