#!/bin/sh
# Usage: cvsdist module [tag] [version]
# Creates a tarball from the CVS archive, generating a 'configure'
# script and .spec file as necessary.
# HEAD is the default tag, and mmmyy is the default version string.
#
# Copyright (C) 1999 Joe Orton <joe@orton.demon.co.uk>
#
# $Id: cvsdist,v 1.3 1999/10/03 12:43:42 joe Exp $

# Usage, redistribution, modification under the terms of the GNU GPL,
# see COPYING for full details.

rel=${3-`date +%b%d | dd conv=lcase 2>/dev/null`}
mod=$1
tag=${2-HEAD}
mname=$mod-$rel
tname=/tmp/$mname
ball=/tmp/${mname}.tar.gz
if [ -d $tname ]; then
	echo $tname exists
	exit -1
fi
if [ -r $ball ]; then
	echo $ball exists
	exit -2
fi
echo Exporting $mod from CVS at $tag...
if ! cvs -Q export -d $tname -r $tag $mod; then
	echo export failed
	exit -3
fi
cd $tname
if [ -e configure.in ]; then
    echo Running `autoconf --version`...
    if ! autoconf; then
	echo autoconf failed
	exit -4
    fi
fi
if [ -e $mod.spec.in ]; then
    echo Creating .spec file for release $rel...
    if ! sed -e s/@VERSION@/$rel/ < $mod.spec.in > $mod.spec; then
	echo sed failed
	exit -5
    fi
fi    

### It would be nice to be able to generate the po files here too,
### but it's a bit complex, since normally you have to run configure
### to have po/Makefile exist

cd /tmp
echo Creating tarball...
tar czf $ball $mname
ls -l $ball
rm -r $mname
