dnl This is an autoconf script.
dnl To rebuild the `configure' script from this, execute the command
dnl 	autoconf
dnl in the directory containing this script.  You must have autoconf
dnl version 1.x for x = 4 or later.
dnl
dnl The following text appears in the resulting `configure' script,
dnl explaining how to rebuild it.
[#!/bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically using autoconf.
# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

progname="`echo $0 | sed 's:^\./\./:\./:'`"
print_error() {
    echo "*# $*" 2>&1 ;
    }
print_usage () {
cat <<.
Usage: ${progname} [-arch=ARCH_TYPE]
                   [-prefix=INSTALL_DIR]  
          	   [-cc=C_COMPILER]
                   [-opt=OPTFLAGS] [-make=MAKEPGM]
where
   ARCH_TYPE    = the type of machine that wrappergen is to be configured for
   INSTALL_DIR  = directory where wrappergen will be installed (optional)
   OPTFLAGS     = optimization flags to give the compilers (e.g. -g)
   MAKEPGM      = version of make to use
                  
One and only one 'arch', and 'prefix' argument should be provided.

The option '-opt' allows you to specify options for the C compiler
For example, '-opt=-O' chooses optimized code generation on many
systems.

The option -make may be used to select an alternate make program.  For
example, on FreeBSD systems, -make=gnumake may be required because of bugs in
the system make.

Sample Configure Usage:

To make for running on sun4's running SunOS and with the installation 
directory equal to the current directory:

  ./configure -arch=sun4 
  make 

Known architectures include
                  sun4      (SUN OS 4.x)
                  solaris   (Solaris; probably 2.x)
                  hpux      (HP UX)
                  rs6000    (AIX for IBM RS6000)
                  sgi       (Silicon Graphics IRIX 5.x or 6.x)
                  IRIX      (synonym for sgi)
                  meiko     (Meiko CS2)
                  CRAY      (CRAY XMP, YMP, C90)

         
Others may be recognized.
.
}
# End of print_usage.
ARCH=""
LIB_PATH=""
OPTFLAGS="-g"
CFLAGS=""
MAKE=make
PREFIX=""
DEVCFLAGS=""
MYPWD=`pwd`
#
# Specific options
#
CONFIGURE_ARGS="$*"
echo "Configuring with args $CONFIGURE_ARGS"
#
for arg
do
  # Handle --exec-prefix with a space before the argument.
  if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix=
  # Handle --host with a space before the argument.
  elif test x$next_host = xyes; then next_host=
  # Handle --prefix with a space before the argument.
  elif test x$next_prefix = xyes; then prefix=$arg; next_prefix=
  # Handle --srcdir with a space before the argument.
  elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
  else
    case $arg in
     # For backward compatibility, also recognize exact --exec_prefix.
     -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*)
	exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
     -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e)
	next_exec_prefix=yes ;;

     -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
	PREFIX=`echo $arg | sed 's/[-a-z_]*=//'` ;;
     -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
	next_prefix=yes ;;

     -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*)
	srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
     -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s)
	next_srcdir=yes ;;

     -arch=* | --arch=*)
       package=`echo $arg|sed 's/-*arch=//'`
       # Delete all the valid chars; see if any are left.
       if test -n "`echo $package|sed 's/[-a-zA-Z0-9_]*//g'`"; then
         echo "configure: $package: invalid architecture name" >&2; exit 1
       fi
       ARCH=`echo $package|sed s/-/_/g`
       eval "arch_`echo $package|sed s/-/_/g`=1"
       ;;

     -cc=* | --cc=*)
	CC=`echo $arg|sed 's/-*cc=//'`
	USERCC=1
	;;

     -pwd=* | --pwd=*)
        MYPWD="`echo $arg|sed 's/-*pwd=//'`"
	;;

     -opt=* | --opt=*)
       package="`echo $arg|sed 's/-*opt=//'`"
       # Delete all the valid chars; see if any are left.
       OPTFLAGS=$package ;;

     -make=* | --make=*)
       package=`echo $arg|sed 's/-*make=//'`
       MAKE="$package"
	;;

     -debug )
        DEBUGFLAG="-DDEBUG"
	;;

     -echo )
	set -x
	;;

     -u | -usage | --usage | --usag | --usa | --us | --u | -help )
       print_usage >&2	
       exit 1 ;;

     -v | -verbose | --verbose | --verbos | --verbo | --verb | --ver | --ve | --v)
       verbose=yes ;;

     *) ;;
    esac
  fi
done]

dnl Finish the initalization
AC_PREPARE()
#
# record top-level directory (this one)
PAC_GETWD(WG_TRIAL,readproto.c)
WG_HOME=$WG_TRIAL
cd ../..
PAC_GETWD(MPIR_HOME,src/pt2pt/iprobe.c)
cd $WG_HOME
#
#
# If the "root" directories haven't been set, set them here using WG_HOME.
#
dnl Set Default values of variables
CC=${CC:-cc}
#
# First, check for the basic CC and Ranlib 
if test -z "$USERCC" ; then
    AC_PROG_CC()
fi
dnl AC_PROG_INSTALL
AC_PROG_RANLIB
CLINKER=$CC
AR="ar clr"
INCLUDE_PATH=""
#
# Fixup for make
PAC_MAKE_IS_GNUMAKE
PAC_MAKE_IS_BSD44
PAC_MAKE_IS_OSF
#
# Check that an ARCH was set
if test -z "$ARCH" ; then
    ARCH=`../../util/tarch`
    if test -z "$ARCH" ; then
        echo "You must set an architecture type with -arch=<value>"
        exit 1
    fi
    echo "Configuring for -arch=$ARCH"
fi
if test -n "$arch_sgi" ; then
    arch_IRIX=1
    ARCH=IRIX
fi

# 
# Check for Unix Variants
AC_AIX
AC_MINIX
#
# Get the compiler
CARCH=$ARCH
PAC_GET_CC($CARCH)

PAC_CHECK_COMPILER_OK(cc_works=1,cc_works=0)
if test $cc_works = 0 ; then
    print_error "Could not compile a simple file with $CC!"
    print_error "Check for license and path restrictions on $CC."
    exit 1
fi

#
# Get the defaults if they were not set...

if test -n "$arch_IRIX"; then
   # Every version and machine under IRIX is incompatible with every other
   # version.  This block of code replaces a generic "IRIX" arch value 
   # with 
   #  IRIX_<version>_<chip>
   #  For example
   #  IRIX_5_4400 (IRIX 5.x, using MIPS 4400)
   osversion=`uname -r | sed 's/\..*//'`
   cputype=`hinv -t cpu | cut -f 3 -d' '`
   echo "osversion and cputype"
   # cputype may contain R4400, R2000A/R3000, or something else.  
   # We may eventually need to look at it.
   if test -z "$osversion" ; then
	echo "Could not determine OS version (got $osversion).  Please send"
        echo " "
	uname -a
	echo "to gropp@mcs.anl.gov"
        exit 1
   elif test $osversion = 4 ; then
	echo "IRIX Version 4 is not supported.  Currently, IRIX 5.2 and"
	echo "IRIX 6.0 systems are available to us."
        exit 1
   elif test $osversion = 5 ; then
	true
   elif test $osversion = 6 ; then
	true
   else 
       echo "Could not recognize the version of IRIX (got $osversion)"
       echo "Wrappergen knows about versions 5 and 6; the version being"
       echo "returned from uname -r is $osversion."
       echo "Please send"
       uname -a
       hinv
       echo "to gropp@mcs.anl.gov"
       exit 1
   fi
   echo "getting cputype..."
   OLD_ARCH=IRIX
   IRIXARCH="$ARCH_$osversion"
   # Now, handle the chip set
   cputype=`echo $cputype | sed -e 's%.*/%%' -e 's/R//' | tr A-Za-z ''`
   case $cputype in 
	3000) ;;
	4000) ;;
	4400) ;;
	4600) ;;
	8000) ;;
        *)
	echo "Unexpected IRIX/MIPS chipset $cputype.  Please send the output"
        uname -a 2>&1
        hinv 2>&1
        echo "to gropp@mcs.anl.gov"
	echo "Wrappergen will contine and assume that the cputype is"
	echo "compatible with a MIPS 4400 processor."
        cputype=4400
	;;
   esac
   IRIXARCH="$IRIXARCH_$cputype"
   echo "IRIX-specific architecture is $IRIXARCH"
fi

# Check all of the devices first; they need to be known 
# (especially chameleon) before doing the transport layer

#
############################################################################
# In order to determine the correct compilers and options to use, 
# we sometimes need to get more detailed information on the system
# This is osversion, osvminor, and cputype.
# Currently, only IRIX uses this
############################################################################
PAC_GET_SPECIAL_SYSTEM_INFO

if test -n "$arch_IRIX"; then
   # We now have to look at  all sorts of things to determine the
   # various flags.  We need to set both the CFLAGS and various options
   # for the linkers (by setting CLINKER and FLINKER).
   # The OS version and chipset were determined above so that they could
   # be used to set the P4_ARCH if necessary.
   if test $osversion = 5 ; then
        # Turn off warnings about long doubles not being supported.
        CFLAGS="$CFLAGS -woff 728"
   elif test $osversion = 6 ; then
	if test $cputype = 8000 ; then
	    CLINKER="$CC -64 -mips4 -non_shared"
	    FLINKER="$F77 -64 -mips4 -non_shared"
        else
	    CLINKER="$CC -64 -mips3 -non_shared"
	    FLINKER="$F77 -64 -mips3 -non_shared"
        fi
        # Warning flags are > 1000
        CFLAGS="$CFLAGS -woff 1152,1174,1184"
   fi
   dnl AC_HAVE_ LIBRARY ( sun )
fi


if test -n "$arch_sun4" ; then
  if test "$STATIC_LINKING" = 1 ; then
      CLINKER="$CLINKER -Bstatic"
      FLINKER="$FLINKER -Bstatic"
  fi
fi
# 
if test -n "$arch_rs6000" ; then
  if test "$STATIC_LINKING" = 1 ; then
      CLINKER="xlc -bnso"
      FLINKER="xlf -bnso"
  fi
fi
cross_compiling=0
AC_CROSS_CHECK()
if test $cross_compiling != 0 ; then
    echo "Cross-compiling; many tests may not work..."
fi
# 

# Check for the functions that may be needed to implement
# Processor_name.  Save these defines in a special place.
AC_STDC_HEADERS
dnl
#
# Set the final choices of flags
if test -n "$DEBUGFLAG" ; then
    CFLAGS="$CFLAGS $DEBUGFLAG"
fi
CFLAGS="$CFLAGS $DEFS"
#
chmod g+w configure > /dev/null 2>&1
dnl Substitute variables
dnl Variables used by Makefile.in's:
AC_SUBST(ARCH)dnl
AC_SUBST(CC)dnl
AC_SUBST(CFLAGS)dnl
AC_SUBST(CLINKER)dnl
AC_SUBST(MAKE)dnl
AC_SUBST(MPIR_HOME)dnl
AC_SUBST(OPTFLAGS)dnl
dnl End configuration file
AC_OUTPUT(Makefile)dnl
