#! /bin/sh
#
# Prepare a release of libpqxx.
#
# Usage: preprelease [sourcedir]
#
# where sourcedir is the main directory of the libpqxx source tree; defaults
# to .
# 
# The script builds libpqxx and runs a regression test from the tarball
# generated by 'make dist'.  This ensures that no important files are left out
# of the distribution archive, and that there are no regression failures in the
# released version.
#
# If successful, the script leaves a distribution tarball in /tmp.

LOGFILE=/tmp/libpqxx-preprelease.log

rm -f $LOGFILE
echo "Preparing libpqxx release.  Log file is $LOGFILE"
echo "preprelease libpqxx" >>$LOGFILE
date >>$LOGFILE
echo >>$LOGFILE

echo "Ensuring PostgreSQL is running..."
echo "$ startpostgres" >>$LOGFILE
startpostgres >>$LOGFILE
echo
if test -z "$PGHOST"; then export PGHOST=/tmp; fi
echo "Accessing PostgreSQL in $PGHOST"
echo "Accessing PostgreSQL in $PGHOST" >>$LOGFILE
echo
echo >>$LOGFILE

set -e
if test -n "$1"; then cd $1; fi

VERSION=`grep AC_INIT configure.ac | cut -d ' ' -f 2 | cut -d ',' -f 1`
echo "Preparing release of version $VERSION"
echo "Preparing release of version $VERSION" >>$LOGFILE
DISTNAME=libpqxx-$VERSION
TARBALL=$DISTNAME.tar.gz
echo
echo >>$LOGFILE

echo "Generating autoconf/automake files"
echo "Generating autoconf/automake files" >>$LOGFILE
./autogen.sh
echo
echo >>$LOGFILE

echo "Generating documentation"
echo "$ doxygen" >>$LOGFILE
doxygen >>$LOGFILE
echo
echo >>$LOGFILE

echo "Creating $TARBALL"
echo "$ make dist" >>$LOGFILE
make dist >>$LOGFILE
echo >>$LOGFILE

rm -f /tmp/$TARBALL
mv $TARBALL /tmp

cd /tmp
rm -rf $DISTNAME
echo "Extracting $TARBALL in /tmp"
tar xzf $TARBALL
rm $TARBALL
cd $DISTNAME

echo "Configuring"
echo "$ ./configure" >>$LOGFILE
nice ./configure >>$LOGFILE
echo >>$LOGFILE

echo "Building"
echo "$ nice make" >>$LOGFILE
nice make >>$LOGFILE
echo
echo >>$LOGFILE

echo "Running regression test"
echo "$ nice make check" >>$LOGFILE
nice make check >>$LOGFILE
echo
echo >>$LOGFILE

echo "Creating release version of $TARBALL"
echo "$ make dist" >>$LOGFILE
make dist >>$LOGFILE
mv $TARBALL ..
cd ..
rm -r $DISTNAME
echo "Finished."
echo "Finished." >>$LOGFILE
echo "Release tarball is /tmp/$TARBALL"

