#!/bin/sh
# This scripts helps with building the source .tar.gz file

VER_MAJOR=3
VER_MINOR=0
VER_MICRO=0
#
VERSION=$VER_MAJOR"."$VER_MINOR"."$VER_MICRO
TAG="ATARI800_"$VER_MAJOR"_"$VER_MINOR"_"$VER_MICRO
#upper case the tag
TAG=`echo $TAG | tr [:lower:] [:upper:]`
FOLDER="atari800-"$VERSION
FNAME=$FOLDER".tar.gz"
#
echo "download from CVS? (y/N)"
read key
if [ "x"$key = "xy" ]; then
	cvs -z9 -d:ext:joy@atari800.cvs.sourceforge.net:/cvsroot/atari800 export -r $TAG atari800
fi
#
grep Atari800_TITLE atari800/src/atari.h | grep $VERSION >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in src/atari.h"
	exit 1
fi
grep "[Vv]ersion "$VERSION atari800/README.1ST >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in README.1ST"
	exit 1
fi
grep "[Vv]ersion "$VERSION atari800/DOC/README >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in DOC/README"
	exit 1
fi
grep "Atari800 "$VERSION atari800/src/atari800.man >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in src/atari800.man"
	exit 1
fi
grep "%define ver" atari800/atari800.spec | grep $VERSION >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in atari800.spec"
	exit 1
fi
grep "AC_INIT(Atari800, "$VERSION atari800/src/configure.ac | grep $VERSION >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in src/configure.ac"
	exit 1
fi
#
cd atari800/src
./autogen.sh
# remove leftovers from autogen process
rm -f autogen.sh config.cache config.log
rm -rf autom4te.cache
cd ../..
mv atari800 $FOLDER
GZIP=--best tar chozvf $FNAME $FOLDER
