#!/bin/sh

if [ $# -ne 0 ]; then
	echo "Simple packaging file for the source."
	echo ""
	echo "Use in the root directory of the game, like so:"
	echo "   scripts/pkg_src"
	echo "The script will output a tarball angband-[git describe].tar.gz"

	exit 1
fi
  
TAG=angband-`git describe`
OUT=$TAG.tar.gz

# Error checking
if [ -e $OUT ]; then
	cat <<EOF
The output file $OUT already exists. 
Please rename or delete it before running the script again.
EOF
	exit 1
fi

if [ -e $TAG ]; then
	cat <<EOF
The output directory $TAG already exists. 
Please rename or delete it before running the script again.
EOF
	exit 1
fi

git checkout-index --prefix=$TAG/ -a &&
	git describe > $TAG/version &&
	cd $TAG &&
	./autogen.sh &&
	rm -rf autogen.sh autom4te.cache &&
	cd .. &&
	tar --exclude .gitignore --exclude *.dll -czvf $OUT $TAG &&
	rm -rf $TAG
