#! /bin/sh
# runs autoheader and autoconf with local macros
echo making configure in `pwd`
#if [ ! -s install-sh ] ; then 
#   # bug in AC_CONFIG_SUDIRS requires install-sh (!)
#   cp /homes/gropp/bin/share/automake/install-sh .
#fi
# 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]*\)'`
## We need a fixed autoconf for the Fortran language support
#if [ "$mainversion" != "2" -o "$subversion" -lt 14 ] ; then
#    echo "Using locally patched autoconf"
#    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
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 [ -s Makefile.am -a ! -x $automake ] ; then
    echo "Could not find working automake"
    exit 1
fi
# Change this if autoconf is version 2.52.
ac_version="2.13"
#
# For autoheader, we need to add a few local definitions.  This will ONLY 
# work if ?what
    cat /homes/gropp/sowing-proj/sowing/confdb/acconfig.h acconfigl.h > \
	acconfig.h
#
# Problem: If you can't checkout sowing, you won't have a copy of these 
# files.
if [ ! -d ../../examples/perftest/config/confdb ] ; then
    if [ -d /homes/gropp/sowing-proj/sowing/confdb ] ; then
        cp -rp /homes/gropp/sowing-proj/sowing/confdb \
	    ../../examples/perftest/config 
    fi
fi
# Problem:  aclocal doesn't know how to process include and ifelse
# directives.  
if [ -d ../../examples/perftest/config/confdb ] ; then
    configdir=../../examples/perftest/config/confdb
    #
    # 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 $configdir/$movefile $configdir/$movefile.tmp
    $aclocal -I $configdir
    mv $configdir/$movefile.tmp $configdir/$movefile
fi
$autoheader 
$autoconf   -l /homes/gropp/sowing-proj/sowing/confdb
if [ ! -s configure ] ; then
    echo "WARNING: configure was not created!"
    exit 1
fi
rm -f config.cache config.system
#for dir in $SUBDIRS ; do
#    (cd $dir; ./makeconfigure)
#done
