#!/usr/bin/make -f

%:
	dh $@ --with python2 --buildsystem=python_distutils

# Run tests on build time, but only if ``nocheck'' build option has
# not been set
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	for py in $(shell pyversions -vr); do \
	  python$$py setup.py test; \
	done
endif

# Generate the upstream tarball from upstream SVN (adapted from
# http://wiki.debian.org/SandroTosi/Svn_get-orig-source)
PACKAGE := xmlmarshaller

SRC_VERSION := $(shell dpkg-parsechangelog | \
	sed -ne 's/^Version: \(\([0-9]\+\):\)\?\(.*\)-.*/\3/p')

SVN_REVISION := $(shell echo $(SRC_VERSION) | awk -F"+" '{ print $$2 }' | \
	sed 's/svn//' )

TARBALL = $(PACKAGE)_$(SRC_VERSION).orig.tar.gz

get-orig-source:
	rm -rf get-orig-source $(TARBALL)
	mkdir get-orig-source
	svn export --non-interactive --trust-server-cert -r $(SVN_REVISION) \
		https://svn.erp5.org/repos/public/erp5/trunk/utils/xml_marshaller \
	  	get-orig-source/$(PACKAGE)-$(SRC_VERSION).orig
	GZIP='--best --no-name' tar czf $(TARBALL) -C get-orig-source \
		$(PACKAGE)-$(SRC_VERSION).orig
	rm -rf get-orig-source
	@echo "'$(TARBALL)' created; move it to the right destination to build the package"

.PHONY: get-orig-source
