#!/bin/csh
# ************************************************************************
# *                                                                      *
# *   Configuration program for sotid.                                   *
# *                                                                      *
# *   This program will work recognizes operating systems:               *
# *   Linux -- it assumes Intel v 6.0 Fortran90/95 compiler;             *
# *   HP-UX -- it assumes HP Fortran90/95 compiler;                      *
# *   SunOS -- it assumes Sun Fortran90/95.                              *
# *                                                                      *
# *   It sets necessary options and compiles configuration program.      *
# *   Then it runs configuration program.                                *
# *                                                                      *
# *  ### 15-JUL-2002   configure   v1.0 (c)  L. Petrov  17-JUL-2002 ###  *
# *                                                                      *
# ************************************************************************
#
if ( -f sotid.cnf == 0 ) then
     echo "You should first create sotid.cnf file. Please read INSTALL"
     exit 1
endif
#
set CHECK = ./check_file.csh  
#
# --- Check whether we have all UNIX commands available
# 
$CHECK csh    command; if ( $status != 0 ) goto error
$CHECK f90    command; if ( $status != 0 ) goto error
$CHECK make   command; if ( $status != 0 ) goto error
$CHECK sed    command; if ( $status != 0 ) goto error
$CHECK sort   command; if ( $status != 0 ) goto error
echo " "
#
# --- Make a nominal update of Makefile: set flags for F90 compiler in
# --- accordance with the operating system
#
switch ( `uname` ) 
  case "Linux":
#
# --- NB: these are options for Intel compiler!
#
    echo "Your operating sustem is Linux"
    sed -e 's/FOPT    = @/FOPT    = -FR -w90 -cpp -Vaxlib/' Makefile.in > Makefile
    breaksw
  case "HP-UX":
    echo "Your operating sustem is HP-UX"
    sed -e 's/FOPT    = @/FOPT    = +source=free +check=all +cpp=yes -D HPUX/' Makefile.in > Makefile
    breaksw
  case "SunOS":
    echo "Your operating sustem is SunOS"
    sed -e 's/FOPT    = @/FOPT    = -free -e/' Makefile.in > Makefile
    breaksw
  default: 
    echo "Your operating system: `uname`"
    echo "Only Linux, HP-UX, SunOS are supported. Please edit Makefile manually"
    exit 1
endsw
echo " "
#
# --- Remove stale sotid_configure
#
if ( -f ./sotid_configure ) then
     rm -f ./sotid_configure 
endif 
if ( $1 == "only_make" ) exit ( 0 )
#
# --- Compile and link sotid_configure
#
make config;        if ( $status != 0 ) goto error
#
# --- Execute sotid_configure
#
./sotid_configure;  if ( $status != 0 ) goto error
echo " "
echo "configure -- successful completion"
echo " "
echo "Now, please, run make all"
echo " "
exit (0)
#
error:
echo "configure -- FAILURE in configuration checks"
exit 1
