ACLOCAL=aclocal
AUTOMAKE=automake
AUTOMAKE_POSTFIX=1.4
AUTOMAKE_VERSION=1.4
# check_version(given,required) compare two versions in up to 6 decimal numbers
check_version()
{
  # number pattern
  N="\([^:]*\)"   
  # remove leading non-numbers, seperate by :
     GIVEN=`echo "$1:0:0:0:0:0:0" | sed -e 's/^[^0-9]*//' -e 's/[^0-9]\+/:/g'`
  REQUIRED=`echo "$2:0:0:0:0:0:0" | sed -e 's/^[^0-9]*//' -e 's/[^0-9]\+/:/g'`
  # extract 6 numbers from $GIVEN into ac_v?
  eval `echo "$GIVEN"    | sed "s/^$N:$N:$N:$N:$N:$N.*$/ac_v1=\1 ac_v2=\2 ac_v3=\3 ac_v4=\4 ac_v5=\5 ac_v6=\6/" `
  # extract 6 numbers from $REQUIRED into ac_r?
  eval `echo "$REQUIRED" | sed "s/^$N:$N:$N:$N:$N:$N.*$/ac_r1=\1 ac_r2=\2 ac_r3=\3 ac_r4=\4 ac_r5=\5 ac_r6=\6/" `
  # do the actual comparison (yielding 1 on success)
  ac_vm=`expr \( $ac_v1 \> $ac_r1 \) \| \( \( $ac_v1 \= $ac_r1 \) \& \(          \
               \( $ac_v2 \> $ac_r2 \) \| \( \( $ac_v2 \= $ac_r2 \) \& \(         \
                \( $ac_v3 \> $ac_r3 \) \| \( \( $ac_v3 \= $ac_r3 \) \& \(        \
                 \( $ac_v4 \> $ac_r4 \) \| \( \( $ac_v4 \= $ac_r4 \) \& \(       \
                  \( $ac_v5 \> $ac_r5 \) \| \( \( $ac_v5 \= $ac_r5 \) \& \(      \
                   \( $ac_v6 \>= $ac_r6 \)                                       \
                  \) \)  \
                 \) \)   \
                \) \)    \
               \) \)     \
              \) \)      `
  #echo "Given:    ac_v1=$ac_v1 ac_v2=$ac_v2 ac_v3=$ac_v3 ac_v4=$ac_v4 ac_v5=$ac_v5 ac_v6=$ac_v6"
  #echo "Required: ac_r1=$ac_r1 ac_r2=$ac_r2 ac_r3=$ac_r3 ac_r4=$ac_r4 ac_r5=$ac_r5 ac_r6=$ac_r6"
  #echo "Result:   $ac_vm"
  test $ac_vm = 1
}
if check_version "`$AUTOMAKE --version 2>/dev/null | sed 1q`" $AUTOMAKE_VERSION ; then
        :       # all fine
elif check_version "`$AUTOMAKE$AUTOMAKE_POSTFIX --version 2>/dev/null | sed 1q`" $AUTOMAKE_VERSION ; then
        AUTOMAKE=$AUTOMAKE$AUTOMAKE_POSTFIX
        ACLOCAL=$ACLOCAL$AUTOMAKE_POSTFIX  
elif check_version "`$AUTOMAKE-$AUTOMAKE_POSTFIX --version 2>/dev/null | sed 1q`" $AUTOMAKE_VERSION ; then
        AUTOMAKE=$AUTOMAKE-$AUTOMAKE_POSTFIX
        ACLOCAL=$ACLOCAL-$AUTOMAKE_POSTFIX  
else
        echo "You need to have $AUTOMAKE (version >= $AUTOMAKE_VERSION) installed to compile $PROJECT."
        echo "Download the appropriate package for your distribution,"
        echo "or get the source tarball at http://ftp.gnu.org/gnu/automake"
        DIE=1
fi
echo ATUOMAKE=$AUTOMAKE ACLOCAL=$ACLOCAL
