#!/usr/bin/make -f

DEB_SOURCE := $(shell dpkg-parsechangelog | grep Source: | sed -e 's/Source: //')
DEB_VERSION := $(shell dpkg-parsechangelog | grep Version: | sed -e 's/Version: //')
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_VERSION) | sed -e 's/-[^-]*$$//')

include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/debhelper.mk

DEB_DESTDIR = $(CURDIR)/debian/tmp/
GIT_URL = git://git.moblin.org/gconnman

get-orig-source::
	set -e; if echo $(DEB_VERSION) | grep -c "git"; \
	then \
		git_version=`echo $(DEB_VERSION) | sed -e 's/^.*git\.*\([0-9]*\.\)*\(.*\)-.*$$/\2/g'`; \
	else \
		git_version=$(DEB_UPSTREAM_VERSION); \
	fi; \
	tmpdir=`mktemp -d -t`; \
	cd $$tmpdir; \
		echo "cloning upstream repository ..."; \
		git clone $(GIT_URL); echo "getting specific upstream revision/tag: $$git_version"; \
		cd `ls | head -n 1`; git checkout -b orig $$git_version; \
		echo "autotools bootstrapping ..."; \
		sh ./autogen.sh; \
		echo "cleaning up autotools caches (autom4te.cache) ..."; \
		rm -rf autom4te.cache; \
		cd ..; tar --exclude=.git -cvzf $(CURDIR)/$(DEB_SOURCE)_$(DEB_UPSTREAM_VERSION).orig.tar.gz `ls | head -n 1`; \
		cd $(CURDIR); rm -rf $$tmpdir

