#!/bin/sh

# Build an e2fsprogs RPM from cvs

pwd=`pwd`
currdir=`basename $pwd`
pkgname=`grep Name: e2fsprogs.spec | awk '{print $2;}'`
pkgvers=`grep Version: e2fsprogs.spec | awk '{print $2;}'`
builddir=${pkgname}-${pkgvers}

cd ..
tmpdir=`mktemp -d rpmtmp.XXXXXX`

# We need to build a tarball for the SRPM using $builddir as the 
# directory name (since that's what RPM will expect it to unpack
# into).  That may require a symlink.

# Make a recursive-symlink copy of the source dir
cp -sR `pwd`/$currdir $tmpdir/$builddir || exit 1

# Remove any build files from the temporary tarball directory
[ -f $tmpdir/$builddir/Makefile ] && make -C $tmpdir/$builddir distclean

EXCLUDE="--exclude .hg* --exclude .pc*"
(cd $tmpdir && tar czfh ${builddir}.tar.gz $EXCLUDE $builddir)

[ "`rpmbuild --version 2> /dev/null`" ] && RPM=rpmbuild || RPM=rpm
$RPM --define "_sourcedir `pwd`/$tmpdir" -ba $currdir/e2fsprogs.spec

ret=$?
rm -rf $tmpdir
exit $?