#! /bin/sh

# $Id: configure,v 1.101 2000/02/10 11:24:48 mdw Exp $

# This builds a configuration for CCP4 installation based on the value
# of an argument which is meant to describe a supported system.  On
# the basis of it we have to establish the necessary directories and
# build makefiles in the appropriate places from the skeletons in the
# master source area.  It's (obviously!) inspired by the GNU
# configuration scripts.

# The default values of the makefile variables (CC etc.) decided
# according to the system type, can be overridden by values defined in
# the environment or, in the case of the binary, library and master
# source directories, by optional arguments.  These variables are:
#   RANLIB, FC, XFFLAGS, CC, XCFLAGS, FOPTIM, COPTIM, LNS, M4,
#   SETFLAGS, MAKE, XLDFLAGS
# See below for an explanation of unconventional ones.

# We also check the supplied values of the environment variables which
# must be defined to run ccp4 (for path names etc.) and create the
# necessary directories if they don't already exist.  The following
# environment variables seem to be essential for *running* the code
# (as deduced from calls to `getenv' and `UGTENV'): BINSORT_SCR,
# CINCL, HOME, CCP4_OPEN, CLIBD, CCP4_SCR, CCP4_HELPDIR (used by
# mosflm), PUBLIC_FONT84

# A design aim is to be able to support different configurations
# painlessly by allowing building and subsequent installation to occur
# independently and in random directories.  The source is maintained
# in a master directory, probably shared over NFS.  For each system
# one can start with a clean directory in which this script is run
# with the system name and source directroy as arguments after setting
# the appropriate environment variables e.g.,
# configure convex --src=/nfs/dlpx1/home/xtal/ccp4 --bin=/priv9/pxbin
# This will make appropriate sub-directories in which everything can
# be built (with a simple `make' at the top level) and from which the
# programs can be run for test purposes.  `make install' will copy the
# results to the production directories for the appropriate system
# once it checks out OK.

# Fixme: check compiler and OS versions somehow against ones we're
# sure about...  (We should allow qualification of the system e.g.,
# sun-sunos4.1, and can arrange regexp matching in the cases.)  Can
# the OS be checked reliably? (uname?  not on alliant -- uv there?)

set -e 2>/dev/null    # not sure whether this still gives an
                                # error message with old sh... 

# Portability notes: the least common denominator so far is the convex
# (os8.1), which has a lousy make, a (version 7-based?) sh without
# functions or the ${foo:-bar} mechanism or a test with e.g., -x or
# set -e.  Use `test' rather than `[', by the way, since there are
# supposed to be systems without the latter.  Odd use of eval on
# variables like $usage is instead of using functions like the
# following (I guess these should just be inlined):


usage='echo "Usage: configure [--help] [--srcdir=DIR] [--bindir=DIR]
       [--libdir=DIR] [--onlylibs] [--tmpdir=DIR] [--with-f2c] 
       [--with-shared-lib] [--with-x] [--with-rxdispencer] [--disable-ccif] 
       SYSTEM";
  echo "where SYSTEM is one of:";
  echo "  irix irix64 convex sunos stardent titan aix hpux concentrix";
  echo "  ultrix esv osf1 linux freebsd linux_compaq_compilers generic";
  echo "Use uname -a to determine system type if you are unsure which to use.";
  exit 1'

### parse the arguments; `--' flags can be abbreviated and `=' can be
### replaced by whitespace

# these made null if not interested in building the src directory:
src=src ; dotsrc=./src ;
if test -d unsupported/src; then
  unsupp=unsupported/src; dotunsupp=./unsupported;
  dotunsuppsrc=./unsupported/src
else true
fi
if test -d x-windows; then
  xwindir=x-windows ; dotxwindir=./x-windows ;
else true
fi

for arg
do
  # Handle --bindir (etc.) with a space before the argument.
  if test x$next_bindir = xyes; then bindir=$arg; next_bindir=
  elif test x$next_libdir = xyes; then libdir=$arg; next_libdir=
  elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
  elif test x$next_tmpdir = xyes; then TMPDIR=$arg 
  else
    case $arg in
    -help | --help | -h | help)
      eval $usage;;

    -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=* | --b=*)
      bindir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
    -bindir | --bindir | --bindi | --bind | --bin | --bi | --b)
      next_bindir=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 ;;

    -libdir=* | --libdir=* | --libdi=* | --libd=* | --lib=* | --li=* | --l=*)
      libdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
    -libdir | --libdir | --libdi | --libd | --lib | --li | --l)
      next_libdir=yes ;;

    -onlylibs | --onlylibs | --onlylib | --onlyli | --onlyl | --onlyl | --only | \
      --onl | --on | --o)
      src= ; dotsrc= ; unsupp= ; dotunsupp= ; dotunsuppsrc= ;;

    -tmpdir=* | --tmpdir=* | --tmpdi=* | --tmpd=* | --tmp=* | --tm=* | t=*)
      tmpdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;

    -with-f2c | --with-f2c  | --with-f2  | --with-f)
      FC=fort77 ; XFFLAGS=${XFFLAGS-'-Nx400 -w'}; FOPTIM=${FOPTIM-"-O"}; with_f2c=1;\
      CC=cc ; AR='ar cru '; RANLIB='ranlib '; F=f;
      SETFLAGS=${SETFLAGS-""}
      ;;

    -with-shared-lib | --with-shared-lib | --with-shared-li | \
      --with-shared-l | --with-shared- | --with-share | --with-sha | \
      --with-sh | --with-s)
      shared_lib=yes
      ;;

    -with-x | --with-x | --wit-x | --wi-x | \
      --w-x)
      with_x=yes
      ;;

    -with-rxdispencer | --with-rxdispencer)
      with_rxdispencer=yes
      ;;

    -disable-ccif | --disable-ccif)
      disable_ccif=yes
      ;;

    -hush)      # only for use by config.status
      hush=1 ;;

    -*)
      eval $usage ;;

    *)
      if test -z "$system" ; then system=$arg
      else eval $usage ; fi ;;  # bad flag
    esac
  fi
done

test -z "$system" && eval $usage || true # system must be defined
srcdir=${srcdir-$PWD}
bindir=${bindir-$PWD/bin}
libdir=${libdir-$PWD/lib}
test "$tmpdir"  && TMPDIR=${tmpdir}

export libdir RANLIB FC FOPTIM COPTIM XFFLAGS XCFLAGS CC LNS M4 M4FLAGS
export SETFLAGS MAKE F INSTALL_PROGRAM INSTALL_DATA XLDFLAGS TMPDIR

### First let's check that we know about the system.

# Any new system must be added in the following case block and in
# the big one later which handles each possibility.  These try to be
# generic operating system names rather than names of hardware.

case $system in
  convex | concentrix | hpux | irix | irix64 | aix | stardent | sunos | \
    titan | ultrix | esv | osf1 | linux | freebsd | gnu_win32 | \
    linux_compaq_compilers | generic)
    echo "OK, setting up for a system type of \`$system'..."
    echo    ;;
  * )
    echo "! System type \`$system' isn't supported -- sorry."
    echo
    echo "If one of the following alternatives doesn't seem to be suitable,"
    echo "you'll have to modify \`configure' and the library files mentioned"
    echo "in the installation guide.  Please let ccp4@dl.ac.uk know of any"
    echo "changes you have to make:"
    echo "  irix irix64 convex sunos stardent titan aix hpux concentrix"
    echo "  ultrix esv osf1 linux linux_compaq_compilers freebsd generic"
    exit 1    ;;
esac

if test -n "$with_f2c"; then
  echo "! Using f2c compiler.  (Needs the \`fort77' perl script and f2c later than 19940920.)"
  echo "! Make sure there is no symbolic link from fort77 to g77"
  echo "! \`fort77' comes from, e.g. ftp://sunsite.unc.edu/pub/Linux/devel/lang/fortran"
  echo ""
elif test "$system" = linux; then
  echo "! Using g77 compiler.  If you have an old g77 compiler, you may be better"
  echo "! off using f2c, see --with-f2c option."
else true
fi
# check for xwin stuff
if test -n "$with_x"; then
  echo 
  echo " Will attempt to install the xwindows programs from \`$xwindir'."
  echo " This is not supported for all systems."
  echo "         ******** please note ************"
  echo " the xwindows programs will be compiled with an option"
  echo " that means errors are ignored. This could result in some"
  echo " xwindows programs not being compiled." 
else
  echo 
  echo "! The x-windows programs will not be installed."
  echo "! If you want the x-windows programs to be installed re-run"
  echo "! configure with the --with-x flag." 
fi
# check for disabling of ccif
if test -n "$disable_ccif"; then
  echo 
  echo " Installation of the CCIF library has been suppressed."
  echo " Some functionality will be lost."
else
  echo 
  echo " The CCIF library will be built and installed."
  echo " This has been tested on the most common systems, but if "
  echo " you have problems, use the --disable-ccif flag."
fi

### Check the values of the necessary environment variables

badvar=0      # set true if any of the checks fail

# fixme: do we need to check BINSORT_MEM?
for i in BINSORT_SCR CCP4_SCR CINCL CLIBD CCP4_OPEN PUBLIC_FONT84 \
  # BINSORT_MEM
do
  if eval test -z \"\$$i\" ; then
    echo "! Please set environment variable $i (see installation instructions)."
    badvar=1
  else true
  fi
done

test $badvar -eq 1 && exit 1 || true

### establish the necessary directories for building and installing
### and check that a scratch directory can be created

# shorthand for a warning needed in some cases:
# syswarn() {
#     echo
#     echo "! Beware -- the $system installation isn't properly tested." ; }
syswarn='echo; echo "! Beware -- the $system installation is not properly tested."'

for i in CCP4_SCR BINSORT_SCR; do
  if eval test -d \$$i || eval mkdir \$$i; then :
  else
    eval echo "! No directory \$$i and can\'t create it."
    echo "  Check the value of $i."
    badvar=1
  fi
done

for i in libdir bindir; do
  if eval test -d \$$i || eval mkdir \$$i; then :
  else
    eval echo "! No directory \$$i and can\'t create it."
    echo "  Check the argument of --$i."
    badvar=1
  fi
done

for i in $dotsrc $dotunsupp $dotunsuppsrc ./lib ./lib/src ./lib/data; do
  if test -d $i || mkdir $i; then :
  else
    eval echo "! No directory $i and can\'t create it."
    badvar=1
  fi
done

### sanity checks

badvar=0
if test ! -f $srcdir/lib/src/ccplib.f ; then
  echo "! $srcdir/lib/src/ccplib.f doesn't exist."
  echo "  Check the value of the --srcdir flag."
  badvar=1
else true
fi

if touch $BINSORT_SCR/binsort$$ ; then
  rm $BINSORT_SCR/binsort$$
else
  echo "! Can't create $BINSORT_SCR/binsort$$."
  echo "  Check the value of BINSORT_SCR."
  badvar=1
fi

test $badvar -eq 1 && exit 1 || true

### Do specific things for each possible system.  Note we preserve any
### supplied values of the variables with the ${...-...} mechanism.

if test ! "$hush" ; then
  if test "${FC}" && test -z "$with_f2c"; then
    echo "! You have specified a non-default Fortran compiler ($FC)."
    echo "  This probably only makes sense if you have made the appropriate"
    echo "  changes to the Fortran-C interface routines."
  else true
  fi
else true
fi

LDFLAG='-L$(LIB_DIR)'   # overridden only for alliant

### To add a new system, see the explanation of variables below

case $system in
irix)     # tested in 4.0.{1,5}, probably ok in 3.3
  RANLIB=${RANLIB-:}
  test "$with_f2c" && M4="m4 -D_f2c=1"
  # fixme: this ought to test the *compiler* version (using `versions')
  case `uname -rs` in
  IRIX\ 4.0*)
  # more nested loops (?), optimise larger routines, use shared
  # libraries -- no provision for parallelisation, try to trap
  # undefined variables, don't want to waste time with cpp
# fixme: -trapuv causing havoc due to undefined variables -- should be
# put back after fixing as many as poss.
#    XFFLAGS=${XFFLAGS-"-Nc45 -Olimit 1500 -share_all -trapuv -nocpp"}
    XFFLAGS=${XFFLAGS-"-Olimit 1500 -nocpp"}
    XLDFLAGS=${XLDFLAGS-"-lfpe"} # to enable floating point traps
    # -Nq for `too many equivalences' (??)
    SETFLAGS=${SETFLAGS-"amore_FLAGS='-O1 -Nq2500 -nocpp'"}
#   Xwindows variables set if wanted or not!
    XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
    XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
    XTYPE=${XTYPE-"IRIX_4"}
  ;;
  IRIX\ 5.*)
    # apparently this is OK for the new SysVile.4-based OS (but don't
    # try to share irix4 libraries, at least)
    XFFLAGS=${XFFLAGS-"-Olimit 1500 -nocpp -w -Wf,-I${srcdir}/lib/src"}
    XCFLAGS=${XCFLAGS-"-DPROTOTYPE -w"}
    FOPTIM=${FOPTIM-"-O2"}
    XLDFLAGS=${XLDFLAGS-"-lfpe"} # to enable floating point traps
    # Xwindows variables set if wanted or not!
    XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
    XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
    XTYPE=${XTYPE-"IRIX_5"}
    # -Nq for `too many equivalences' (??)
    # sopt was broken in v4.  You might think it would help here, but it's
    # a loss, for some reason
    SETFLAGS=${SETFLAGS-"amore_FLAGS='-O1 -Nq2500 -nocpp' \
                sftools_FLAGS='$XFFLAGS $FOPTIM -Nq3000 -backslash' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static'"}
    # we need to worry about rewinding scratch files with 5.1 fortran
    # (and apparently also with 5.2):
    M4=${M4-"m4 -D_sgi=1 -D_irix51=1"}
    if test "$shared_lib" = yes; then
      SHARE_LIB=${SHARE_LIB-'ld -shared -all libccp4.a -o libccp4.so'}
      SHARE_INST='$(INSTALL_DATA) `pwd`/libccp4.so $(libdir)/libccp4.so'
    fi
    case `uname -sr` in
    IRIX\ 5.1*)
      echo "! Beware -- f77 in Irix5.1 is supposed to be badly broken"
      ;;
    esac
    ;;
  IRIX64\ 6.*|IRIX\ 6.*)
    echo "* SGI machines with IRIX6.* can run either 32 or"
    echo "* 64-bit compiled programs."
    echo "* With the system option irix the code will compile under "
    echo "* the -32 (therefore 32 bit) option."
    echo "* For R2000/R3000 you may need to add -mips1."
    echo "* If you have IRIX 6.3 or above and want to try the 64 bit"
    echo "* compilation run configure again with the system choice irix64."
    echo "* This is not tested on systems running irix6.2 or below."
    echo 
#   Example for compiling code with -64 option. I believe this is currently
#   only appropriate for R8000s and R10000s. Also, notice that the options 
#   are different from those when using -32. The C and F flags are given 
#   below and others remain the same. Also, if you are using shared libraries 
#   then you need to alter $SHARE_LIB. Perhaps better performance can be 
#   gained with additional optimisations but code integrity is not 
#   guaranteed. Adam 21/01/97.
#XFFLAGS=${XFFLAGS-"-64 -mips4 -r10000 -nocpp -TENV:trapuv=ON -OPT:Olimit=1500 -w"}
#XCFLAGS=${XCFLAGS-"-64 -mips4 -r10000 -trapuv -DPROTOTYPE -w"}
#SHARE_LIB=${SHARE_LIB-"ld -64 -mips4 -shared -all libccp4.a -o libccp4.so"}
#
    case `uname -sr` in
    IRIX64\ 6.0*|IRIX\ 6.0*)
      # This is said to work on unknown Irix6 minor version by
      # george@tusk.med.harvard.edu (George Planansky)
      XFFLAGS=${XFFLAGS-"-32 -nocpp"}
      XCFLAGS=${XCFLAGS-"-32 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-"-lfpe"}
      FOPTIM=${FOPTIM-"-O2"}
      # -Nq still needed in 6.01, apparently, but not later versions.
      SETFLAGS=${SETFLAGS-"amore_FLAGS='$XFFLAGS -Nq2500' \
                sftools_FLAGS='$XFFLAGS $FOPTIM -Olimit 1250 -Nq3000 -backslash' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static'"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.1*|IRIX\ 6.1*)
      # -lfpe no longer exists - replacement sought.
      # tnearnest@LBL.Gov (Thomas Earnest) following SGI rep. says for 6.1:
      # Heaven knows how you're supposed to trap FPEs...
      XFFLAGS=${XFFLAGS-"-32 -nocpp "}
      XCFLAGS=${XCFLAGS-"-32 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      # Or use -O3 for agressive optimisation.
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.2*|IRIX\ 6.2*)
      XFFLAGS=${XFFLAGS-"-32 -w -nocpp"}
      XCFLAGS=${XCFLAGS-"-32 -w -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-"-lfpe"}
      # Or use -O3 for agressive optimisation.
      FOPTIM=${FOPTIM-"-O2 -Olimit 3000"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.3*|IRIX\ 6.3*)
      # e.g. O2's
      XFFLAGS=${XFFLAGS-"-32 -w -nocpp"}
      XCFLAGS=${XCFLAGS-"-32 -w -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.4*|IRIX\ 6.4*)
      # e.g. Origin200
      XFFLAGS=${XFFLAGS-"-32 -w -nocpp"}
      XCFLAGS=${XCFLAGS-"-32 -w -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6_4"}
      ;;
    IRIX64\ 6.5*|IRIX\ 6.5*)
      XFFLAGS=${XFFLAGS-"-32 -w -nocpp"}
      XCFLAGS=${XCFLAGS-"-32 -w -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6_5"}
      ;;
    *)
      XFFLAGS=${XFFLAGS-"-32 -w -nocpp"}
      XCFLAGS=${XCFLAGS-"-32 -w -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_5"}
      ;;
    esac
    SETFLAGS=${SETFLAGS-"sftools_FLAGS='$XFFLAGS $FOPTIM -Olimit 1250 -Nq3000 -backslash' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static'"}
    M4=${M4-"m4 -D_sgi=1 -D_irix51=1"}
    SHARED_LIB_FLAGS=${SHARED_LIB_FLAGS-'-32'}
    if test "$shared_lib" = yes; then
      SHARE_LIB=${SHARE_LIB-'ld -32 -shared -all libccp4.a -o libccp4.so'}
      SHARE_INST='$(INSTALL_DATA) `pwd`/libccp4.so $(libdir)/libccp4.so'
    fi
    ;; 
  IRIX*)
    XFFLAGS=${XFFLAGS-"-32 -Olimit 1500  -nocpp"}
    XLDFLAGS=${XLDFLAGS-"-lfpe"} # to enable floating point traps
    # Xwindows variables set if wanted or not!
    XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
    XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
    XTYPE=${XTYPE-"IRIX_6_5"}
    echo "! Beware -- this is a substantially different OS version to those tested"
    ;;
  *)
     echo "! This doesn't appear to be an IRIX system.
  you should run configure on a machine of the correct type."
     exit 1 ;;
  esac
  # Each version of the irix compiler seems to bring a different set
  # of optimisation problems, some of which we probably never find out
  # about.  The default optimisation seems to be the best thing to go
  # with.  Maybe you can win in some cases by using -O2, caveat emptor...
  FOPTIM=${FOPTIM-""}
  M4=${M4-"m4 -D_sgi=1"}
  ;;
irix64)     
# new option added to allow users to have 64bit compilatioins.
  RANLIB=${RANLIB-:}
  test "$with_f2c" && M4="m4 -D_f2c=1"
  # fixme: this ought to test the *compiler* version (using `versions')
  case `uname -rs` in  IRIX64\ 6.*|IRIX\ 6.*)
    echo "* IRIX6.* can run on 32 or 64-bit machines."
    echo "* You have chosen to compile the suite as 64 bit code. "
    echo "* 32 bit SGI machines will not be able to run 64 bit programs."
    echo "* The 64 bit compilation is relativley untested especially on "
    echo "* irix6.2 and below."
    echo "* Please report problems or changes to ccp4@dl.ac.uk."
#
# Below is the origional suggestion by Adam in 1997
#
#   Example for compiling code with -64 option. I believe this is currently
#   only appropriate for R8000s and R10000s. Also, notice that the options 
#   are different from those when using -32. The C and F flags are given 
#   below and others remain the same. Also, if you are using shared libraries 
#   then you need to alter $SHARE_LIB. Perhaps better performance can be 
#   gained with additional optimisations but code integrity is not 
#   guaranteed. Adam 21/01/97.
#XFFLAGS=${XFFLAGS-"-64 -mips4 -r10000 -nocpp -TENV:trapuv=ON -OPT:Olimit=1500 -w"}
#XCFLAGS=${XCFLAGS-"-64 -mips4 -r10000 -trapuv -DPROTOTYPE -w"}
#SHARE_LIB=${SHARE_LIB-"ld -64 -mips4 -shared -all libccp4.a -o libccp4.so"}
#
# 02-02-00: replacing mips4 with mips3 ... this might mean some loss of
# performance for some systems, but will result in more portable executable code.
    case `uname -sr` in
    IRIX64\ 6.0*|IRIX\ 6.0*)
      # This is said to work on unknown Irix6 minor version by
      # george@tusk.med.harvard.edu (George Planansky)
      echo "\n* Warning this option is not tested *\n"
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-"-lfpe"}
      FOPTIM=${FOPTIM-"-O2"}
      # -Nq still needed in 6.01, apparently, but not later versions.
      SETFLAGS=${SETFLAGS-"amore_FLAGS='$XFFLAGS' \
                sftools_FLAGS='$XFFLAGS $FOPTIM -OPT:Olimit=1250 -backslash' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static'"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.1*|IRIX\ 6.1*)
      # -lfpe no longer exists - replacement sought.
      # tnearnest@LBL.Gov (Thomas Earnest) following SGI rep. says for 6.1:
      # Heaven knows how you're supposed to trap FPEs...
      echo "\n* Warning this option is not tested *\n"
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.2*|IRIX\ 6.2*)
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-"-lfpe"}
      # Or use -O3 for agressive optimisation.
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.3*|IRIX\ 6.3*)
      # e.g. O2's
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.4*|IRIX\ 6.4*)
      # e.g. Origin200
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-"-lfpe"}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    IRIX64\ 6.5*|IRIX\ 6.5*)
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6_5"}
      ;;
    *)
      XFFLAGS=${XFFLAGS-"-64 -mips3 -nocpp -OPT:Olimit=1500 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE"}
      XLDFLAGS=${XLDFLAGS-""}
      FOPTIM=${FOPTIM-"-O2"}
      # Xwindows variables set if wanted or not!
      XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
      XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
      XTYPE=${XTYPE-"IRIX_6"}
      ;;
    esac
    SETFLAGS=${SETFLAGS-"sftools_FLAGS='$XFFLAGS $FOPTIM -Olimit 1250 -Nq3000 -backslash' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static'"}
    M4=${M4-"m4 -D_sgi=1 -D_irix51=1"}
    SHARED_LIB_FLAGS=${SHARED_LIB_FLAGS-'-64'}
    if test "$shared_lib" = yes; then
      SHARE_LIB=${SHARE_LIB-'ld -64 -mips3 -shared -all libccp4.a -o libccp4.so'}
      SHARE_INST='$(INSTALL_DATA) `pwd`/libccp4.so $(libdir)/libccp4.so'
    fi
    ;; 
  IRIX64*)
    XFFLAGS=${XFFLAGS-"-OPT:Olimit=1500 1500  -nocpp"}
    XLDFLAGS=${XLDFLAGS-"-lfpe"} # to enable floating point traps
    # Xwindows variables set if wanted or not!
    XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
    XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
    XTYPE=${XTYPE-"IRIX_6_5"}
    echo "! Beware -- this is a substantially different OS version to those tested"
    ;;
  *)
     echo "! This doesn't appear to be an IRIX64 system."
     echo "! you should run configure on a machine of the correct type."
     exit 1 ;;
  esac
  # Each version of the irix compiler seems to bring a different set
  # of optimisation problems, some of which we probably never find out
  # about.  The default optimisation seems to be the best thing to go
  # with.  Maybe you can win in some cases by using -O2, caveat emptor...
  FOPTIM=${FOPTIM-""}
  M4=${M4-"m4 -D_sgi=1"}
  ;;
esv)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  # first make sure we have the BSD stuff e.g. `which' on the path
  # (might it ever be missing?)
  PATH=/bsd43/bin:/usr/ucb:$PATH
  # similar to irix (from LMB):
  case `uname -rv` in
  2.3\ UMIPS)
    ;;
  *UMIPS)
    echo "! Beware -- this is a substantially different OS version to those tested";;
  *)
    echo "! This doesn't appear to be an ESV system.
  you should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  case `what \`which f77\`` in
  *ES/os\ 2.2alpha)
    XFFLAGS=${XFFLAGS-"-systype bsd43 -Nc45 -nocpp -Olimit 1500"}
    # uopt fails:
    SETFLAGS=${SETFLAGS-"ecalc_FLAGS='-systype bsd43' \
      tffc_FLAGS='-systype bsd43' fhscal_FLAGS='-systype bsd43' \
      amore_FLAGS='-systype bsd43 -O0'"}
    # there are posix headers in /usr/include/posix, but the BSD fcntl
    # gets included as well as the posix one and there is a clash,
    # causing a fatal error.  thus use NOUNISTD to avoid unistd.h in library.c 
    XCFLAGS=${XCFLAGS-"-systype bsd43 -DESV -DNOUNISTD"} # use BSD universe (a la LMB)
    ;;
  *)
# fixme: -trapuv as for IRIX
#    XFFLAGS=${XFFLAGS-"-Nc45 -trapuv -nocpp -Olimit 1500"} ;;
    XFFLAGS=${XFFLAGS-"-Nc45 -nocpp -Olimit 1500"} ;;
  esac
  FOPTIM=${FOPTIM-"-O2"}
  XCFLAGS=${XCFLAGS-"-systype bsd43 -DESV -DNOUNISTD"} # use BSD universe (a la LMB)
  test "$with_f2c" && M4="m4 -D_f2c=1"
  M4=${M4-"m4 -D_esv=1"}    # `-s' breaks fsplit, sigh
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"/bsd43/bin/install -c"}
  INSTALL_DATA=${INSTALL_DATA-"/bsd43/bin/install -m 644 -c"}
  ;;
stardent | titan)  # from aberg@titan.embl-grenoble.fr (Anders Aberg)
                   # on `TitanOS 4.2 P1'
                   # Update from tax@titan.embl-grenoble.fr (Takemasa KAWASHIMA)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  case `uname -sr` in
  "TitanOS 4") ;;
  "TitanOS")
    echo "! Beware -- this is a substantially different OS version to those tested";;
  *)
     echo "! This doesn't appear to be a Titan system.
  You should run configure on a machine of the correct type."
  esac
  FC=${FC-f77}
  XFFLAGS=${XFFLAGS-"-continuations=50 -w"} # -w suppresses warnings
  FOPTIM=${FOPTIM-"-O2"} # vectorisation
  RANLIB=${RANLIB-":"}
  XCFLAGS=${XCFLAGS-"-DNOSTDLIB"}
  test "$with_f2c" && M4="m4 -D_f2c=1" || true
  M4=${M4-"m4 -D_titan=1"}
  echo; echo "! Beware -- the $system installation is not tested."
  ;;    
aix)              # (tested in AIX 3.2, xlf v2.2 (?) but can't
                # find a way to get the compiler version)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  FC=${FC-xlf}
  case `uname -vrs` in
  "AIX 2 3") ;;         # 3.2, not 2.3
  AIX*)
    echo "! Beware -- this is a substantially different OS version to those tested";;
  *)
     echo "! This doesn't appear to be an AIX system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  # avoid truncation to character*500 and ensure that the default
  # handling of external names is in force (no postfixed `_') and use
  # larger internal table sizes
  XFFLAGS=${XFFLAGS-"-qcharlen=4000 -qnoextname -NQ20000 -NT40000"}
  FOPTIM=${FOPTIM-"-O"}
  test "$with_f2c" && M4="m4 -D_f2c=1"
  M4=${M4-"m4 -D_AIX=1"}
  SETFLAGS=${SETFLAGS-"amore_FLAGS='$XFFLAGS $LDFLAGS' tracer_FLAGS='$XFFLAGS' \
                       fftbig_FLAGS='$XFFLAGS $FOPTIM -qintlog'"}
  # this seems not to be exactly BSD install, but looks OK to use:
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/ucb/install -c"}
  INSTALL_DATA=${INSTALL_DATA-"/usr/ucb/install -m 644 -c"}
  # echo; echo "! Beware -- the $system installation is not fully tested."
  ;;
concentrix)     # tested under v 2.2.00 on 2800 system
  # fixme: what other breeds of Alliant are there?
  # from LMB (for concentrix 2.2)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  case `uv|head -1` in
  *Alliant\ Concentrix\ 2800\ 2.2*)
    CFLAGS=${CFLAGS-"-Dconcentrix2 -DNOUNISTD"} ;;
  *Alliant\ Concentrix\ 2800\ 2.*)
    CFLAGS=${CFLAGS-"-Dconcentrix2 -DNOUNISTD"}
    echo "! Beware -- this is a substantially different OS version to those tested";;
  # beware the tabs in this!
  *Alliant*Concentrix\ 2800*3*) ;; # now has posix.1
  *Concentrix*)
    echo "! Beware -- this is a substantially different OS version to those tested";;
  *)
     echo "! This doesn't appear to be a Concentrix system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  # `fortran -v 2>&1|head -1` = fortran , version 1.3.0
  FC=${FC-fortran}
  CC=${CC-scc}      # scalar version (default?)
  CFLAGS=${CFLAGS-"-uniproc"}
  XCFLAGS=${XCFLAGS-"-uniproc"}
  COPTIM=${COPTIM-"-Og"}
  XFFLAGS=${XFFLAGS-"-uniproc"}
  # -ieee only on polarrfn (speed), procheck programs must be -save
  SETFLAGS=${SETFLAGS-"almn_FLAGS='-uniproc' scaleit_FLAGS='-uniproc -ieee'\
    vecref_FLAGS='-uniproc -ieee' polarrfn_FLAGS='-uniproc -ieee'\
    anglen_FLAGS='-uniproc -save' secstr_FLAGS='-uniproc -save' \
    proclean_FLAGS='-uniproc -save' pplot_FLAGS='-uniproc -save'"}
  FOPTIM=${FOPTIM-"-Og"}
  LDFLAG=     # have to use LD_PATH instead, sigh
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/bin/install -c"}
  INSTALL_DATA=${INSTALL_DATA-"/usr/bin/install -m 644 -c"}
  ;;
convex)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  # for os8.1 (fc 6.1) originally, also tried on 10.0 (fc 7.0)
  case `vers /vmunix` in
  /vmunix:\ 8.*)
    XFFLAGS=${XFFLAGS-"-or none"}
    MAKE=${MAKE-make}   # old Convex make doesn't set it
    ;;
  /vmunix:\ 10.*)
    # IJT says -noptst to fit in 600 megs VM!
    XFFLAGS=${XFFLAGS-"-noptst -or none"}
  ;;
  /vmunix:*) 
    XFFLAGS=${XFFLAGS-"-or none"}
    echo "! Beware -- this is a substantially different OS version to those tested";;
  *)
     echo "! This doesn't appear to be a Convex system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  FC=${FC-fc}
  FOPTIM=${FOPTIM-"-O2"}  # vectorisation
  M4=${M4-"m4 defs.m4"}
  if test "$with_f2c"; then echo 'define(_f2c,1)dnl' > lib/src/defs.m4
  else echo 'define(_convex,1)dnl' > lib/src/defs.m4
  fi
  # convex ar won't create the archive with `ar r':
  ar cq lib/src/libccp4.a
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/bin/install -c"}
  INSTALL_DATA=${INSTALL_DATA-"/usr/bin/install -m 644 -c"}
  ;;
sunos)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  # for os4.1, f771.4, at least
  case `uname -rs` in
  SunOS\ 4.1*)
    test "$with_f2c" && M4="/usr/5bin/m4 -D_f2c=1"
    M4=${M4-"/usr/5bin/m4 -D_sun=1"} # SysVile version
    INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/bin/install -c"}
    INSTALL_DATA=${INSTALL_DATA-"/usr/bin/install -m 644 -c"}
    XTYPE=${XTYPE-"SUNOS_4"}
    if test -z "$CC"; then
      # Look for an ANSI C compiler
      case `type acc` in
        *acc)
          CC=acc;;
        *)
          case `type gcc` in
          *gcc)
            CC=gcc;;
          *)
            echo "! Can't find GCC or the SunPro compiler."
            echo "! The default \`cc' won't compile \`solomon' or the XCCPJIFFY stuff."
          esac;;
      esac
    fi
    ;;
  SunOS\ 5*)
    test "$with_f2c" && M4="m4 -D_f2c=1"
    M4=${M4-"m4 -D_sun=1"} # (presumably)
    RANLIB=${RANLIB-:}    # I know this much
    INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/ucb/install -c"}
    INSTALL_DATA=${INSTALL_DATA-"/usr/ucb/install -m 644 -c"}
    XTYPE=${XTYPE-"SUNOS_5"}
    if [ "$shared_lib" = yes ]; then
      XFFLAGS=${XFFLAGS-"-Nl45 -pic"}
      XCFLAGS=${XCFLAGS-"-pic"}
      if test "$shared_lib" = yes; then
        SHARE_LIB=${SHARE_LIB-'ld -dy -G -z text -o libccp4.so libccp4.a'}
        SHARE_INST='$(INSTALL_DATA) `pwd`/libccp4.so $(libdir)/libccp4.so'
      fi
    fi
    echo "! Beware -- the SunOS5 installation is not well tested";;
  SunOS*)
    test "$with_f2c" && M4="/usr/5bin/m4 -D_f2c=1"
    M4=${M4-"/usr/5bin/m4 -D_sun=1"} # SysVile version
    echo "! Beware -- this is a substantially different OS version to those tested";;
  *)
     echo "! This doesn't appear to be a SunOS system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  FOPTIM=${FOPTIM-"-O3"}  # -fast is a possibility
  XFFLAGS=${XFFLAGS-"-Nl45"}  # more continuation lines (until
        # problems removed)
  SETFLAGS=${SETFLAGS-"amore_FLAGS='$XCFLAGS\ $LDFLAGS\ -O1'"}
  ;;
hpux)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  case `uname -sr` in
  HP-UX\ A.08.*)  # uname -a: HP-UX tcs-hp0 A.08.07 A 9000/750 2002285682
    XLDFLAGS=${XLDFLAGS-"-lfsys -lm"} # access to routines f77<C name>
                                      # -lm for solomon
    XFFLAGS=${XFFLAGS-"+T +E1"} # +T is trap signals, +E1 gets access to
                # IDATE etc
    M4=${M4-"m4 -D_hpux=1"}
    SETFLAGS=${SETFLAGS-"prepform_FLAGS='$XFFLAGS' \
                         arp_warp_FLAGS='$XFFLAGS $FOPTIM -C'"} # exclude optimisation
  ;;
  HP-UX\ A.09.*)  # uname -a: HP-UX tcs-hp0 A.09.01 A 9000/755 2002285682 two-user license
  # floating point traps and access to routines f77<C name>
    XLDFLAGS=${XLDFLAGS-"+FPVZO -lfsys -lm"}
    # Note that this is the documented way to get IDATE, and gives you the
    # usual unix variant.  I think in HPUX8, +E1 was OK.  We need a new flag
    # to know whether to use SECNDS or not, at least, since we don't seem to
    # be able to get both E1 and U77.
    # -lm for solomon
    XFFLAGS=${XFFLAGS-"+U77 -w"} # access to IDATE etc
    XCFLAGS=${XCFLAGS-"-w"}
    M4=${M4-"m4 -D_hpux=1 -D_hpux9=1"}
    SETFLAGS=${SETFLAGS-"prepform_FLAGS='$XFFLAGS' \
                         arp_warp_FLAGS='$XFFLAGS $FOPTIM -C'"} # exclude optimisation
  ;;
  HP-UX\ B.10.*)
# Thanks to Morten Kjeldgaard <mok@beast.imsb.au.dk>
    XLDFLAGS=${XLDFLAGS-"+FPVZO -lfsys -lm"}
    FOPTIM=${FOPTIM-"-O2"}
    XFFLAGS=${XFFLAGS-"+U77 -w"} # access to IDATE etc
    XCFLAGS=${XCFLAGS-"-w"}
    M4=${M4-"m4 -D_hpux=1 -D_hpux10=1"}
    SETFLAGS=${SETFLAGS-"prepform_FLAGS='$XFFLAGS' \
                         arp_warp_FLAGS='$XFFLAGS $FOPTIM -C'"} # exclude optimisation
  ;;

  "HP-UX U.09*")                # What you get from on Convex-rebadged HP-SUX
                                # (honestly!) <zhangj@cuhhca.hhmi.columbia.EDU>
    if test ! -x /usr/convex/bin/fc; then
      echo "! This is a strange version of HPUX -- apparently not the Convex one."
      echo "! Don't know how to deal with it; contact ccp4 with details."
      exit 1
    else true; fi
    FC=${FC-fc}                 # convex compiler
    M4=${M4-"m4 -D_convex=1"}
    XFFLAGS=${XFFLAGS-"-or none"}
    XLDFLAGS=${XLDFLAGS-"-lm"} 
    FOPTIM=${FOPTIM-"-O2"}
    # ``On HP AMORE can give problems when compliled with -O, You need to
    # complile it with -N.'' quoth MATTEVI@IPVGEN.UNIPV.IT.  No reports of
    # this under HPUX8.
    SETFLAGS=${SETFLAGS-"amore_FLAGS='$XCFLAGS\ $LDFLAGS\ -N' \
                         prepform_FLAGS='$XFFLAGS' \
                         arp_warp_FLAGS='$XFFLAGS $FOPTIM -C'"} # exclude optimisation
    ;;
  HP-UX*) echo "! Beware -- this is a substantially different OS version to those tested"
    XLDFLAGS=${XLDFLAGS-"-lfsys -lm"} # access to routines f77<C name>
                                      # -lm for solomon
    XFFLAGS=${XFFLAGS-"+U77 -w"}
    XCFLAGS=${XCFLAGS-"-w"}
    M4=${M4-"m4 -D_hpux=1"}
    SETFLAGS=${SETFLAGS-"prepform_FLAGS='$XFFLAGS' \
                         arp_warp_FLAGS='$XFFLAGS $FOPTIM -C'"} # exclude optimisation
    ;;
  *) echo "! This doesn't appear to be a HP-UX system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  # what `which fort77`:          HP-UX Fortran/9000s700 09/19/91 B2408A.08.07
  # what `which cc'        HP92453-01 A.08.71 HP C (Bundled) Compiler
  FC=${FC-fort77}
  COPTIM=${COPTIM-""}   # doesn't have -O
  FOPTIM=${FOPTIM-"-O"}
  RANLIB=${RANLIB-:}
  test "$with_f2c" && M4="m4 -D_f2c=1"
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"cp"}
  INSTALL_DATA=${INSTALL_DATA-"cp"}
 ;;
ultrix)       # 3.2?
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  case `uname -sr` in
#  ULTRIX\ 4.2) ;;
  ULTRIX*)
#    echo "! Beware -- this is a substantially different OS version to those tested"
    ;;
  *)
     echo "! This doesn't appear to be an Ultrix system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
  # Dec are now supplying `DEC Fortran' rather than the MIPS compiler.
  # Significant differences, sigh.
  case `what \`which f77\` | tail +2` in
  *DEC\ Fortran\ Compiler\ Driver*) # e.g., (with leading whitespace)
           # DEC Fortran Compiler Driver X3.1-14
    M4=${M4-"m4 -D_dec_fortran=1"} ;;
    # else assume MIPS compiler -- should find out how to identify it
  esac
  test "$with_f2c" && M4="m4 -D_f2c=1" || true
  SETFLAGS=${SETFLAGS-"amore_FLAGS='-O0\
    absurd_FLAGS=-O0'"} # fixme: is this still necessary?
  FOPTIM=${FOPTIM-"-O2"}
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/bin/install -c"}
  INSTALL_DATA=${INSTALL_DATA-"/usr/bin/install -m 644 -c"}
  # -O4 is default in version 3.10.  that version supports -trapuv
  #echo; echo "! Beware -- the $system installation is not fully tested."
  ;;
osf1)
  case `uname -sr` in
  # This may be changing in `DEC Unix' (?).
  # v3.2c is reported to have problems with GNU stuff related to
  # the loader, I think.
  OSF1\ V3*|OSF1\ V4*)
    # I don't know whether -assume dummy_aliases is supported/needed in 
    # earlier versions...
    XFFLAGS=${XFFLAGS-"-fpe0 -assume dummy_aliases -nowarn"}
    XCFLAGS=${XCFLAGS-"-w -DPROTOTYPE"}
    FOPTIM=${FOPTIM-"-O1"}
#   don't yet know if this is enough...
    if test "$shared_lib" = yes; then
      SHARE_LIB=${SHARE_LIB-'ld -shared -o libccp4.so -expect_unresolved \* -all libccp4.a'}
      SHARE_INST='$(INSTALL_DATA) `pwd`/libccp4.so $(libdir)/libccp4.so'
    fi
    ;;
  OSF1*)
    ;;
  *)
     echo "! This doesn't appear to be an OSF/1 system.
  You should run configure on a machine of the correct type."
    exit 1 ;;
  esac
	test "$with_f2c" && M4="m4 -D_f2c=1"
  M4=${M4-"m4 -D_dec_fortran=1"} 
  FOPTIM=${FOPTIM-"-O1"}
  XFFLAGS=${XFFLAGS-"-fpe0 -nowarn"} # & core dump on overflow, /0 and invalid
  XCFLAGS=${XCFLAGS-"-w -DPROTOTYPE"}
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"/usr/bin/installbsd -c"}
  INSTALL_DATA=${INSTALL_DATA-"/usr/bin/installbsd  -m 644 -c"}
  SETFLAGS=${SETFLAGS-"amore_FLAGS='-O0' rsps_FLAGS='-O1 -Olimit 3000' \
                   sftools_FLAGS='$XFFLAGS $FOPTIM -assume backslash' \
                  arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' "}
  # Xwindows variables set if wanted or not!
  XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
  XWIN_LIB=${XWIN_LIB-"-lX11 -lXt"}
  XTYPE=${XTYPE-"DECALPHAOSF"}
  # echo; echo "! Beware -- the $system installation is not fully tested."
  ;;
linux_compaq_compilers)
# Thanks to Sanjoy Ray and David van der Spoel for this. 
# Apparently compaq now distribute a set of compilers for linux
# this conifure was hacked together by Sanjoy Ray from the 
# OSF1 option.
    echo "! This is a new option and is relativeley untested!"
    echo "! November 1999"
  case `uname -sr` in
    Linux*)

       ;;
    *)
       echo "! This doesn't appear to be a Linux system. You should run"
       echo "! configure on a machine of the correct type."
       exit 1 ;;
  esac
  case `grep Alpha /proc/cpuinfo` in
    *Alpha)

       ;;
    *)
       echo "! This doesn't appear to be an Alpha system. You should run"
       echo "! configure on a machine of the correct type."
       exit 1 ;;
  esac
  case `which fort` in
    *fort)

       ;;
    *)
       echo "! You don't appear to have the Compaq Fortran compiler (fort). "
       echo "! Either configure for Linux, or install fort."
       echo "! See http://www.unix.digital.com/linux/software.htm"
       exit 1 ;;
  esac
  case `which ccc` in
    *ccc)

       ;;
    *)
       echo "! You don't appear to have the Compaq C compiler (ccc). "
       echo "! Either configure for Linux, or install ccc."
       echo "! See http://www.unix.digital.com/linux/software.htm"
       exit 1 ;;
  esac
  FC=${FC-fort}
  CC=${CC-ccc}
  M4=${M4-"m4 -D_dec_fortran=1"}
  FOPTIM=${FOPTIM-"-O1"}
  XFFLAGS=${XFFLAGS-"-fpe0 -assume dummy_aliases -nowarn"}
  XCFLAGS=${XCFLAGS-"-w -DPROTOTYPE -D__OSF1__"}
  INSTALL_DATA=${INSTALL_DATA-"cp"}
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"cp"}
  SETFLAGS=${SETFLAGS-"amore_FLAGS='-O0' rsps_FLAGS='-O2' \
                   sftools_FLAGS='$XFFLAGS $FOPTIM'"}
  XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
  XWIN_LIB=${XWIN_LIB-"-L/usr/X11R6/lib -lX11 -lXt -lICE -lSM"}
  XTYPE=${XTYPE-"LINUX"}
  ;;
linux)
  case `uname -sr` in
    Linux*)
       
       ;;
    *)
       echo "! This doesn't appear to be a Linux system. You should run"
       echo "! configure on a machine of the correct type."
       exit 1 ;;
  esac
  test "$with_f2c" && M4="m4 -D_f2c=1"
  test "$with_f2c" && XCFLAGS=${XCFLAGS-"-DPROTOTYPE"}
  test ! "$with_f2c" && M4="m4 -D_g77=1"
  test ! "$with_f2c" && XCFLAGS=${XCFLAGS-"-DG77 -DPROTOTYPE -DHAVE_G2C_H"}
  FC=${FC-g77}
  CC=${CC-gcc}
# Michael Wahl says this is sometimes needed: may need to be removed.
  XFFLAGS=${XFFLAGS-"-fno-second-underscore -fno-globals"}
  FOPTIM=${FOPTIM-"-O"}
  COPTIM=${COPTIM-"-O"}
  INSTALL_DATA=${INSTALL_DATA-"cp"}
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"cp"}
  SETFLAGS=${SETFLAGS-"sftools_FLAGS='$XFFLAGS $FOPTIM -fno-backslash' \
                      refmac_FLAGS='$XFFLAGS -O0' \
                      arp_warp_FLAGS='$XFFLAGS $FOPTIM -fforce-mem'"}
  XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
  XWIN_LIB=${XWIN_LIB-"-L/usr/X11R6/lib -lX11 -lXt -lICE -lSM"}
  XTYPE=${XTYPE-"LINUX"}
  if test "$shared_lib" = yes; then
    SHARE_LIB=${SHARE_LIB-'ld -shared --whole-archive -o libccp4.so libccp4.a'}
    SHARE_INST='$(INSTALL_DATA) `pwd`/libccp4.so $(libdir)/libccp4.so'
  fi
  ;;
gnu_win32)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
  case `uname -sr` in
    CYGWIN32_*)
       echo; echo "! You will need the fsplit utility"
       echo; echo "*************************************************************"
       echo " ! Sorry but you MUST also do a minor change to \$CPROG/Makefile and"
       echo " ! (to be safe) \$CPROG/Makefile.in."
       echo " ! sfcheck will not compile with the object sfch_unix and so all"
       echo " ! cases of sfch_unix.o or sfch_unix.f must be replaced with "
       echo " ! sfch_linux.o or sfch_linux.f prior to makeing the suite."
       echo " ! This will eventually be automated!"; echo
       ;;
    *)
       echo "! This doesn't appear to be a gnu32 system. You should run"
       echo "! configure on a machine of the correct type."
       exit 1 ;;
  esac
  test "$with_f2c" && M4="m4 -D_f2c=1"
  test "$with_f2c" && XCFLAGS=${XCFLAGS-"-DPROTOTYPE"}
  test ! "$with_f2c" && M4="m4 -D_g77=1"
  test ! "$with_f2c" && XCFLAGS=${XCFLAGS-"-DG77 -D_WIN32 -DPROTOTYPE"}
  FC=${FC-g77}
  CC=${CC-gcc}
# Michael Wahl says this is sometimes needed: may need to be removed.
  XFFLAGS=${XFFLAGS-"-fno-second-underscore"}
  FOPTIM=${FOPTIM-"-O"}
  COPTIM=${COPTIM-"-O"}
  INSTALL_DATA=${INSTALL_DATA-"cp"}
  INSTALL_PROGRAM=${INSTALL_PROGRAM-"cp"}
  SETFLAGS=${SETFLAGS-"sftools_FLAGS='$XFFLAGS $FOPTIM -fno-backslash'"}
  ;;
freebsd)
  if test -n "$with_x"; then
    echo "! Xwindows installation has not been tested    !"
    echo "! for this system and so will not be attempted.!"
    with_x=
  fi
	case `uname -sr` in
		FreeBSD*)
			echo; echo "! Beware -- the $system installation is not tested.";;
		*)
			echo "! This doesn't appear to be a FreeBSD system.
  You should run configure on a machine of the correct type."
    	exit 1 ;;
	esac
	XFFLAGS=${XFFLAGS-'-Nx400'}; FOPTIM=${FOPTIM-"-O"}; with_f2c=1;
	SETFLAGS=${SETFLAGS-""}
	;;
generic) ;;			# just the defaults (library.c will barf)
esac

### defaults for the variables if not set above:

RANLIB=${RANLIB-ranlib} 	# ranlib for libraries -- Berzerkeley has it,
				# SysVile doesn't use it
FC=${FC-f77}			# fortran compiler
# XFFLAGS (special fortran flags) null by default
CC=${CC-cc}			# C compiler
XCFLAGS=${XCFLAGS-""}		# special C flags
FOPTIM=${FOPTIM-""}		# Fortran optimisation flag
COPTIM=${COPTIM-"-O"}		# C optimisation flag
LNS=${LNS-"ln -s"}		# make symbolic link or copy if system
				# doesn't have symbolic links, because can't hard link across
				# file systems [fixme: configure could test ability to hard
				# link from $srcdir to . ]
# how to run m4 to preprocess unix.m4
# The BSD4.2 m4 doesn't allow any command-line flags.  With it
# `pre-defines' will have to be specified in an extra file and sync
# lines can't be inserted.  Actually, sync lines probably lose for
# various reasons, so don't use them.  Where there's a choice you
# probably want the SysVile m4.
if test -z "$M4"; then
  if test "$with_f2c"; then
    M4="m4 -D_f2c=1"
  else
    M4=m4
  fi
else true
fi
MAKE=${MAKE-}			# We need the variable MAKE for recursion in
				# the makefiles and some makes don't set it.  Setting it with
				# configure prevents using e.g., gmake, pmake at different
				# times
F=${F-f}			# extension for fortran files (now always .f)

test "$with_f2c" && test "$hush" != 1 && XCFLAGS="$XCFLAGS -DF2C" || true

# XLDFLAGS (extra load flags e.g., for libraries) null by default

# SETFLAGS defines individual FCFLAGS for some targets which need
# special treatment, probably through optimiser problems and is
# normally null.  If program foo needs flags -bar and -baz, define
# SETFLAGS="foo_FLAGS=-bar\ -baz".  To express null flags use use
# foo_FLAGS=' '.
# n.b. amore has horrible data-aliasing problems -- always turn off optimistion
# in the hope they won't bite...
# Actually, -O0 isnt always valid...
#SETFLAGS=${SETFLAGS-"amore_FLAGS=$XCFLAGS\ $LDFLAGS\ -O0"}
INSTALL_PROGRAM=${INSTALL_PROGRAM-"cp"} # command to install executables --
					# use BSD install if available, to
					# avoid chaos with running programs
INSTALL_DATA=${INSTALL_DATA-"cp"} # install for non-executables -- BSD install
				  # with appropriate -m if available

test -z "$MAKE" || MAKELINE="MAKE = $MAKE"

test "$shared_lib" = yes && test -z "$SHARE_LIB" &&
  echo "! --with-shared-lib not supported for $system" || true

if test "$shared_lib" = yes; then
	case $system in
# fixme: I think this is wrong and was corrected previously.
# LD_LIBRARY_PATH probably works -- needs checking.
# 	osf1) test -z "$_RLD_LIST" &&
# 			echo; echo "! Set _RLD_LIST to use the shared library"; echo; ;;
	*) test -z "$LD_LIBRARY_PATH" &&
			( echo; echo "! Set LD_LIBRARY_PATH to use the shared library"; echo; ) ;;
  esac
else true
fi

# some setting up for xwindows - or not
if test "$with_x" = yes; then
    DIRS=". $src $unsupp $xwindir lib/src lib/data"
    /bin/cp $xwindir/XCCPJIFFY/Imakefile $xwindir/XCCPJIFFY/Imakefile.bak
    echo "#define $XTYPE" > $xwindir/XCCPJIFFY/Imakefile
    echo "PLOT_COMMAND = " $PLOT_COMMAND >> $xwindir/XCCPJIFFY/Imakefile 
    echo "PRINT_COMMAND = " $PRINT_COMMAND >> $xwindir/XCCPJIFFY/Imakefile
    cat $xwindir/XCCPJIFFY/Imakefile.in >> $xwindir/XCCPJIFFY/Imakefile
else
    if test -f x-windows/Makefile; then 
      /bin/mv x-windows/Makefile x-windows/Makefile.old
      echo 
      echo "* an old x-windows/Makefile has been moved to "
      echo "* x-windows/Makefile.old for safe keeping!"
    else true
    fi
    DIRS=". $src $unsupp lib/src lib/data"
fi

### Set CCIF variables, and run separate configure unless disabled
if test "$disable_ccif" = yes; then
# disable CCIF stuff
  ccifdir= 
  XCIF_LIB= 
  if test ! -f lib/src/harv_orig.f; then 
     /bin/mv lib/src/harvlib.f lib/src/harv_orig.f; else true; fi
  /bin/cp lib/src/harv_dummy.f lib/src/harvlib.f
else
# run configure for CCIF library
  ccifdir=lib/ccif
  XCIF_LIB="-L$srcdir/lib/ccif -lccif"
  if test -f lib/src/harv_orig.f; then 
     /bin/cp lib/src/harv_orig.f lib/src/harvlib.f; else true; fi
  CFLAGS="${COPTIM} ${XCFLAGS}"
  FFLAGS="${FOPTIM} ${XFFLAGS}"
  export CFLAGS FFLAGS SHARED_LIB_FLAGS
  if test "$shared_lib" = yes; then 
    xopts="--enable-shared=yes"
  else
    xopts="--enable-shared=no"
  fi
  if test "$with_rxdispencer" = yes; then
    echo 
    echo "Running separate configure for rxdispencer."
    echo
    MAKE=${MAKE:-make}
    cd lib/rxdispencer
    ./configure 
    $MAKE
    cd ../..
    RX_H="$srcdir/lib/rxdispencer/rx"
    RX_L="$srcdir/lib/rxdispencer/rx"
    export RX_H RX_L
  fi
  echo 
  echo "Running separate configure for CCIF library."
  echo
  cd lib/ccif
  ./configure $xopts --libdir=${libdir}
  cd ../..
  echo
  echo "Returning to main configure."
  echo
fi

### Build makefiles in the sub-directories
for i in $DIRS ; do
  cat >$i/Makefile <<END
# This file was generated by configure -- don't edit it!

TMPDIR = $tmpdir
top_srcdir = $srcdir
libdir = $libdir
ccifdir = $ccifdir
bindir = $bindir
RANLIB = $RANLIB
FC     = $FC
FOPTIM = $FOPTIM
COPTIM = $COPTIM
XFFLAGS = $XFFLAGS
XCFLAGS = $XCFLAGS
FFLAGS = \$(FOPTIM) \$(XFFLAGS)
XCIF_LIB = $XCIF_LIB
LDFLAGS = $LDFLAG -lccp4 $XLDFLAGS \$(XCIF_LIB)
CFLAGS = \$(COPTIM) \$(XCFLAGS)
XDL_LIB = $XDL_LIB
XWIN_LIB = \$(XDL_LIB) $XWIN_LIB
CC     = $CC
LNS    = $LNS
M4     = $M4
SETFLAGS = $SETFLAGS
F      = $F
INSTALL_PROGRAM = $INSTALL_PROGRAM
INSTALL_DATA = $INSTALL_DATA
$MAKELINE

END

if test $i = lib/src; then
  cat >>$i/Makefile <<END
SHARE_LIB = $SHARE_LIB
SHARE_INST = $SHARE_INST
END
else true
fi

cat $srcdir/$i/Makefile.in >>$i/Makefile

done

if test "$with_x" = yes; then
# run configure for xdlview library
  CFLAGS="${COPTIM} ${XCFLAGS}"
  FFLAGS="${FOPTIM} ${XFFLAGS}"
  export CFLAGS FFLAGS SHARED_LIB_FLAGS
  if test "$shared_lib" = yes; then 
    xopts="--enable-shared=yes"
  else
    xopts="--enable-shared=no"
  fi
  echo
  echo "Running separate configure for xdlview library."
  echo
  cd x-windows/xdl_view/src
  echo "configure $xopts --libdir=${libdir}"
  ./configure $xopts --libdir=${libdir} 
  cd ../../..
  echo
  echo "Returning to main configure."
  echo
fi

# suggested by Bart Hazes to solve manual edditing of $CPROG/Makefile
if test $system = linux; then
    echo 
    echo "* Changing $CPROG/Makefile to use sfch_linux and molrep_linux" 
    echo "* instead of sfch_unix and molrep_unix."
    sed 's/sfch_unix/sfch_linux/g' $CPROG/Makefile > $CPROG/Makefile.linux
    /bin/mv -f $CPROG/Makefile.linux $CPROG/Makefile
    sed 's/molrep_unix/molrep_linux/g' $CPROG/Makefile > $CPROG/Makefile.linux
    /bin/mv -f $CPROG/Makefile.linux $CPROG/Makefile
fi

# fixme: decide whether we should zap any existing libccp4.a

# That's it.  Record the result in config.status for possible re-use
# (following the GNU convention) and give the luser some idea what we've
# done...

test $src || opts=" --onlylibs"
test "$with_f2c" && opts=$opts" -with-f2c" || true
test "$shared_lib" = yes && opts="$opts -with-shared-lib" || true
test "$tmpdir"  && opts="$opts --tmpdir=$tmpdir" || true
test "$with_x" = yes && opts="$opts --with-x" || true
test "$with_rxdispencer" = yes && opts="$opts --with-rxdispencer" || true
test "$disable_ccif" = yes && opts="$opts --disable-ccif" || true

cat <<EOF >config.statusx
#!/bin/sh
# (Generated automatically by configure)
# CCP4 was configured as follows:
libdir="$libdir"		RANLIB="$RANLIB" \\
FC="$FC"			FOPTIM="$FOPTIM" \\
COPTIM="$COPTIM"		XFFLAGS="$XFFLAGS" \\
XCFLAGS="$XCFLAGS"	 	CC="$CC" \\
LNS="$LNS"			M4="$M4" \\
M4FLAGS="$M4FLAGS"		SETFLAGS="$SETFLAGS" \\
MAKE="$MAKE"			F="$F"       \\
INSTALL_PROGRAM="$INSTALL_PROGRAM"	INSTALL_DATA="$INSTALL_DATA" \\
XLDFLAGS="$XLDFLAGS" SHARE_LIB="$SHARE_LIB" SHARED_LIB_FLAGS="$SHARED_LIB_FLAGS" \\
 SHARE_INST="$SHARE_INST" \\
$srcdir/configure -srcdir=$srcdir --bin=$bindir --lib=$libdir $opts $system -hush

EOF

chmod a+x config.statusx

echo
echo "The configuration can be re-built by executing config.status :"
echo
# indirect as we may be executing config.status
cat config.statusx
mv config.statusx config.status

touch Makefile			# for Makefile target in itself

# I'm not sure if this is a completely reliable/robust way to figure
# out if the program is there.  If `type' is universal, it may be best
# to use `if type fsplit >/dev/null'
if fsplit </dev/null >/dev/null; then true
else                            # e.g. some OSFs, Linux
  echo "! You don't appear to have \`fsplit', without which the"
  echo "! CCP4 library won't build."
  if test $system = irix; then
    cat <<\+
! You need to install the ftn_dev util stuff, which apparently isn\'t done
! by default.  You should then see something like this:
!   % versions long ftn_dev | grep fsplit
!   f 33940    29 ftn_dev.sw.util         usr/bin/fsplit
!   f 51059     4 ftn_dev.man.util        usr/share/catman/u_man/cat1/fsplit.z
+
  else
  echo "!  You can get a copy e.g. by ftp or via the Web from"
  echo "! http://src.doc.ic.ac.uk/computing/systems/unix/bsd-sources/usr.bin/fsplit"
  echo "! amongst other places.  Also complain to your vendor!"
  fi
fi

if test -f lib/src/libccp4.a; then
	echo
	echo "If the compiled library \`lib/src/libccp4.a' is from a previous release"
	echo "you should delete it before compiling the current version."
else true
fi

#