#!/bin/sh -e

echo "For snapshot releases use the code below.  Real releases work with uscan."
uscan --verbose

exit 0
URL="http://gel.ahabs.wisc.edu/mauve/source/snapshots/"
NAME=libgenome
UVERSION=snapshot
DVERSION=1.3.0
UPSTREAMTAR="$NAME"-"$UVERSION".tar.gz
UPSTREAMDIR=libGenome

# To rebuild the new upstream tarball you need these
# packages installed.  This will be checked later on.
# The rationale behind this dependency is that the
# script should work for later upstream releases as well
# and thus a simple patch for Makefile.am and
# configure.in would not work
BUILDTARBALLDEPENDS="autoconf automake libtool"
# Also these build-dependencies are needed to be installed to
# run ./configure which is a precondition for "make dist"
BUILDDEPS=""
missingdepends=`dpkg -l ${BUILDTARBALLDEPENDS} ${BUILDDEPS} | \
    grep -v -e "^ii" -e "^|" -e "^++" -e "^ " -e "^..[^[:space:]]" | \
    sed 's/^[a-z][a-z][[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+.*/\1/'`

if [ "$missingdepends" != "" ] ; then
    echo "Please install the following packages to rebuild the upstream source tarball:"
    echo $missingdepends
    exit -1
fi

mkdir -p ../tarballs
cd ../tarballs

if [ ! -f "$UPSTREAMTAR" ] ; then
    wget "$URL"/"$UPSTREAMTAR"
fi
tar -xzf "$UPSTREAMTAR"

cd "$UPSTREAMDIR"

autogen.sh
./configure
make dist

DISTTAR="$UPSTREAMDIR"-"${DVERSION}".tar.gz
DVERSION="${DVERSION}."`date +%Y%m%d`
mv "$DISTTAR" ../"$NAME"_"$DVERSION".orig.tar.gz
cd ..
rm -rf "$UPSTREAMDIR"
