#!/bin/sh
#
# Copyright (c) 2002
# Reinhard Jessich  <reinhard.jessich@telering.at>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in
#   the documentation and/or other materials provided with the
#   distribution.
#
# * Neither the name of the copyright holders nor the names of
#   contributors may be used to endorse or promote products derived
#   from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# 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 AUTOHEADER

status="fail"
#for AUTOMAKE in automake automake14 automake-1.4
for AUTOMAKE in automake 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
for AUTOCONF in autoconf 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=""
		AUTOHEADER=autoheader`expr "$AUTOCONF" : 'autoconf\(.*\)'`
		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}
#${AUTOHEADER}
${AUTOCONF}
${AUTOMAKE} --foreign --add-missing --copy
