#!/bin/sh

# this small script increments build version number

if [ $# != 1 -a $# != 2 ]
   then
   echo "Usage: $0 build-filename [target]"
   exit 1
   fi

build=$1
build_log=$build.log

if test ! -f $build -o ! -f $build_log ; then
  exit 0
fi

if [ $# = 2 ]; then
  target=" $2"
else
  target=
fi

current=`cat $build` || exit 1

new=`expr $current + 1` || exit 1

#chmod u+w $build
echo $new >$build
#chmod u-w $build

if [ "$WINDIR" != "" ]; then
  target="$target (win)"
fi

if [ -w $build_log ]; then
  echo "`printf "%04d" $current` `date`$target" >> $build_log
fi

echo Current build number is $current

exit 0
