#! /bin/sh
set -x
set -e

# Check for automake
amvers="none"
if automake-1.7 --version >/dev/null 2>&1
then
  amvers="-1.7"
else
  if automake-1.6 --version >/dev/null 2>&1
  then
    amvers="-1.6"
  else
    if automake-1.5 --version >/dev/null 2>&1
    then
      amvers="-1.5"
    else
      if automake --version > /dev/null 2>&1
      then
        amvers=`automake --version | sed -e '1s/[^0-9]*//' -e q`
  
        if expr "$amvers" "<" "1.5" > /dev/null 2>&1
        then amvers="none"
        else amvers=""
        fi        
      fi
    fi 
  fi
fi

if test "$amvers" = "none"
then
  set +x
  echo "bootstrap: you need automake version 1.5 or later"
  exit 1
fi

# Remove old cruft
rm -f aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh
(cd autotools && rm -f config.guess config.sub missing mkinstalldirs compile ltmain.sh depcomp install-sh)

aclocal${amvers}
libtoolize --copy --force
autoconf
autoheader
automake${amvers} --add-missing --copy