#!/bin/sh
#
#  Creates configuration Makefile. Before attempting to make anything
#  in this directory, enter
#
#   ./configure
#
#  !REVISION HISTORY
#
#  09oct97   da Silva   Initial code.
#  19oct97   da Silva   Simplified.
#  22oct97   Jing Guo	Converted to libpsas.a environment
#			- special configuration for CRAY
#			- fool-prove configuration
#			- additional information
#  25jun99   J. Larson  Added distinction between Cray T3E and
#                       other Cray (UNICOS) platforms.
#  19jan01   J. Larson  Added distinction for linux clusters of the
#                       i686 and alpha type.
#  15jul02   J. Larson  Added detection of Fujitsu vector platforms.
#            Also made script slightly more verbose.
#  26feb03   R. Jacob   Add distinction for linux ia64
#
#.....................................................................

c=`basename $0 .sh`

# Node > OS
# ---------------------------------------
# Some Set-up

  echo "Entered directory mpi0."

  OpSys="`uname -s | awk '{print $1}'`"
  Mach="`uname -m | awk '{print $1}'`"

  echo "Platform detection using uname:"
  echo "OpSys = " ${OpSys}
  echo "Mach = " ${Mach}

# Node specific configuration
# ---------------------------------------
makeconf="Makefile.conf.`uname -n | awk '{print $1}'`"

if [ ! -r ${makeconf} ]; then # No host-specific Make config.
  echo "$c: host-specific configuration not available, ${makeconf}" 1>&2
fi # closes if [ ! -r ${makeconf} ]; then...

# OS/chip specific configuration for commodity Linux clusters
# -----------------------------------------------------------
#
if [ ! -r ${makeconf} ]; then
  echo "$c: not available, ${makeconf}" 1>&2
  if [ "${OpSys}" = Linux ]; then
    if [ "${Mach}" = i686 ]; then
      makeconf="Makefile.conf.Linux-i686"
    fi
    if [ "${Mach}" = alpha ]; then
      makeconf="Makefile.conf.Linux-alpha"
    fi
    if [ "${Mach}" = ia64 ]; then
      makeconf="Makefile.conf.Linux-ia64"
    fi
  fi
fi #closes if [ ! -r ${makeconf} ]...Block for Linux clusters

# OS/chip specific configuration for Fujitsu Machines
# ---------------------------------------------------
#
if [ ! -r ${makeconf} ]; then
  if [ "${OpSys}" = UNIX_System_V ]; then # A Fujitsu?
    if [ "${Mach}" = F300 ]; then # Fujitsu VPP-300
      makeconf="Makefile.conf.Fujitsu-VPP"
    fi
    if [ "${Mach}" = 5000 ]; then # Fujitsu VPP-5000
      makeconf="Makefile.conf.Fujitsu-VPP"
    fi
  fi # closes if [ "${OpSys}" = UNIX_System_V ]; then...
fi # closes if [ ! -r ${makeconf} ]...Block to test for Fujitsu

# OS specific configuration
# ---------------------------------------
if [ ! -r ${makeconf} ]; then
  echo "$c: not available, ${makeconf}" 1>&2

  makeconf="Makefile.conf.`uname -s | awk '{print $1}'`"
fi

# if the OS is UNICOS, it does not follow the convention
# ---------------------------------------
if [ ! -r ${makeconf} ]; then
  echo "$c: not available, ${makeconf}" 1>&2

  mech="`uname -m | awk '{print $1}'`"
  if [ "${mech}" = CRAY ]; then
    model="`uname -m | awk '{print $2}'`"
    if [ "${model}" = T3E ]; then
       makeconf="Makefile.conf.T3E"
    else
       makeconf="Makefile.conf.UNICOS"
    fi
  fi
fi

# if all are failed, make a simple one
# ---------------------------------------
if [ ! -r ${makeconf} ]; then
  echo "$c: not available, ${makeconf}" 1>&2

  makeconf="Makefile.conf.unknown"
  if [ ! -r ${makeconf} ]; then
    touch ${makeconf}
  fi
fi

rm -f Makefile.conf
ln -s ${makeconf} Makefile.conf

echo "$c: Makefile.conf is ${makeconf}" 1>&2

#------------Finally, announce exit from the mpi0 directory.
echo "$c: Make configuration of mpi0 complete."
echo "$c: Exiting directory mpi0."

#.

