#! /bin/sh

# If any step fails, the bootstrap exits
# Linux use aclocal-1.5 ie aclocal-1.5
# Solaris use version 1.4 ie aclocal 

set -x
/bin/rm -f config.cache

if aclocal-1.5 --version > /dev/null; then
  ACLOCAL="aclocal-1.5"
else
  if aclocal --version > /dev/null; then
    ACLOCAL="aclocal"
  else
    echo "Could not find suitable aclocal"
  fi
fi

if automake-1.5 --version > /dev/null; then
  AUTOMAKE="automake-1.5"
else
  if automake --version > /dev/null; then
      AUTOMAKE="automake"
  else
    echo "Could not find suitable automake"
  fi
fi

if autoheader-2.53 --version > /dev/null; then
  AUTOHEADER="autoheader-2.53"
else
  if autoheader --version > /dev/null; then
      AUTOHEADER="autoheader"
  else
    echo "Could not find suitable autoheader"
  fi
fi

if autoconf-2.53 --version > /dev/null; then
  AUTOCONF="autoconf-2.53"
else
  if autoconf --version > /dev/null; then
      AUTOCONF="autoconf"
  else
    echo "Could not find suitable autoconf"
  fi
fi

# *** IF YOU ARE NOT BUILDING WITH GNU MAKE *AND* GCC: you must
# *** add --include-deps
touch .make_v_tmpfile; make -v -f .make_v_tmpfile 2>/dev/null | grep GNU 1>/dev/null 2>/dev/null; 
if [ $? != 0 ]; then
  echo "Default 'make' is not GNU make; appending --include-deps to AUTOMAKE_FLAGS"
  AUTOMAKE_FLAGS="--include-deps $AUTOMAKE_FLAGS"
fi
/bin/rm .make_v_tmpfile
AUTOMAKE_FLAGS="--foreign --copy $AUTOMAKE_FLAGS"


$ACLOCAL -I config_ac \
&& $AUTOHEADER \
&& $AUTOMAKE $AUTOMAKE_FLAGS \
&& $AUTOCONF \
|| echo "bootstrap failed"

# aclocal -I config_ac && autoheader && automake --foreign --copy --include-deps && autoconf || echo "bootstrap failed"
# aclocal-1.5  && autoheader-2.53  && automake-1.5  --foreign --copy --include-deps && autoconf-2.53 || echo "bootstrap failed"

# do the configure outsite the bootstrap script
# && ./configure --cache-file=./config.cache --prefix=`pwd`/`config_ac/config.guess`/install \
