#!/usr/bin/make -f

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

PACKAGE := mysql-utilities
PY2VERS := $(shell pyversions -r)

%:
	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 $(PY2VERS); do \
	    $$python check.py ;\
	done
endif

## get-orig-source
## Depends: bzr (>= 2.6.0~bzr6520-1) # due to #666496
VER := $(shell dpkg-parsechangelog | perl -ne 'print $$1 if m/Version:\s*([\d\.]+)/')
get-orig-source: $(PACKAGE)-$(VER)
	@echo "Cleaning and Packing..."
	$(RM) -r $(PACKAGE)-$(VER)/.bzr*
	tar cJf "$(PACKAGE)_$(VER).orig.tar.xz" "$(PACKAGE)-$(VER)" \
	&& $(RM) -r "$(PACKAGE)-$(VER)"

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