#!/bin/sh
#
# "$Id: makesrcdist 9852 2011-07-06 20:14:24Z mike $"
#
# makesrcdist - make a source distribution of CUPS.
#

# Make sure we are running in the right directory...
if test ! -f tools/makesrcdist; then
        echo "Run this script from the top-level CUPS source directory, e.g.:"
        echo ""
        echo "    tools/makesrcdist $*"
        echo ""
        exit 1
fi

if test $# = 0; then
	echo Updating for snapshot...
	svn up
	rev=`svnversion . | sed -e '1,$s/[a-zA-Z]//g'`
	version="1.5svn"
	revision="-r$rev"
	fileversion="1.5svn-r$rev"
	fileurl="http://ftp.easysw.com/pub/cups/test/cups-$fileversion-source.tar."
	url="."
else
	echo Creating tag for release...
	rev="1"
	version=$1
	revision=""
	fileversion=$1
	fileurl="http://ftp.easysw.com/pub/cups/$version/cups-$fileversion-source.tar."
	url="https://svn.easysw.com/public/cups/tags/release-$version"

	svn copy https://svn.easysw.com/public/cups/trunk "$url" \
		-m "Tag $version" || exit 1
fi

fileurl=`echo $fileurl | sed -e '1,$s/\\//\\\\\\//g'`

echo Exporting $fileversion...
rm -rf /tmp/cups-$version
svn export $url /tmp/cups-$version

echo Updating version information...
cd /tmp/cups-$version/config-scripts

sed -e '1,$s/^CUPS_VERSION=.*/CUPS_VERSION='$version'/' \
	-e '1,$s/^CUPS_REVISION=.*/CUPS_REVISION='$revision'/' \
	<cups-common.m4 >cups-common.m4.new
mv cups-common.m4.new cups-common.m4
cd ..

echo Configuring...
autoconf -f
rm -rf autom4te*.cache
rm -rf tools
cd ..

echo -n Archiving...gz
sed -e '1,$s/@CUPS_VERSION@/'$version'/' \
	-e '1,$s/^Release:.*/Release: '$rev'/' \
	-e '1,$s/^Source:.*/Source: '$fileurl'gz/' \
	<cups-$version/packaging/cups.spec.in \
	>cups-$version/packaging/cups.spec
tar czf cups-$fileversion-source.tar.gz cups-$version

echo -n ...bz2
sed -e '1,$s/@CUPS_VERSION@/'$version'/' \
	-e '1,$s/^Release:.*/Release: '$rev'/' \
	-e '1,$s/^Source:.*/Source: '$fileurl'bz2/' \
	<cups-$version/packaging/cups.spec.in \
	>cups-$version/packaging/cups.spec
tar cjf cups-$fileversion-source.tar.bz2 cups-$version
echo "..."

if test -x /usr/bin/md5sum; then
	(cd /tmp; md5sum cups-$fileversion-source.tar.* | awk '{print $1, "'$fileversion' cups/'$fileversion'/" $2}')
elif test -x /sbin/md5; then
	(cd /tmp; md5 cups-$fileversion-source.tar.* | awk '{print $4, "'$fileversion' cups/'$fileversion'/" substr($2, 2, length($2) - 2)}')
fi

echo Removing temporary files...
rm -rf cups-$version

echo "Done!"

#
# End of "$Id: makesrcdist 9852 2011-07-06 20:14:24Z mike $".
#
