#!/bin/sh
#
# build-utils/bootstrap --
#
# Copyright (C) Nicolas Roussel
# Copyright (C) Olivier Chapuis
#
# See the file LICENSE for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

automake_version=`automake --version | grep 'automake' | sed -e 's/^[^0-9]*\([0-9.][0-9.]*\).*$/\1/'`
libtool_version=`libtoolize --version | grep 'libtoolize' | sed -e 's/^[^0-9]*\([0-9.][0-9.]*\).*$/\1/'`
autoconf_version=`env WANT_AUTOCONF_2_5=1 autoconf --version | grep 'autoconf' | sed -e 's/^[^0-9]*\([0-9.][0-9.]*\).*$/\1/'`

echo "found automake version: $automake_version (1.7.x or better required) "
echo "found libtool version:  $libtool_version   (1.4.x or better required)"
echo "found autoconf version: $autoconf_version  (2.57 or better required)"

bad_libtool=true
case $libtool_version in
    1.4*|1.5*|1.6*)
	bad_libtool=false
    ;;
esac

bad_automake=true
case $automake_version in
    1.7*|1.8*|1.9*)
	bad_automake=false
    ;;
esac

bad_autoconf=true
case $autoconf_version in
    2.5*)
	bad_autoconf=false
    ;;
esac

do_abort=false

if $bad_automake ; then
    echo "automake version 1.7 or better is required"
    do_abort=true
fi
if $bad_libtool ; then
    echo "libtool version 1.4 or better is required"
    do_abort=true
fi
if $bad_autoconf ; then
    echo "autoconf version 2.57 or better is required"
    do_abort=true
fi

if $do_abort ; then
    echo "...aborting"
    exit 1
fi

set -x

rm -rf autom4te*.cache
aclocal || exit 1
autoheader || exit 2
libtoolize --automake || exit 3
automake --add-missing || exit 4
# WANT_AUTOCONF_2_5 is used by Mandrake Linux 8.2
env WANT_AUTOCONF_2_5=1 autoconf || exit 5

# autoreconf || exit 6
