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

export WANT_AUTOCONF="latest"
export WANT_AUTOMAKE="1.9"
export LANG=C

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 -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

# Bug with automake 1.10?
touch autotools/config.rpath

if test $DIE = 0 ; then
	echo -n "* Running automake...   " ; (automake --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 ""