dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
dnl
dnl aclocal_cache.m4, included by sowing/confdb/aclocal.m4, fixes 
dnl bugs in autoconf caching.
dnl
dnl
dnl Environment variables that affect behavior of the test configure
dnl MPICH_FAST 
dnl
dnl The file name here refers to a file in the source being configured
AC_INIT(include/mpitest.h)
AC_CONFIG_HEADER(include/mpitestconf.h)
AH_TOP([/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*  
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#ifndef FORKERCONF_H_INCLUDED
#define FORKERCONF_H_INCLUDED
])
AH_BOTTOM([#endif])
# This version is the version of the test suite.
VERSION=1.0
AC_SUBST(VERSION)
dnl
AC_CONFIG_AUX_DIR(../../confdb)
dnl
echo "RUNNING CONFIGURE FOR MPI TESTS"
AC_ARG_ENABLE(echo, 
[--enable-echo  - Turn on strong echoing. The default is enable=no.] ,set -x)
otherlangs=""
AC_ARG_ENABLE(f77,
[--enable-f77 - Turn on Fortran 77 tests (default)],,enable_f77=yes)
dnl
AC_ARG_ENABLE(f90,
[--enable-f90 - Turn on Fortran 90 tests (if f90 available)],,enable_f90=default)
AC_ARG_ENABLE(cxx,
[--enable-cxx - Turn on C++ tests (default)],,enable_cxx=yes)
AC_ARG_ENABLE(romio,
[--enable-romio - Enable ROMIO MPI I/O implementation],
,enable_romio=yes)
AC_ARG_ENABLE(spawn,
[--enable-spawn - Enable tests of the dynamic process parts of MPI-2 (default)],
,enable_spawn=yes)
AC_ARG_ENABLE(checkerrors,
[--enable-checkerrors - Add some tests for checking for errors in user programs],,enable_checkerrors=default)
AC_ARG_ENABLE(fast,
[--enable-fast - Indicates that the MPI implementation may have been built for fastest operation, such as building without error checking.  Has the effect of --enable-checkerrors=no])

AC_ARG_WITH(mpi,
[--with-mpi=dir - Use the selected MPI; compilation scripts for mpicc, mpif77
                  and mpicxx should be in dir/bin],,)

AC_ARG_ENABLE(threads,
[--enable-threads=level - Specify the level of thread support expected from the
MPI implementation.  The following levels are supported.
    single - No threads (MPI_THREAD_SINGLE)
    funneled - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
    serialized - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
    multiple - Fully multi-threaded (MPI_THREAD_MULTIPLE)
The default is funneled.  If enabled and no level is specified, the
level is set to multiple.  If disabled, the level is set to single.
If the environment variable MPICH_THREAD_LEVEL is set, that thread
level is used (this is to let MPICH2 build for the correct thread 
support without requiring a specific --enable-threads argument.
],,
enable_threads=default)
# ------------------------------------------------------------------------
if test "$enable_threads" = "yes" ; then 
    enable_threads=multiple
elif test "$enable_threads" = "no" ; then
    enable_threads=single
elif test "$enable_threads" = default ; then
    if test -n "$MPICH_THREAD_LEVEL" ; then
        case $MPICH_THREAD_LEVEL in 
	    MPI_THREAD_MULTIPLE)
	    enable_threads=multiple
	    ;;
	    MPI_THREAD_SERIALIZED)
	    enable_threads=serialized
	    ;;
	    MPI_THREAD_FUNNELED)
	    enable_threads=funneled
	    ;;
	    MPI_THREAD_SINGLE)
	    enable_threads=single
	    ;;
        esac
    else
        enable_threads=funneled
    fi
fi

if test "$enable_fast" = "yes" ; then
    if test "$enable_checkerrors" = "default" ; then
        enable_checkerrors=no
    fi
fi
# default for MPICH2 is to check error handling; for other cases it
# is to only check correct programs.
if test "$FROM_MPICH2" = "yes" ; then
    if test "$enable_checkerrors" = "default" -a "$MPICH_FAST" != "YES" ; then
         enable_checkerrors=yes
    else 
         enable_checkerrors=no
    fi
else
    if test "$enable_checkerrors" = "default" ; then
         enable_checkerrors=no
    fi
fi
# errordir is substituted into the testlist file as errors when the
# tests should check error handling and as a comment (#) otherwise.
errordir="#"
if test "$enable_checkerrors" = "yes" ; then
    errordir=errors
fi
AC_SUBST(errordir)
# 
# Only run the threads tests if multiple is specified
if test "$enable_threads" = "multiple" ; then
    threadsdir="threads"
fi

PAC_LOAD_BASE_CACHE

PAC_VPATH_CHECK()

PAC_PROG_MAKE

MPILIBLOC=""
AC_SUBST(MPILIBLOC)
# Select the base compiler.  We need to run them through
# the ac_prog_xx commands because in later versions of autoconf, these
# commands do more than just find the program, they set many of the 
# variables that are needed when using the other autoconf commands, such as 
# try compile
AC_PROG_CC
if test -z "$BASECC" ; then
    BASECC="$CC"
fi
# If we're building from MPICH2, check the MPICH2_ENABLE_xxx environment
# variables for enable defaults
if test "$FROM_MPICH2" = yes ; then
    if test -n "$MPICH2_ENABLE_F77" ; then
        enable_f77=$MPICH2_ENABLE_F77
    fi
    if test -n "$MPICH2_ENABLE_F90" ; then
        enable_f90=$MPICH2_ENABLE_F90
    fi
    if test -n "$MPICH2_ENABLE_CXX" ; then
        enable_cxx=$MPICH2_ENABLE_CXX
    fi
    #
    # Set the BASE_xx variables from MPICH2_BASE_xx environment
    if test -n "$MPICH2_BASEF77" ; then
        BASEF77=$MPICH2_BASEF77
    fi
    if test -n "$MPICH2_BASEF90" ; then
        BASEF90=$MPICH2_BASEF90
    fi
    if test -n "$MPICH2_BASECXX" ; then
        BASECXX=$MPICH2_BASECXX
    fi
fi
if test "$enable_f77" = yes ; then
    AC_PROG_F77
    if test -z "$BASEF77" ; then
        BASEF77="$F77"
    fi
    # If there is no working F77, then set enable_f77 to no
    if test -z "$F77" ; then
        enable_f77=no
    fi    
fi
if test "$enable_cxx" = yes ; then
    AC_PROG_CXX
    if test -z "$BASECXX" ; then
        BASECXX="$CXX"
    fi
    if test -z "$CXX" ; then
        enable_cxx=no
    fi
fi
# 
# Some MPI-2 implementations (including some of the MPICH2 shared-memory
# channels and BG/L) leave out the dynamic process routines.  This
# allows tests to avoid reporting failure for these routines.  
# This can be controlled by either a --disable-spawn argument or by
# setting the environment variable MPI_NO_SPAWN to yes.
spawndir=spawn
if test "$enable_spawn" != yes ; then
    spawndir="#"
elif test "$MPI_NO_SPAWN" = yes ; then
    spawndir="#"
fi
#echo "MPI_NO_SPAWN = $MPI_NO_SPAWN"
AC_SUBST(spawndir)

# Also allow rma to be disabled
rmadir=rma
if test "$MPI_NO_RMA"  = yes ; then
    rmadir="#"
else
    AC_DEFINE(HAVE_MPI_WIN_CREATE,1,[Define if MPI_Win_create is available])
fi
AC_SUBST(rmadir)
#
# Now, get the versions of the compilers that we'll use for MPI programs
if test -n "$with_mpi" ; then
    if test -z "$MPICC" ; then
        CC=$with_mpi/bin/mpicc
    else 
        CC=$MPICC
    fi	
    if test -z "$MPIF77" ; then
        F77=$with_mpi/bin/mpif77
    else
        F77=$MPIF77
    fi
    if test -z "$MPICXX" ; then
        CXX=$with_mpi/bin/mpicxx
    else
        CXX=$MPICXX
    fi
    if test -z "$MPIEXEC" ; then
        MPIEXEC=$with_mpi/bin/mpiexec
    fi        
else
    if test -z "$top_build_dir" ; then 
        top_build_dir=`cd ../.. ; pwd`
    fi

    # The following choices can cause problems if we configure as part of a 
    # MPICH2 configure, because the libraries may not yet exist.  In 
    # that case, we wait to make these definitions until after the
    # tests, since the environment variables for the compilers is set 
    # as part of the initial build
    if test "$FROM_MPICH2" != yes ; then
        if test -z "$BASECC" ; then 
            BASECC=$CC
        fi     
        BASEF77=$F77
        CC=$top_build_dir/bin/mpicc
        FC=$top_build_dir/bin/mpif77
        F77=$FC
	BASEF90=$F90
        F90=$top_build_dir/bin/mpif90
        CXX=$top_build_dir/bin/mpicxx
        # Be careful of exec prefix
	if test "X$exec_prefix" = "XNONE" ; then
	    saveExec_prefix=$exec_prefix
	    if test "X$prefix" = "XNONE" ; then
	        # Use the default
	        exec_prefix=$ac_default_prefix
	    else
	        exec_prefix=$prefix
	    fi
	    # Evaluate with the current setting of exec_prefix
	    eval mpibindir=${bindir}
	    exec_prefix=$saveExec_prefix
        else
            eval  mpibindir=${bindir}
	fi
        MPIEXEC=$mpibindir/mpiexec
    else
        # Remove the libraries, since they will not be needed for the
        # few tests that we do
        saveLIBS=$LIBS
        LIBS=
    fi
fi

# Clear the CPPFLAGS, since the MPI configure will have added many items
# that are not required for user MPI programs.
CPPFLAGS=
#
# Note that some versions of autoconf will insist that the compiler 
# produce executables at this point, which is why we must do something
# special for building within MPICH2
dnl We cannot use AC_C_LONG_DOUBLE
dnl because it does not support cross-compilation.  Instead, we use the
dnl same test in the MPICH2 configure.
# Check on support for long double and long long types.  Do this before the
# structure alignment test because it will test for including those
# types as well
AC_CACHE_CHECK([whether long double is supported],pac_cv_have_long_double,[
     AC_TRY_COMPILE(,[long double a;],
    pac_cv_have_long_double=yes,pac_cv_have_long_double=no)])
if test "$pac_cv_have_long_double" = "yes" ; then
    AC_DEFINE(HAVE_LONG_DOUBLE,1,[Define if long double is supported])
fi
AC_CACHE_CHECK([whether long long is supported],pac_cv_have_long_long,[
    AC_TRY_COMPILE(,[long long a;],
    pac_cv_have_long_long=yes,pac_cv_have_long_long=no)])
if test "$pac_cv_have_long_long" = yes ; then 
    AC_DEFINE(HAVE_LONG_LONG,1,[Define if compiler supports long long])
fi
#
# Check for const and restrict (used in some of the performance tests)
AC_C_CONST
PAC_C_RESTRICT

# General headers
AC_CHECK_HEADERS(unistd.h stdarg.h string.h stdlib.h memory.h)

# Define functionality that we support

# Now, select the proper compilers for the tests
if test "$FROM_MPICH2" = yes ; then
    AC_MSG_RESULT([Configuring tests for MPICH2])
    # Build for testing in place if no prefix was given
    if test "$enable_in_place" = yes -o "X$prefix" = "XNONE" ; then
        LIBS=$saveLIBS
	if test -z "$BASECC" ; then
	    BASECC=$CC
        fi
	# We need the base Fortran compiler for some tests that 
	# are only about Fortran, not MPI and Fortran
	BASEF77=$F77
	#BASEINCDIR=$top_build_dir/src/include
        CC=$top_build_dir/bin/mpicc
        FC=$top_build_dir/bin/mpif77
        F77=$FC
        CXX=$top_build_dir/bin/mpicxx
	BASEF90=$F90
        F90=$top_build_dir/bin/mpif90
	MPIEXEC=$top_build_dir/bin/mpiexec
        MPILIBLOC=$top_build_dir/lib/libmpich.a
    else
        # note that the default definition of bindir is 
	#    '${exec_prefix}/bin'
        # so even if prefix is set, exec prefix is not until
	# the very last moment (i.e., not here). 
	if test "X$exec_prefix" = "XNONE" ; then
	    saveExec_prefix=$exec_prefix
	    if test "X$prefix" = "XNONE" ; then
	        # Use the default
	        exec_prefix=$ac_default_prefix
	    else
	        exec_prefix=$prefix
	    fi
	    # Evaluate with the current setting of exec_prefix
	    eval mpibindir=${bindir}
	    exec_prefix=$saveExec_prefix
        else
            eval  mpibindir=${bindir}
	fi
	if test -z "$BASECC" ; then
	    BASECC=$CC
        fi
        CC=$mpibindir/mpicc
        FC=$mpibindir/mpif77
        BASEF77=$F77
        F77=$FC
        CXX=$mpibindir/mpicxx
        MPIEXEC=$mpibindir/mpiexec
        # For some of the tests below, we'll need a separate compiler
	# One more complication.  If we are in the midst of building
	# MPICH2, the installation directory does not yet contain
	# the current compilation scripts (just to make things worse,
	# it *may* contain old scripts!).
#        if test ! -x $CXX ; then
            CXXTEST=$top_build_dir/bin/mpicxx
#        else 
#            CXXTEST=$CXX
#        fi
	BASEF90=$F90
        F90=$mpibindir/mpif90
    fi
fi
# Simple tests for which other languages we can handle.  
# Use these only when configuring separate from an MPICH2 build
f77dir="#"
AC_SUBST(f77dir)
buildingF77=no
if test "$FROM_MPICH2" = yes ; then
    if test "$enable_f77" = yes ; then
       # Assume success
        otherlangs="$otherlangs f77"
	f77dir=f77
	buildingF77=yes
    fi
elif test "$enable_f77" = yes ; then
    AC_MSG_CHECKING([that we can build MPI programs with Fortran 77])
    rm -f conftest*
    cat >conftest.f <<EOF
        program main
        include 'mpif.h'
        integer ierr
        call mpi_init(ierr)
        call mpi_finalize(ierr)
        end
EOF
    if test -z "$FC" ; then FC=$F77 ; fi
    if $FC -o conftest conftest.f >conftest.out 2>&1 ; then
        AC_MSG_RESULT(yes)
        otherlangs="$otherlangs f77"
	f77dir=f77
	buildingF77=yes
    else
        AC_MSG_RESULT(no)
	echo "Failed program was" >&AC_FD_CC
	cat conftest.f >&AC_FD_CC
	echo "Compiler output was" >&AC_FD_CC
        cat conftest.out >&AC_FD_CC
    fi
    rm -f conftest*
fi
#
# At least one test (C++ test of C and Fortran datatypes) needs to 
# know if Fortran is supported
if test "$f77dir" = "f77" ; then
    AC_DEFINE(HAVE_FORTRAN_BINDING,1,[Define if Fortran is supported])
fi

# Common tests for F77
if test "$buildingF77" = "yes" ; then
    # Match integer types to the MPI types for MPI_Aint and MPI_Offset

    # FIXME: Add a test to see if the environment is importing the
    # necessary information.

    # Get the sizes of the MPI types.  We use the following:
    # MPI_SIZEOF_OFFSET and MPI_SIZEOF_AINT
    if test -z "$MPI_SIZEOF_AINT" ; then
        # Aint should be an address-sized integer, the same as void*
        # We use a test on the size of void * to avoid any complications
        # in dealing with running programs containing MPI headers (e.g.,
        # the IBM MPI changes the main entry point so that MPI 
	# programs cannot be run on the host node)
        AC_CHECK_SIZEOF(void *,$CROSS_SIZEOF_VOID_P)
	MPI_SIZEOF_AINT=$ac_cv_sizeof_void_p
    fi
    if test -z "$MPI_SIZEOF_OFFSET" ; then
        # We have to try and get the size of offset anyway, since 
	# it is not the same as void * (it depends on the available
	# file systems).  Since we want to avoid using the MPI linker,
        # we could do the following:
        #    Use the mpi compiler to compile the file, using the mpi 
	#    header but no MPI calls
        #    Use the regular C linker to link the program
        # However, we do this only if the environment variable BASECC
        # has been provided.  Else we can try the following:
        # use
        #    sed -n 's/typedef \(.*\) MPI_Offset *;/\1/p' mpi.h
        # to extract the type corresponding to MPI_Offset and then
        # just use that.
        AC_CACHE_CHECK([the sizeof MPI_Offset],ac_cv_sizeof_MPI_Offset,[
             ac_cv_sizeof_MPI_Offset=unknown
	     rm -f conftest*
             cat >>conftest.c <<EOF
#include "mpi.h"
#include <stdio.h>
int main( int argc, char **argv )
{
    MPI_Offset a;
    FILE *f = fopen("conftestval", "w" );
    if (! f) exit(1);
    fprintf( f, "%ld\n", (long)sizeof(MPI_Offset) );
    fclose(f);
    return 0;
}
EOF
        # FIXME.  Check for BASECC
        # Note: This assumes that CC has been set to the C compiler for
        # MPI Programs, and that either any necessary include paths are 
        # already set or they are in CPPFLAGS (prefered) or CFLAGS.
        if AC_TRY_EVAL(ac_link) && test -s conftest$ac_exeext ; then
            if ./conftest$ac_exeext ; then
                #success
                ac_cv_sizeof_MPI_Offset=`cat conftestval`
            else
                # failure
                AC_MSG_WARN([Unable to run the program to determine the size of MPI_Offset])
	        echo "configure: failed program was:" >&AC_FD_CC
	        cat conftest.c >&AC_FD_CC
	    fi
        else
	    # failure
            AC_MSG_WARN([Unable to build the program to determine the size of MPI_Offset])
	    echo "configure: failed program was:" >&AC_FD_CC
	    cat conftest.c >&AC_FD_CC
        fi
        rm -f conftest*
])
	if test "$ac_cv_sizeof_MPI_Offset" = "unknown" ; then
	     AC_MSG_WARN([Using 8 for the size of MPI_Offset])
	     MPI_SIZEOF_OFFSET=8
        else
             MPI_SIZEOF_OFFSET=$ac_cv_sizeof_MPI_Offset
        fi
    fi
    # Find out if the sized types are available in Fortran (we need only
    # the Fortran compiler, not the MPI-Fortran compiler)
    saveF77=$F77
    if test -z "$BASEF77" ; then
       # Find some Fortran compiler.  Note that we've already saved the
       # old F77
       F77=
       save_FFLAGS="$FFLAGS"
       AC_PROG_F77
       FFLAGS="$save_FFLAGS"
       BASEF77=$F77
    fi
    if test -n "$BASEF77" ; then
        F77=$BASEF77
    fi	
    
    AC_LANG_FORTRAN77
    AC_CACHE_CHECK([whether integer*4 is supported],pac_cv_fort_integer4,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*4 i])],
        pac_cv_fort_integer4=yes,
        pac_cv_fort_integer4=no)])
    AC_CACHE_CHECK([whether integer*8 is supported],pac_cv_fort_integer8,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*8 i])],
        pac_cv_fort_integer8=yes,
        pac_cv_fort_integer8=no)])
    AC_CACHE_CHECK([whether integer*16 is supported],pac_cv_fort_integer16,[
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[      integer*16 i])],
        pac_cv_fort_integer16=yes,
        pac_cv_fort_integer16=no)])

    F77=$saveF77
    AC_LANG_C
    # Determine Aint and Offset
    for len in 4 8 16 ; do
        eval testval=\$"pac_cv_fort_integer$len"
	if test "$testval" = no ; then continue ; fi
	testval=$len
        if test $len = "$MPI_SIZEOF_AINT" ; then
	    F77_MPI_ADDRESS="integer*$len"
        fi
        if test $len = "$MPI_SIZEOF_OFFSET" ; then
	    F77_MPI_OFFSET="integer*$len"
        fi
    done

    # Check for name mapping so that we can do the handle conversion tests
    # This test needs both the base c and fortran compilers
    saveF77=$F77
    saveCC=$CC
    if test -n "$BASECC" ; then 
        CC=$BASECC 
    fi	   
    if test -n "$BASEF77" ; then
        F77=$BASEF77
    fi	
    AC_LANG_FORTRAN77
    PAC_PROG_F77_NAME_MANGLE

    # Check whether we need -lU77 to get iargc and getarg, which 
    # are used for a few of the tests in spawn
    # FIXME: if we can't figure out how to get iargc/getarg, then 
    # we should really turn off those spawn tests
    AC_MSG_CHECKING([for Fortran libraries needed for getarg])
    AC_LINK_IFELSE([AC_LANG_PROGRAM(,[
        character*64 s
        integer i
        i = iargc()
        call getarg(i,s)])],
        pac_cv_getarg_needs_u77=no,
        pac_cv_getarg_needs_u77=unknown)
    if test "$pac_cv_getarg_needs_u77" != "no" ; then
        # Try again with -lU77
        saveLIBS="$LIBS"
        LIBS="$LIBS -lU77"
        AC_LINK_IFELSE([AC_LANG_PROGRAM(,[
        character*64 s
        integer i
        i = iargc()
        call getarg(i,s)])],
            pac_cv_getarg_needs_u77=yes,
            pac_cv_getarg_needs_u77=unavailable)
        LIBS="$saveLIBS"
        if test "$pac_cv_getarg_needs_u77" = "yes" ; then
            F77_GETARG_LIBS=-lU77
        fi
    fi
    if test -n "$F77_GETARG_LIBS" ; then
        AC_MSG_RESULT($F77_GETARG_LIBS)
    else
        if test "$pac_cv_getarg_needs_u77" = "unavailable" ; then 
	    AC_MSG_RESULT([getarg and/or iargc are not available.  Some spawn tests will fail to link])
	else 
            AC_MSG_RESULT([none needed])
        fi
    fi
    AC_SUBST(F77_GETARG_LIBS)
    # FIXME: Currently, we hope that F90 accepts the same library
    F90_GETARG_LIBS="$F77_GETARG_LIBS"
    AC_SUBST(F90_GETARG_LIBS)

    # ALLOCMEMF is set in f77/ext/testlist if we can try this
    # Fortran extension
    ALLOCMEMF=""
    PAC_PROG_F77_HAS_POINTER(ALLOCMEMF="allocmemf 1")
    AC_SUBST(ALLOCMEMF)
    # See the f90 block of code for the Fortran 90 version of
    # ALLOCMEMF

    # It is safe to now switch back to the "final" (MPI) compilers
    F77=$saveF77
    CC=$saveCC
fi
# Set a default for the Fortran 77 version of MPI_Offset.
if test -z "$F77_MPI_OFFSET" ; then
    F77_MPI_OFFSET="integer*8"
    AC_MSG_WARN([Selecting integer*8 as the Fortran type for MPI_Offset])
fi
AC_SUBST(F77_MPI_OFFSET)
# FIXME: Find a way to get the correct value
if test -z "$F77_MPI_ADDRESS" ; then
    F77_MPI_ADDRESS="integer"
    AC_MSG_WARN([Selecting integer as the Fortran type for MPI_Aint])
fi
AC_SUBST(F77_MPI_ADDRESS)

f90dir="#"
AC_SUBST(f90dir)
# First, see if we have an f90 compiler.  This uses code similar to that
# in the MPICH2 top-level configure
if test "$enable_f90" = default -a "$enable_f77" = yes ; then
    enable_f90=no
    if test -n "$BASEF90" ; then
        saveF90=$F90 
        F90=$BASEF90
    fi
    # Work around bug in autoconf that adds -g to F90FLAGS
    saveF90FLAGS="$F90FLAGS"
    PAC_PROG_F90
    PAC_PROG_F90_WORKS
    F90FLAGS=$saveF90FLAGS
    if test -z "$F90" -o "$pac_cv_prog_f90_works" != yes ; then
        AC_MSG_WARN([Use --disable-f90 to keep configure from searching for a Fortran 90 compiler])
	enable_f90=no
    elif test -z "$BASEF90" ; then
        BASEF90=$F90
    fi
    F90=$saveF90
fi

if test "$enable_f90" = yes ; then
    if test -n "$BASEF90" ; then
        saveF90=$F90 
        F90=$BASEF90
    fi
    # Work around bug in autoconf that adds -g to F90FLAGS
    saveF90FLAGS="$F90FLAGS"
    PAC_PROG_F90
    PAC_PROG_F90_WORKS
    F90FLAGS=$saveF90FLAGS

    if test -n "$F90" ; then
        # Make sure that the compilers are compatible.  This 
	# will also make sure that the program named in F90 is
	# a working Fortran 90 compiler
	# Only check if we're *not* building within MPICH2 
	# (MPICH2 will have made the test)
        # FIXME: Do we want to check only simple routine names 
	# (those without an underscore?)
	if test "$FROM_MPICH2" != yes ; then
            PAC_F90_AND_F77_COMPATIBLE(enable_f90=yes,enable_f90=no)
        fi
    fi
    if test -n "$F90" -a "$pac_cv_f90_ext" != "f90" ; then
        # The tests assume that .f90 works as the extension.  
        # The IBM xlf90 compiler needs a special option to accept f90
	AC_MSG_CHECKING([whether -qsuffix=f=f90 allows f90 suffix])
	saveF90FLAGS=$F90FLAGS
	F90FLAGS="$F90FLAGS -qsuffix=f=f90"
	rm -f conftest*
	cat >conftest.f90 <<EOF
       program main
       end
EOF
        if $F90 $F90FLAGS -o conftest conftest.f90 ; then
            pac_cv_f90_needs_qsuffix=yes
        else
            pac_cv_f90_needs_qsuffix=no
        fi
        rm -f conftest*
        AC_MSG_RESULT($pac_cv_f90_needs_qsuffix)
        if test "$pac_cv_f90_needs_qsuffix" != "yes" ; then
            F90FLAGS=$saveF90FLAGS;
            AC_MSG_WARN([Fortran 90 tests being disabled because the $F90 compiler does not accept a .f90 extension])
            f90dir=#
            enable_f90=no
        fi
    fi

    # See if the compiler supports the Cray-style pointers
    ALLOCMEMF90=""
    PAC_PROG_F90_HAS_POINTER(ALLOCMEMF90="allocmemf90 1")
    AC_SUBST(ALLOCMEMF90)

    if test -n "$BASEF90" ; then
        F90=$saveF90
    fi
fi
#
if test "$FROM_MPICH2" = yes ; then
    if test "$enable_f90" = yes ; then
        otherlangs="$otherlangs f90"
	f90dir=f90
    fi
elif test "$enable_f90" = yes ; then
    AC_MSG_CHECKING([that we can build MPI programs with Fortran 90])
    rm -f conftest*
    cat >conftest.f90 <<EOF
        program main
        use mpi
        integer ierr
	call mpi_init(ierr)
        call mpi_finalize(ierr)
        end
EOF
    if $F90 -o conftest conftest.f90 >conftest.out 2>&1 ; then
        AC_MSG_RESULT(yes)
        otherlangs="$otherlangs f90"
	f90dir=f90
    else
        AC_MSG_RESULT(no)
	echo "Failed to build program" >&AC_FD_CC
	cat conftest.f90 >&AC_FD_CC
        echo "Error messages:" >&AC_FD_CC
	cat conftest.out >&AC_FD_CC
    fi
    rm -f conftest*
fi
# Simple tests for which other languages we can handle
cxxdir="#"
AC_SUBST(cxxdir)
if test "$FROM_MPICH2" = yes ; then
    if test "$enable_cxx" = yes ; then
        otherlangs="$otherlangs cxx"
	cxxdir=cxx
    fi
elif test "$enable_cxx" = yes ; then
    AC_MSG_CHECKING([that we can build MPI programs with C++])
    rm -f conftest*
    cat >conftest.cxx <<EOF
#include "mpi.h"
int main( int argc, char **argv)
{
    MPI::Init();
    MPI::Finalize();
    return 0;
}    
EOF
    if $CXX -o conftest conftest.cxx >conftest.out 2>&1 ; then
        AC_MSG_RESULT(yes)
        otherlangs="$otherlangs cxx"
	cxxdir=cxx
    else
        AC_MSG_RESULT(no)
    fi
    rm -f conftest*
fi
if test "$enable_cxx" = yes ; then
    CXXsave=$CXX
    if test -n "$CXXTEST" ; then
        CXX=$CXXTEST
    fi
    AC_CACHE_CHECK([whether <iostream> available],pac_cv_cxx_has_iostream,[
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    AC_TRY_COMPILE([
#include <iostream>
],[using namespace std;],pac_cv_cxx_has_iostream=yes,pac_cv_cxx_has_iostream=no)])
    if test "$pac_cv_cxx_has_iostream" = yes ; then
        AC_DEFINE(HAVE_IOSTREAM,1,[Define if iostream is available])
    else
        # Look for iostream.h (in C++ mode, we need the full name)
        AC_CHECK_HEADERS(iostream.h)
        if test "$ac_cv_header_iostream_h" != yes ; then
            AC_MSG_ERROR([C++ compiler $CXX $CXXFLAGS has neither iostream nor iostream.h.])
        fi
        # Warning: the autoconf macros will fall back onto /lib/cpp for
        # C and C++ preprocessing *without* checking that /lib/cpp even
        # exists.  
        if test "$CXXCPP" = "/lib/cpp" ; then
            if test ! -x "/lib/cpp" ; then
                AC_MSG_WARN([Warning: Autoconf error, could not find a C++ Preprocessor.  Using false for the preprocessor so that tests will continue.])
                CXXCPP=false
            fi
        fi
    fi

    AC_CXX_NAMESPACE_STD
   
    if test "$ac_cv_cxx_namespaces" != yes ; then 
        AC_MSG_WARN([The compiler $CXX does not support C++ namespaces.  This may cause problems for the tests])
    fi
    CXX=$CXXsave
    AC_LANG_RESTORE
fi
# IO
iodir="#"
if test "$enable_romio" != no ; then
    iodir=io
    AC_DEFINE(HAVE_MPI_IO,1,[Define if MPI-IO (really ROMIO) is included])
fi
AC_SUBST(iodir)

# Find perl; used to create some of the tests from template and 
# defintion files
AC_PATH_PROG(PERL,perl)
AC_SUBST(PERL)
AC_SUBST(otherlangs)
AC_SUBST(threadsdir)
AC_SUBST(CC)
AC_SUBST(FC)
AC_SUBST(F90)
AC_SUBST(F90FLAGS)
AC_SUBST(FFLAGS)
AC_SUBST(CXX)
AC_SUBST(CXXFLAGS)
AC_SUBST(MPIEXEC)
AC_SUBST(MAKE)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
if test -z "$MPILIBNAME" ; then MPILIBNAME=mpich ; fi
AC_SUBST(MPILIBNAME)
dnl MPI_SOURCE may be set as an environment variable giving the location
dnl of the MPI implementation.  This is used only in runtests to include
dnl the location of the source of the MPI implementation into the XML
dnl summary file
AC_SUBST(MPI_SOURCE)

# Get the location of the CVS repository, if present
    # We can use this test (for CVS/Root) for creating maintainer targets
    # as well, and tests for maintainer-required software, such as 
    # doctext
if test -s CVS/Root ; then
    MPICVSHOME=`cat CVS/Root`
elif test -s "$srcdir/CVS/Root" ; then
    MPICVSHOME=`cat $srcdir/CVS/Root`
fi
AC_SUBST(MPICVSHOME)

dnl
dnl Etags
AC_CHECK_PROGS(ETAGS,etags,true)
AC_SUBST(ETAGS)
AC_SUBST(ETAGSADD)
export ETAGS
export ETAGSADD

AC_OUTPUT_COMMANDS([chmod a+x maint/testmerge])
AC_OUTPUT_COMMANDS([chmod a+x runtests])
AC_OUTPUT_COMMANDS([chmod a+x manual/manyconnect])
dnl Note that this format for AC_OUTPUT can cause problems for autoconf
dnl run under cygwin
AC_OUTPUT(maint/testmerge \
          runtests \
          Makefile \
          basic/Makefile \
	  attr/Makefile \
	  util/Makefile \
	  coll/Makefile \
	  comm/Makefile \
	  datatype/Makefile \
	  errhan/Makefile \
	  group/Makefile \
	  info/Makefile \
	  init/Makefile \
	  pt2pt/Makefile \
          rma/Makefile \
	  spawn/Makefile \
	  topo/Makefile \
	  io/Makefile \
	  f77/Makefile \
	  f77/attr/Makefile \
	  f77/attr/attraints.h \
	  f77/datatype/Makefile \
	  f77/datatype/typeaints.h \
	  f77/util/Makefile \
	  f77/coll/Makefile \
	  f77/comm/Makefile \
	  f77/topo/Makefile \
	  f77/init/Makefile \
	  f77/rma/addsize.h \
	  f77/pt2pt/Makefile \
	  f77/info/Makefile \
	  f77/spawn/Makefile \
	  f77/spawn/type1aint.h \
	  f77/rma/Makefile \
	  f77/ext/Makefile \
	  f77/ext/testlist \
          f77/io/Makefile \
	  f77/io/iooffset.h \
	  f77/io/iodisp.h \
	  f77/io/ioaint.h \
	  f90/Makefile \
	  f90/attr/Makefile \
	  f90/datatype/Makefile \
	  f90/util/Makefile \
	  f90/coll/Makefile \
	  f90/comm/Makefile \
	  f90/topo/Makefile \
	  f90/init/Makefile \
	  f90/pt2pt/Makefile \
	  f90/rma/Makefile \
	  f90/info/Makefile \
	  f90/spawn/Makefile \
	  f90/timer/Makefile \
	  f90/ext/Makefile \
	  f90/ext/testlist \
          f90/io/Makefile \
	  f90/misc/Makefile \
	  cxx/Makefile \
	  cxx/util/Makefile \
	  cxx/attr/Makefile \
	  cxx/comm/Makefile \
	  cxx/coll/Makefile \
          cxx/info/Makefile \
	  cxx/datatype/Makefile \
	  cxx/io/Makefile \
	  cxx/init/Makefile \
	  cxx/rma/Makefile \
	  cxx/spawn/Makefile \
	  threads/Makefile \
	  threads/pt2pt/Makefile \
	  threads/util/Makefile \
	  threads/comm/Makefile \
	  errors/Makefile \
	  errors/coll/Makefile \
	  errors/comm/Makefile \
	  errors/group/Makefile \
	  errors/pt2pt/Makefile \
	  errors/rma/Makefile \
	  errors/spawn/Makefile \
	  errors/io/Makefile \
	  errors/cxx/Makefile \
	  errors/cxx/errhan/Makefile \
	  errors/cxx/io/Makefile \
	  errors/f77/Makefile \
	  errors/f90/Makefile \
	  manual/Makefile \
	  manual/manyconnect \
	  perf/Makefile \
	  testlist \
	  cxx/testlist \
	  f77/testlist \
	  f90/testlist \
	  errors/testlist \
	  errors/cxx/testlist \
	  )
