#!/bin/sh

#set -x

# determine absolute path to source dir root
srctree="$(cd $(dirname "$0") && cd .. && pwd)"

# change to scripts dir (or wherever this script resides)
cd "$(dirname "$0")"
if [ ! -f ./make-release ]; then
    echo "need to be in scripts dir"; exit 1;
fi

. ../vsn.mk

echo packing release ${YAWS_VSN} 

TAG="yaws-${YAWS_VSN}"
NAME_VERSION="yaws-${YAWS_VSN}"


(cd ../win32; make clean all)
cd ../..


export GIT_DIR="$srctree/.git"
if test -d "$GIT_DIR" && test -f "$GIT_DIR/config"; then :;
else
	echo "Fatal: Could not find GIT_DIR at $GIT_DIR."
	exit 13
fi


# Add/update release tag
git tag -f -a -m "version ${YAWS_VSN}" "$TAG"

# Create release .tar.gz of sources
# (including symlink yaws -> $NAME_VERSION)
rm -rf tmp 2> /dev/null
mkdir tmp
git archive --format=tar --prefix="$NAME_VERSION/" "$TAG" | (cd tmp && tar xf -)
ln -s $NAME_VERSION tmp/yaws
(cd tmp/yaws; autoconf)
(cd tmp && tar cfz - yaws "$NAME_VERSION") > "$NAME_VERSION.tar.gz"

echo release resides in `pwd`/$NAME_VERSION.tar.gz
echo release resides in `pwd`/yaws/win32/Yaws-${YAWS_VSN}-windows-installer.exe

echo "To push this do:"
#echo "git push origin revs/tags/yaws-${version}:revs/tags/yaws-${version}"
echo "ehhh or git push --tags"


exit 0



