#!/bin/sh
#
#  Creates preliminary Make.macros file. Before attempting to make anything
#  in this directory, enter
#
#   ./configure
#
#  !REVISION HISTORY
#
#  01dev00   da Silva   First FVGCM version adapted from PSAS.
#
#  022900    Mirin      Resultant file name = Make.macros_pre.
#
#  040500    Mirin      Name change to choose_makemacros.
#.....................................................................

c=`basename $0 .sh`

# Node > OS
# ---------------------------------------

# Node specific configuration
# ---------------------------------------
makeconf="cf/Make.macros.`uname -n | awk '{print $1}'`"

# Site specific configuration
# ---------------------------
if [ ! -r ${makeconf} ]; then
#  echo "$c: cannot find site specific ${makeconf}" 1>&2
  makeconf="cf/Make.macros.`uname -s | awk '{print $1}'`"
fi

# if the OS is UNICOS, it does not follow the convention
# ------------------------------------------------------
if [ ! -r ${makeconf} ]; then
# echo "$c: cannot find ${makeconf} in `pwd`" 1>&2
  mech="`uname -m | awk '{print $2}'`"
  if [ "${mech}" = J90 ]; then
    makeconf="cf/Make.macros.CRAY"
  elif [ "${mech}" = SV1 ]; then
    makeconf="cf/Make.macros.CRAY"
  elif [ "${mech}" = T3E ]; then
    makeconf="cf/Make.macros.CRAY_T3E"
  fi
fi

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

  makeconf="cf/Make.macros.unknown"
  if [ ! -r ${makeconf} ]; then
    #touch ${makeconf}
    exit 1
  fi
fi

rm -f Make.macros Make.macros_pre
ln -s ${makeconf} Make.macros_pre

echo "$c: using ${makeconf} in `pwd`" 1>&2

#.
