+Search()
+{
+ [ $# -eq 2 ] || exit 1
+
+ name="$1"
+ major="$2"
+ minor=99
+
+ type "${name}" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "${name}"
+ return 0
+ fi
+
+ while [ $minor -ge 0 ]; do
+ type "${name}${major}${minor}" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "${name}${major}${minor}"
+ return 0
+ fi
+ type "${name}-${major}.${minor}" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "${name}-${major}.${minor}" >/dev/null 2>&1
+ fi
+ minor=`expr $minor - 1`
+ done
+ return 1
+}
+
+Notfound()
+{
+ echo "Error: $* not found!"
+ echo "Please install recent versions of GNU autoconf and GNU automake."
+ exit 1
+}
+
+# Reset locale settings to suppress warning messages of Perl
+unset LC_ALL
+unset LANG
+
+# We want to use GNU automake 1.7, if available (WANT_AUTOMAKE is used by
+# the wrapper scripts of Gentoo Linux):
+WANT_AUTOMAKE=1.7
+export WANT_AUTOMAKE
+
+# Try to detect the needed tools when no environment variable already
+# spezifies one:
+echo "Searching tools ..."
+[ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
+[ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
+[ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
+[ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
+
+# Some debugging output ...
+if [ -n "$DEBUG" ]; then
+ echo "ACLOCAL=$ACLOCAL"
+ echo "AUTOHEADER=$AUTOHEADER"
+ echo "AUTOMAKE=$AUTOMAKE"
+ echo "AUTOCONF=$AUTOCONF"