#! /bin/bash
#
# Bootstrap file for 'autotools' build
#

export WANT_AUTOCONF_2_5=1
export LANG=C

amvers="no"

if automake-1.8 --version >/dev/null 2>&1; then
  amvers="-1.8"
#if automake-1.7 --version >/dev/null 2>&1; then
#  amvers="-1.7"
#elif automake-1.6 --version >/dev/null 2>&1; then
#  amvers="-1.6"
#elif automake-1.5 --version >/dev/null 2>&1; then
#  amvers="-1.5"
elif 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
  if expr "$amvers" "<" "1.8" > /dev/null 2>&1; then
    amvers="no"
  else
    amvers=""
  fi
fi

if test "$amvers" = "no"; then
  echo "$0: you need automake version 1.8 or later"
  exit 1
fi

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 INSTALL
rm -Rf autom4te.cache
(mkdir autotools >& /dev/null)
(cd autotools && rm -f config.guess config.sub missing mkinstalldirs compile ltmain.sh depcomp install-sh)

DIE=0

echo ""

if test $DIE = 0 ; then
	echo -n "* Running aclocal...    " ; (aclocal${amvers} -I m4 >& bootstrap.tmpout) \
		&& (echo "[OK]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout) \
		|| (echo "[NO]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout ; not_a_command >& /dev/null) || DIE=1
fi

if test $DIE = 0 ; then
	echo -n "* Running autoconf...   " ; (autoconf >& bootstrap.tmpout) \
		&& (echo "[OK]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout) \
		|| (echo "[NO]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout ; not_a_command >& /dev/null) || DIE=1
fi

if test $DIE = 0 ; then
	echo -n "* Running autoheader... " ; (autoheader >& bootstrap.tmpout) \
		&& (echo "[OK]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout) \
		|| (echo "[NO]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout ; not_a_command >& /dev/null) || DIE=1
fi

if test $DIE = 0 ; then
	echo -n "* Running libtoolize... " ; (libtoolize --copy --force --automake >& bootstrap.tmpout) \
		&& (echo "[OK]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout) \
		|| (echo "[NO]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout ; not_a_command >& /dev/null) || DIE=1
fi

if test $DIE = 0 ; then
	echo -n "* Running automake...   " ; (automake${amvers} --add-missing --copy >& bootstrap.tmpout) \
		&& (echo "[OK]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout) \
		|| (echo "[NO]" ; cat bootstrap.tmpout ; rm -f bootstrap.tmpout ; not_a_command >& /dev/null) || DIE=1
fi

echo ""