#!/usr/bin/make -f

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

# Generate the upstream tarball from upstream Git (adapted from
# http://wiki.debian.org/SandroTosi/Svn_get-orig-source for Git)
PACKAGE := slapos.slap

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

GIT_VERSION := $(shell echo $(SRC_VERSION) | \
	sed -ne 's/.*git\([a-z0-9]\+\)/\1/p')

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

get-orig-source:
	rm -rf get-orig-source $(TARBALL)
	mkdir get-orig-source

	# Gitorious does not seem to support remote archive command,
	# thus clone and then archive the local copy
	git clone http://git.gitorious.org/slapos/slapos-libslap-python.git \
		get-orig-source/$(PACKAGE)-$(SRC_VERSION).orig

	cd get-orig-source/$(PACKAGE)-$(SRC_VERSION).orig && \
		git archive --prefix=$(PACKAGE)-$(SRC_VERSION).orig/ \
			--format=tar $(GIT_VERSION) | \
			gzip --no-name --best > ../../$(TARBALL)

	rm -rf get-orig-source
	@echo "'$(TARBALL)' created; move it to the right destination to build the package"

.PHONY: get-orig-source
