#!/bin/bash

# Makes the dist file, updates everything
echo "Verifying this is a perl module..."
if [ ! -f 'Makefile.PL' ]
then
	echo "No Makefile.PL found... BAIL!"
	exit
fi

echo "Searching for old distribution..."
DIST=`ls | grep .tar.gz`
if [ ! -z "$DIST" ]
then
	echo "tar.gz files found!!"
	echo "  --> $DIST"
	echo "Delete them? (Y/n)"
	read DELETE

	if [ "$DELETE" != "n" ]
	then
		echo "Deleting..."
		rm -f $DIST
	fi
fi

echo "Clearing backup files..."
find . -iname '*~' -exec rm -v {} \;

echo "Creating INSTALL..."
cat > INSTALL << EOF
Use the standard procedure to install:

perl Makefile.PL
make
make test
make install

Steve Slaven <bpk@hoopajoo.net>
EOF

echo "Updating changes..."
if [ -f Changes ]
then
	rm Changes
fi
cvs2cl.pl -f Changes

echo "Updating manifest..."
rm MANIFEST
perl Makefile.PL
make realclean manifest
echo "Making tardist..."
perl Makefile.PL
make tardist realclean

for FILE in MANIFEST.bak Changes.bak
do
	if [ -f $FILE ]
	then
		echo "Deleting $FILE..."
		rm $FILE
	fi
done

# Tag the dist
echo "Would you like to tag this distribution? (y/N) "
read TAG
if [ "$TAG" = "y" ]
then
	echo "Searching for tag version..."
	VERS=`grep ^.VERSION *.pm | tail -n1 | sed s/\"/\'/g`
	VERSION_NUM=`perl -e "$VERS ; \\\$VERSION =~ s/[^A-Za-z0-9]/_/g ; print \\\$VERSION"`
	TAG=v_$VERSION_NUM

	echo "Tagging as $TAG"
	cvs tag $TAG
fi

