#!/bin/sh
#
# Generate a current snapshot from source control

echo "Updating source"
cd $HOME/libsdl.org/tmp
dir=SDL
(cd $dir && \
    git checkout include/SDL_revision.h && \
    git pull && \
    sh build-scripts/updaterev.sh)

major=`fgrep "#define SDL_MAJOR_VERSION" $dir/include/SDL_version.h | \
       sed 's,[^0-9]*\([0-9]*\),\1,'`
minor=`fgrep "#define SDL_MINOR_VERSION" $dir/include/SDL_version.h | \
       sed 's,[^0-9]*\([0-9]*\),\1,'`
patch=`fgrep "#define SDL_PATCHLEVEL" $dir/include/SDL_version.h | \
       sed 's,[^0-9]*\([0-9]*\),\1,'`
rev=`fgrep "#define SDL_REVISION " $dir/include/SDL_revision.h | \
       sed 's,.*\@\(.......\).*,\1,'`
path="SDL-$major.$minor.$patch-$rev"

mv $dir/.git $dir-git
mv $dir $path
echo $path.tar.gz
tar zcf $path.tar.gz $path
echo $path.zip
rm -f $path.zip
zip -rq $path.zip $path
mv $path $dir
mv $dir-git $dir/.git

ln -sf $path.tar.gz SDL-2.0.tar.gz
ln -sf $path.zip SDL-2.0.zip
date=`date +"%a %b %e"`
sed -e "s|<!-- SDL 2.0 DATE -->.*|<!-- SDL 2.0 DATE --> $date|" \
    -e "s|<!-- SDL 2.0 ZIP -->.*<!-- -->|<!-- SDL 2.0 ZIP --><a href=\"tmp/$path.zip\">$path.zip</a><!-- -->|" \
    -e "s|<!-- SDL 2.0 TGZ -->.*<!-- -->|<!-- SDL 2.0 TGZ --><a href=\"tmp/$path.tar.gz\">$path.tar.gz</a><!-- -->|" \
<../git.php >../git.php.new
mv ../git.php.new ../git.php
