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

VER_MAJOR=5
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"-src.tgz"
#
echo "download from GitHub? (y/N)"
read key
if [ "x"$key = "xy" ]; then
	git clone https://github.com/atari800/atari800.git
	rm -rf atari800/.git atari800/.gitignore
	rm -rf atari800/.travis atari800/.travis.yml
fi
#
grep "[Vv]ersion "$VERSION atari800/README.TXT >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in README.TXT"
	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/configure.ac | grep $VERSION >/dev/null
if [ $? -ne 0 ]; then
	echo "ERROR: increase version in configure.ac"
	exit 1
fi
#
cd atari800
./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
