#!/bin/sh
#
# Reconfigure the whole project.
#
# usage: reconf
#
# This script will rerun all auto tools. It is for the developer
# only. If you don't know anything about automake/autoconf, do
# never execute this script.
#
# ATTENTION:
#  You need automake-1.4-p5 and autoconf-2.13, otherwise strange things could
#  happen during the build process.
#

export AUTOMAKE AUTOCONF ACLOCAL

status="fail"
for AUTOMAKE in automake automake14 automake-1.4
do
	AUTOMAKE_VER=`(${AUTOMAKE} --version | head -n 1 | cut -d ' ' -f 4 | cut -c -3) 2>/dev/null`
	if [ $? != 0 ]
	then
		continue
	fi
	if [ "$AUTOMAKE_VER" = "1.4" ]
	then
		status=""
		ACLOCAL=aclocal`expr "$AUTOMAKE" : 'automake\(.*\)'`
		break
	fi
done

if [ -n "$status" ]
then
	echo "You need to use automake version 1.4 (preferrable 1.4-p5)."
	echo "You are using `automake --version | head -n 1`."
	echo
	exit 1
fi

status="fail"

for AUTOCONF in autoconf autoconf213 autoconf-2.13
do
	AUTOCONF_VER=`(${AUTOCONF} --version 2>/dev/null | head -n 1 | cut -d ' ' -f 3 | cut -c -4) 2>/dev/null`
	if [ $? != 0 ]
	then
		continue
	fi
	if [ "$AUTOCONF_VER" = "2.13" ]
	then
		status=""
		break
	fi
done

if [ -n "$status" ]
then
	echo "You need to use autoconf version 2.13."
	echo "You are using `autoconf --version | head -n 1`."
	echo
	exit 1
fi

# to see what is executed
set -x

${ACLOCAL}
${AUTOCONF}
${AUTOMAKE} --foreign --add-missing --copy
