#!/bin/sh

# Make an ASCII-comparible copy of a version number by zero-padding it
# 1.20.3.4 becomes 01200304
# It removes letters
ugly_version() {
    echo $1 | tr . ' ' | tr -d -c '[0-9 ]' | xargs -n1 printf "%03i"
}

am_version=$(automake --version | head -n1 | cut -d ' ' -f 4)

# It's actually fixed in 1.9.5b, but my version comparison strips the b
am_working=$(ugly_version "1.9.6")
am_v2=$(ugly_version "$am_version")

if test "$am_v2" \< "$am_working" ; then
    topdir="$(cd `dirname $0` && pwd)"

    echo "WARNING: automake < 1.9.5b doesn't know how to handle relative"
    echo "m4_include paths. Working around it."
    echo
    set -x
    mkdir -p "$topdir/m4/m4"
    ln -sf $topdir/m4/fixups.m4 $topdir/m4/m4/fixups.m4
    set +x
    echo
fi

autoreconf --force --verbose --install -I m4 -I thirdparty/m4
