#!/bin/sh
# Takes one optional argument: the new version number.
# If not provided, increment previous patch number,
# e.g. 3.45.6 ==> 3.45.7, or 3.56 ==> 3.56.1
NEWVER="${1}"
PROG="$0"
ASDFDIR="$(cd $(dirname $PROG)/.. ; /bin/pwd)" ## readlink -f doesn't work on BSD
ASDFLISP=${ASDFDIR}/asdf.lisp
ASDFASD=${ASDFDIR}/asdf.asd

if [ -z "$NEWVER" ] ; then
  OLDVER="$(grep '         (asdf-version "' $ASDFLISP | cut -d\" -f2)"
  NEWVER="$(echo $OLDVER | perl -npe 's/([0-9].[0-9]+)(\.([0-9]+))?/"${1}.".($3+1)/e')"
fi
echo "Setting ASDF version to $NEWVER"
perl -i.bak -npe 's/^(         \(asdf-version "|;;; This is ASDF )[0-9.]+("\)|:)/${1}'"$NEWVER"'${2}/' $ASDFLISP
perl -i.bak -npe 's/^(  :version ")[0-9.]+(")/${1}'"$NEWVER"'${2}/' $ASDFASD
cat<<EOF
To complete the version change, you may:
	git add -u
	git commit
	git tag $NEWVER
EOF
