#!/bin/sh
VERSION_AUTOTOOLS=$(grep ^AC_INIT configure.ac | sed -r 's/[^[]+\[([^]]+)\].+/\1/')
VERSION_DEB=`head -n 1 debian/changelog  | sed -re 's/.+\(([^-]+).+/\1/'`
VERSION="$VERSION_AUTOTOOLS"

if [ "$VERSION_AUTOTOOLS" != "$VERSION_DEB" ]
then
	echo "Version mismatch between autotools ($VERSION_AUTOTOOLS) and debian/changelog ($VERSION_DEB)" >&2
	exit 1
fi

if [ z"$1" = z"need-orig" ]
then
	DEST=../tagcoll2_$VERSION.orig.tar.gz
	if ! [ -f $DEST ]
	then
		test -f Makefile || ./configure
		make dist
		mv tagcoll2-$VERSION.tar.gz $DEST
	fi
else
	echo "$VERSION"
fi

exit 0
