#! /bin/sh

# Configuration script
# Peter G"untert, 24-02-1995


# System type

if [ $# = 1 ]; then
  system=$1
elif [ $# != 0 ]; then
  echo 'Usage: configure [<system-type>]'
  exit 1
else
  system=`(uname) 2>/dev/null`
  hosttype=${HOSTTYPE:-generic}
  system=${system:-$hosttype}
fi


# Base directory, program name, macro extension, version number

b=`pwd`
basedir=${PWD:-$b}
b=`basename $basedir`
program=`echo $b | awk -F- '{ print $1 }'`
if [ -f src/make$program.def ]; then 
  makeprogram=make$program
else
  makeprogram=none
fi
macext=`echo $b | awk -F- '{ printf(".%3.3s",$1) }'`
v=`echo $b | awk -F- '{ print $2 }'`
version=${v:-unknown}


# Generic parameters

stride=1
nrecl=1
timer="etime(tarray)"
iprec=1
shell=/bin/sh
fc=f77
fflags="-O"
cc=cc
cflags="-O"
cp="CC"
cpflags="-O"
ldflags=
libs=


# Machine-specific parameters

case $system in
SunOS | sun4 | sun)
  vers=`uname -r | awk -F. '{print $1}'`
  if [ $vers -le 4 ]; then system=Sun; else system=Solaris; fi
  nrecl=4;;
AIX | aix | ibm)
  system=AIX
  nrecl=4
  cp="xlC"
  timer="clock()*1.0E-6";;
IRIX | iris4d | iris | sgi)
  system=SGI;;
IRIX64)
  system=SGI64;;
HP-UX | hp9000s700 | hp)
  system=HP-UX
  nrecl=4
  timer="clock()*1.0E-6";;
ConvexOS | convex)
  system=Convex
  stride=7
  nrecl=4
  fc=fc
  cflags="-O2"
  cpflags="-O2"
  fflags="-O2";;
SUPER-UX | NEC | nec)
  system="NEC SX-3"
  stride=7
  fc=f77sx
  fflags="-pvctl vr128 nodivloop noloopchg nomsg";;
CRAY | cray | sn1522)
  system="Cray"
  stride=7
  nrecl=8
  fc=cf77
  fflags=-Zv
  timer="second()";;
GNU | gnu)
  system=GNU
  cc=gcc
  cflags="-O -g"
  cp=g++
  cpflags="-O -g"
  ldflags=-g;;
*)
  system=generic
  echo "Warning: Unknown system type. Generic parameters used.";;
esac
fflags2=$fflags
cflags2=$cflags
cpflags2=$cpflags
ldflags2=$ldflags
libs2=$libs


# Program-specific parameters

case $program in
prosa)
	case $system in
	"NEC SX-3")
	  fflags="-float1 -pvctl vr128 nodivloop noloopchg nomsg"
	  ldflags="-float1";;
	esac;;
diana | opal)
	case $system in
	Sun | Solaris)
	  fflags="$fflags -r8";;
 	AIX)
 	  fflags="$fflags -qautodbl=dblpad4"
          libs="-lxlfpmt4 -lxlfpad";;
	HP-UX)
	  fflags="$fflags -R8";;
	SGI)
	  fflags="$fflags -r8"
	  iprec=2;;
	Convex)
	  fflags="$fflags -p8";;
	esac;;
garant)
	case $system in
	Convex)
	  libs="-lF77 -lI77 -lm";;
	GNU)
	  ldflags="-g -static"
          libs="-L/usr/lang/SC1.0 -lF77 -lm -lg++";;
	Solaris)
          libs="-lM77 -lF77 -lm";;
	SGI)
          fflags="-g"
          libs="-lF77 -lm";;
	SGI64)
          fflags="-g -32"
          cflags="-O -32"
          cpflags="-O -32"
          ldflags="-32"
          libs="-lF77 -lftn -lm"
          cpflags2=$cpflags;;
	Sun)
	  ldflags="-Bstatic"
          libs="-lF77 -lm";;
	AIX)
	  fflags="-O -qextname"
          cpflags2=""
          libs="/usr/lpp/xlf/lib/lowsys.exp -lm -lxlf90";;
	esac;;
esac


# Create 'config.make'

(echo "MACHNAME    = $system"
 echo "PROGRAM     = $program"
 echo "MAKEPROGRAM = $makeprogram"
 echo "VERSION     = $version"
 echo "MACEXT      = $macext"
 echo "BASEDIR     = $basedir"
 echo "STRIDE      = $stride"
 echo "NRECL       = $nrecl"
 echo "IPREC       = $iprec"
 echo "TIMER       = $timer"
 echo "SHELL       = $shell"
 echo "FC          = $fc"
 echo "FFLAGS      = $fflags"
 echo "FFLAGS2     = $fflags2"
 echo "CC          = $cc"
 echo "CFLAGS      = $cflags"
 echo "CFLAGS2     = $cflags2"
 echo "C++         = $cp"
 echo "C++FLAGS    = $cpflags"
 echo "C++FLAGS2   = $cpflags2"
 echo "LDFLAGS     = $ldflags"
 echo "LDFLAGS2    = $ldflags2"
 echo "LIBS        = $libs"
 echo "LIBS2       = $libs2"
) > config.make


# List configuration

echo "Configuration:"
echo "System type       : $system"
echo "Program           : $program"
echo "Makeprogram       : $makeprogram"
echo "Version           : $version"
echo "Macro extension   : $macext"
echo "Base directory    : $basedir"
echo "Stride            : $stride"
echo "Record length unit: $nrecl per word"
echo "Integer length    : $iprec per real"
echo "Timing routine    : $timer"
echo "Bourne shell      : $shell"
echo "Fortran compiler  : $fc"
echo "Fortran options   : $fflags"
echo "Fortran options 2 : $fflags2"
echo "C compiler        : $cc"
echo "C options         : $cflags"
echo "C options 2       : $cflags2"
echo "C++ compiler      : $cp"
echo "C++ options       : $cpflags"
echo "C++ options 2     : $cpflags2"
echo "Linker options    : $ldflags"
echo "Linker options 2  : $ldflags2"
echo "Libraries         : $libs"
echo "Libraries 2       : $libs2"

