#! /bin/sh
# runs autoheader and autoconf with local macros
echo making configure in `pwd`
# Check on version of autoconf
#autoconf=autoconf
#autoheader=autoheader
#version=`autoconf --version | sed -e 's/Autoconf version //'`
#mainversion=`expr $version : '\([0-9]\)\..*'`
#subversion=`expr $version : '[0-9]\.\([0-9]*\)'`
#if [ "$mainversion" != "2" -o "$subversion" -lt 13 ] ; then
#    autoconf=/homes/gropp/bin/autoconf
#    autoheader=/homes/gropp/bin/autoheader
#fi
# Must use patched automake
if [ -z "$ARCH" ] ; then
    system="`uname -sr | sed -e 's/ /-/g'`"
    case "$system" in 
	SunOS-5*) ARCH=solaris-2 ;;
	Linux*)   ARCH=linux ;;
    esac
fi
larch=$ARCH
case "$larch" in
    linux*|Linux*) larch=linux ;;
esac
automake=/homes/gropp/bin/$larch/automake
aclocal=/homes/gropp/bin/$larch/aclocal
autoheader=/homes/gropp/bin/$larch/autoheader
autoconf=/homes/gropp/bin/$larch/autoconf
if [ ! -x $automake ] ; then
    echo "Could not find working automake"
    exit 1
fi
# Change this if autoconf is version 2.52.
ac_version="2.13"
#
if [ ! -d config/confdb ] ; then
    (cd config ; cvs -d /homes/gropp/cvsMaster_z -r checkout confdb )
fi
#
# GRRRR.  aclocal reads *everything* out of the directory.  This
# breaks when the aclocal.m4 file includes different files depending on
# which mutually incompatible version of autoconf is being used.
# The problem is that automake needs aclocal.  We try to fix this 
# by hoping for autoconf 2.13 instead of 2.52
if [ "$ac_version" = "2.13" ] ; then
    movefile=aclangf90.m4
else
    movefile=aclocal_f90.m4
fi
mv config/confdb/$movefile config/confdb/$movefile.tmp
$aclocal -I config/confdb
mv config/confdb/$movefile.tmp config/confdb/$movefile
if [ `uname -s` = "SunOS" -a `uname -r` = "5.7" ] ; then
    echo "Dependency handling turned off"
    #$automake --no-dependencies
    $automake -i
elif [ "$MAKE_DIST_MAKEFILE" = "yes" ] ; then
    # This is a special entry point for building tar files without using
    # the make dist target (for example, for including this package within
    # MPICH)
    $automake --include-deps --foreign Makefile
else
    # Turn off dependencies even locally so that development builds that
    # use vpath will work
    $automake -i
fi
$autoheader 
$autoconf  
rm -f config.cache config.system
