+set -e
+
+usage () {
+ if ! [ -z "$1" ]
+ then
+ echo $1
+ fi
+ cat <<EOF
+
+usage: $0 [-s] VERSION-NUMBER [REV]
+
+ This script frobs NEWS, makes a "release" commit, builds, runs tests
+ and creates an annotated tag for the release with VERSION-NUMBER.
+
+ If -s is given, then use the gpg-sign mechanism of "git tag". You
+ will need to have your gpg secret key handy.
+
+ if REV is given, it is the git revision to build into a release.
+ Default is origin/master.
+
+ No changes will be pushed upstream. This script will tell you how to
+ do this when it finishes.
+
+EOF
+ exit 1
+}
+
+if [ "-s" = "$1" ] || [ "--sign" = "$1" ]
+then
+ sign="-s"; shift
+else
+ sign=""
+fi
+
+if [ -z "$1" ]
+then
+ usage "No version number."
+else
+ version=$1; shift
+fi
+
+if [ -z "$1" ]
+then
+ rev=origin/master
+else
+ rev=$1; shift
+ type=$(git cat-file -t "$rev" 2> /dev/null || echo "unknown")
+ if ([ "tag" != "$type" ] && [ "commit" != "$type" ])
+ then
+ usage "$rev is $type, not a tag or a commit."
+ fi
+fi
+
+if ! [ -z "$@" ]
+then
+ usage "Extra command-line arguments: $@"
+fi
+
+sbcl_directory="$(cd "$(dirname $0)"; pwd)"
+tmpfile=$(mktemp -t sbcl-build-$(date +%Y%m%d)-XXXXXXXXX)
+tmpdir="$(mktemp -d -t sbcl-build-tree-$(date +%Y%m%d)-XXXXXXXXX)"
+
+## Check for messy work dirs:
+
+echo "Fetching updates."
+git fetch
+
+branch_name="release-$(date '+%s')"
+original_branch="$(git describe --all --contains HEAD)"
+trap "cd \"$sbcl_directory\" ; git checkout $original_branch" EXIT
+git checkout -b $branch_name $rev
+
+echo "Checking that the tree is clean."
+if ! [ $(git status --porcelain | wc -l) = 0 ]
+then
+ echo "There are uncommitted / unpushed changes in this checkout!"
+ git status
+ exit 1
+fi
+
+## Perform the necessary changes to the NEWS file:
+
+echo "Munging NEWS"
+sed -i.orig "/^changes relative to sbcl-.*:/ s/changes/changes in sbcl-$version/ " NEWS
+rm -f NEWS.orig
+if ! grep "^changes in sbcl-$version relative to" NEWS > /dev/null
+then
+ echo "NEWS munging failed!"
+ exit 1
+fi