+# This script generates the ./configure script using GNU automake and
+# GNU autoconf. It tries to be smart in finding the correct/usable/available
+# installed versions of these tools on your system.
+#
+# In addition, it enables or disables the "de-ANSI-fication" support of GNU
+# automake, which is supported up to autoconf 1.11.x an has been removed
+# in automake 1.12 -- make sure to use a version of automake supporting it
+# when generating distribution archives!
+#
+# The following strategy is used for each of aclocal, autoheader, automake,
+# and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
+# or "automake") is checked. If this fails, "tool<major><minor>" (for example
+# "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
+# with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
+# <minor> is tried from 99 to 0. The first occurrence will be used.
+#
+# When you pass <configure-args> to autogen.sh it will call the generated
+# ./configure script on success and pass these parameters to it.
+#
+# You can tweak the behaviour using these environment variables:
+#
+# - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
+# Name and optionally path to the particular tool.
+# - PREFIX=<path>
+# Search the GNU autoconf and GNU automake tools in <path> first. If the
+# generated ./configure script will be called, pass "--prefix=<path>" to it.
+# - EXIST=<tool>
+# Use <tool> to test for aclocal, autoheader etc. pp. ...
+# When not specified, either "type" or "which" is used.
+# - VERBOSE=1
+# Output the detected names of the GNU automake and GNU autoconf tools.
+# - GO=1
+# Call ./configure even if no arguments have been passed to autogen.sh.
+#
+# Examples:
+#
+# - ./autogen.sh
+# Generates the ./configure script.
+# - GO=1 ./autogen.sh
+# Generates the ./configure script and runs it as "./configure".
+# - VERBOSE=1 ./autogen.sh --with-ident
+# Show tool names, generates the ./configure script, and runs it with
+# these arguments: "./configure --with-ident".
+# - ACLOCAL=aclocal-1.6 GO=1 PREFIX=$HOME ./autogen.sh
+# Uses "aclocal-1.6" as aclocal tool, generates the ./configure script,
+# and runs it with these arguments: "./configure --prefix=$HOME".
+#
+
+Search()
+{
+ [ $# -eq 2 ] || exit 1
+
+ searchlist="$1"
+ major="$2"
+ minor=99
+
+ [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
+
+ for name in $searchlist; do
+ $EXIST "${name}" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ "${name}" --version 2>&1 \
+ | grep -v "environment variable" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "${name}"
+ return 0
+ fi
+ fi
+ done
+
+ while [ $minor -ge 0 ]; do
+ for name in $searchlist; do
+ $EXIST "${name}${major}${minor}" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "${name}${major}${minor}"
+ return 0
+ fi
+ $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "${name}-${major}.${minor}"
+ return 0
+ fi
+ done
+ minor=$(expr $minor - 1)
+ done
+ return 1
+}
+
+Notfound()
+{
+ echo "Error: $* not found!"
+ echo 'Please install supported versions of GNU autoconf, GNU automake'
+ echo 'and pkg-config: see the INSTALL file for details.'
+ exit 1
+}
+
+Run()
+{
+ [ "$VERBOSE" = "1" ] && echo " - running \"$*\" ..."
+ "$@"
+}