#! /bin/sh

# $Id: configure,v 1.126 2001/01/31 14:41:52 pjx 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):

###
###   CCP4 licensing and conditions.
###
### A complete new section for licensing
### Removing or attempting to bypass this section in the configure script 
### is deemed as agreeing to the conditions outlined in $CCP4/license.txt

agreed=no
ans=n
user=`whoami`

### has someone else we (know about) agreed to the ccp4 conditions before?
### and if so make sure the the home dir has agreement file
if test -f .agree2ccp4; then
   eval touch ${HOME}/.agree2ccp4;
   if test -w .agree2ccp4; then 
      echo $user `date` >> .agree2ccp4;   
   fi
   if test -w ${HOME}/.agree2ccp4; then
      date >> ${HOME}/.agree2ccp4;
   fi
   agreed=yes
fi

### has the user agreed to the ccp4 condition's before?
if test $agreed = "no"; then
   if test -f ${HOME}/.agree2ccp4; then
      eval touch .agree2ccp4
      if test -w ${HOME}/.agree2ccp4; then
         date >> ${HOME}/.agree2ccp4;
      fi
      if test -w .agree2ccp4; then 
         echo $user `date` >> .agree2ccp4;   
      fi
      agreed=yes
   fi
fi

### so if this site, as far as we know has never agreed to ccp4 
### conditions then they must!

if test $agreed = "no"; then
  echo ; echo ;
  echo "    For legal reasons we must draw your attention to the"
  echo "    conditions of use and license agreement required to "
  echo "    use the CCP4 package (If you agree to the conditions"
  echo "    you should only be prompted for this information once)."
  echo ; echo ;
  echo -n "    Please press return to continue:"

  read return;

  if test -r licence.txt; then
     echo ; echo ; echo "Please read the following"; echo ;
     more licence.txt ;
     echo ; echo ; 
     echo "Do you agree to the above and agree (if this has not" ;
     echo "already been done) to return a completed and signed";
     echo "copy of this document found in license.txt? "
     echo "(Please note that if a copy of the previous license has been";
     echo "returned there is no need to send a copy of this new agreement)";
     echo -n "          y/n [n] ?:";

     read ans ;

     if test $ans = "y"; then 
       eval touch ${HOME}/.agree2ccp4;
       if test -w ${HOME}/.agree2ccp4; then
         date > ${HOME}/.agree2ccp4;
       else
         echo "  No record of you agreeing to the CCP4 license coditions";
         echo "  has been kept in your home area.";
       fi
       echo $user `date` > .agree2ccp4;
       chmod ugo+rw .agree2ccp4 ;   
       agreed=yes ;
       echo ; echo ; echo " Thank you. The CCP4 configure will now run as normal.";
     fi
  else
    echo " The file license.txt in the $CCP4 directory could not be found" 
    echo " Please download or contact ccp4@ccp4.ac.uk" ; echo ; echo;
    exit 1
  fi
fi

if test $agreed = "no"; then
    echo ; echo ; echo " You have indicated that you do not agree to the conditions";
    echo " of use for the CCP4 package. Please delete all CCP4 software";
    echo " from your system. If you have any further queries please refer ";
    echo " to the CCP4 web pages on http://www.dl.ac.uk/CCP/CCP4/ or contact" ;
    echo " ccp4@ccp4.ac.uk";
    exit 1
fi

### End of licensing section.

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] 
       [--with-lapack] 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
if test -d x-windows/Rotgen; then
  rotgendir=x-windows/Rotgen ;
else true
fi
if test -d x-windows/Mosflm; then
  mosflmdir=x-windows/Mosflm ;
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'}; FOPTIM=${FOPTIM-"-O"}; with_f2c=1;
      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
      ;;

    -with-lapack | --with-lapack)
      with_lapack=yes
      ;;

    -with-lapack=FORCE | --with-lapack=FORCE)
      with_lapack=yes
      force_lapack=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
PWD=`pwd`     # not always 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 for inclusion of lapack
if test -n "$with_lapack"; then
  echo
  echo " You have requested inclusion of the LAPACK linear algebra"
  echo " package. This package is not required for the current release."
  echo " If a version of LAPACK is not found on your system then the"
  echo " NetLib version will be built for you automatically."
  echo " If you want NetLib LAPACK and BLAS to be used regardless of"
  echo " system libraries then rerun configure using --with-lapack=FORCE"
  echo "         ******** please note ************"
  echo " This option has not been widely tested. Please report problems"
  echo " or comments to ccp4@ccp4.ac.uk"
else
  echo
  echo "! The LAPACK linear algebra package will not be built or"
  echo "! otherwise included."
  echo "! This is not required for the current release but may be"
  echo "! useful for program developers, re-run configure with the"
  echo "! --with-lapack flag to include it."
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 ./ccp4i/etc/unix $mosflmdir/lib $mosflmdir/bin $mosflmdir/cbf/lib ; 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' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -Nn18000 -Nq12000 -static' \
               mosflm_LDFLAGS='$XFFLAGS -s -static' \
               filec_CFLAGS='$XCFLAGS $COPTIM -Dsgi'"}
    # 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' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -Nn18000 -Nq12000 -static' \
               mosflm_LDFLAGS='$XFFLAGS -s -static' \
               filec_CFLAGS='$XCFLAGS $COPTIM -Dsgi'"}
      # 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' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -Nn18000 -Nq12000 -static' \
               mosflm_LDFLAGS='$XFFLAGS -s -static' \
               filec_CFLAGS='$XCFLAGS $COPTIM -Dsgi'"}
    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 -w"}
#      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' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -Nn18000 -Nq12000 -static' \
               mosflm_LDFLAGS='$XFFLAGS -s -static' \
               filec_CFLAGS='$XCFLAGS $COPTIM -Dsgi' \
               dps_FFLAGS='$XFFLAGS $FOPTIM -static' \
               fftpack_FFLAGS='$XFFLAGS $FOPTIM -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 -w"}
      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 -w"}
#      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 -w"}
      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 -w"}
#      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=0 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE -w"}
      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=0 -w"}
      XCFLAGS=${XCFLAGS-"-64 -DPROTOTYPE -w"}
      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 -Nq3000' \
                 detwin_FLAGS='$XFFLAGS $FOPTIM -static' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -Nn18000 -Nq12000 -static' \
               mosflm_LDFLAGS='$XFFLAGS -s -static' \
               filec_CFLAGS='$XCFLAGS $FOPTIM -Dsgi' \
               dps_FFLAGS='$XFFLAGS $FOPTIM -static' \
               fftpack_FFLAGS='$XFFLAGS $FOPTIM -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
# Automated x-install for AIX from Sandra McLaughlin (March 2000)
  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' \
                       xdlmapman_FLAGS='$XFFLAGS -qfixed=80'"}
  # 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"}
  # Xwindows variables set if wanted or not!
  # But I don't know what to set XTYPE to (or what it is used for) ! 
  XDL_LIB=${XDL_LIB-"${CCP4_LIB}/libxdl_view.a"}
  XWIN_LIB=${XWIN_LIB-"-lX11 -lXt -lXext"}
  XTYPE=${XTYPE-"AIX"}
  # 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\ V5*)
    # This is based on the V3/4 entry
    # I don't know whether -assume dummy_aliases is supported/needed in 
    # earlier versions...
    # -D__V40_OBJ_COMPAT -nointrinsics required for V5 executables to run
    # under 4.0
    XFFLAGS=${XFFLAGS-"-fpe0 -assume dummy_aliases -nowarn"}
    XCFLAGS=${XCFLAGS-"-w -DPROTOTYPE -D__V40_OBJ_COMPAT -nointrinsics"}
    FOPTIM=${FOPTIM-"-O1"}
    # Xwindows variables set if wanted or not!
    XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
    XWIN_LIB=${XWIN_LIB-"-lXt -lSM -lX11 -lICE -ldnet_stub"}
#   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' \
                  arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM' \
               mosflm_LDFLAGS='-s' \
               filec_CFLAGS='$XCFLAGS $COPTIM -Dalpha' "}
  # 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' \
               arp_warp_FLAGS='$XFFLAGS $FOPTIM -C -static' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -w' \
               mosflm_LDFLAGS='-s' \
               filec_CFLAGS='$XCFLAGS $FOPTIM -Dlinux' "}
  XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
  XWIN_LIB=${XWIN_LIB-"-L/usr/X11R6/lib -lXt -lSM -lX11 -lICE"}
  XTYPE=${XTYPE-"LINUX"}
  TIDY=${TIDY-"rm -f sta*"}
  ;;
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' \
                      refmac_FLAGS='$XFFLAGS -O0' \
                      arp_warp_FLAGS='$XFFLAGS $FOPTIM -fforce-mem' \
               mosflm_FFLAGS='$XFFLAGS $FOPTIM -w' \
               mosflm_LDFLAGS='-s' \
               filec_CFLAGS='$XCFLAGS $FOPTIM -Dlinux' \
               dps_CFLAGS='$XFFLAGS' "}
  XDL_LIB=${XDL_LIB-"-L${CCP4_LIB} -lxdl_view"}
  XWIN_LIB=${XWIN_LIB-"-L/usr/X11R6/lib -lXt -lSM -lX11 -lICE"}
  XTYPE=${XTYPE-"LINUX"}
  TIDY=${TIDY-"rm -f sta*"}
  if test "$shared_lib" = yes; then
    SHARE_LIB=${SHARE_LIB-'ld -shared -soname libccp4.so --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'"}
  ;;
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 . ]
TIDY=${TIDY-"rm -f ________64ELEL_"}      # used in Mosflm script
# 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-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 $rotgendir $mosflmdir/mosflm \
          $mosflmdir/cbf $mosflmdir/index 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}"
  if test "$CC" = gcc && test "$shared_lib" = yes; then
    CFLAGS="${COPTIM} ${XCFLAGS} -fPIC"
    FFLAGS="${FOPTIM} ${XFFLAGS} -fPIC"
  fi
  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

### Set variables for LAPACK build, and run configure if enabled
if test "$with_lapack" = yes; then
  # configure for build of LAPACK and BLAS
  # First find BLAS library
  echo 
  echo "********* BLAS AND LAPACK CONFIGURATION ***********"
  echo
  echo "Warning: this option has not been extensively tested!"
  echo "Please send questions or problems to ccp4@ccp4.ac.uk"
  # Search for vendor LAPACK/BLAS
  if test ! "$force_lapack" ; then
    # Possible directories to check for vendor or pre-existing LAPACK or
    # BLAS - add to these if you want to test others
    trydirs="/lib /usr/lib /usr/local/lib $CCP4_LIB"
    # Possible library names
    # These are the names like xxxx where the library will be libxxxx.a
    # or libxxxx.so
    echo
    echo "Guessing names for native/vendor LAPACK and/or BLAS libraries"
    echo "on this system"
    case $system in
      osf1)
        # OSF1 has dxml (old version) and cxml
        # which should have both lapack and blas 
        trylapack="dxml cxml"
        tryblas=
        ;;
      irix)
        # Additional search paths for IRIX
        trydirs="${trydirs} /usr/lib32"
        # SCSL should have both LAPACK and BLAS
        trylapack="scs"
        tryblas="blas"
        ;;
      irix64)
        # Additional search paths for IRIX64
        trydirs="${trydirs} /usr/lib64"
        # SCSL should have both LAPACK and BLAS
        trylapack="scs"
        tryblas="blas"
        # Extra compiler flags?
        #XLAPACKFLAGS="-OPT:IEEE_NaN_inf=ON"
        ;;
      hpux)
        # Additional search paths for HPUX
        trydirs="${trydirs} /opt/fortran/lib /opt/fortran/lib/pa2.0 /opt/mlib/lib/pa2.0"
        # HPUX should have both LAPACK (part of mlib) and BLAS
        trylapack="lapack"
        tryblas="blas"
        # Extra compiler flags?
        # +U77 required for ETIME function - this is already in XFFLAGS
        #XLAPACKFLAGS="+U77"
        ;;
      sunos)
        # Sun has libraries with BLAS and LAPACK invoked using -xlic_lib=sunperf
        echo "SunOs can use the Sun Performance Library which has both"
        echo "BLAS and LAPACK 3.0"
        trylapack=
        tryblas=
        ;;
      *)
        echo "! Sorry - I don't know which libraries have BLAS and/or"
        echo "! LAPACK on this system."
        echo "! Please e-mail ccp4@ccp4.ac.uk if you have any information"
        # Default guess is just libblas
        trylapack=
        tryblas="blas"
        ;;
    esac
    #
    # Search for LAPACK libraries
    #
    # Write out what the guesses are
    if test "$trylapack" ; then
      echo "Possible LAPACK library names for this system:"
      for libname in $trylapack
      do
        echo "   lib$libname"
      done
      # Possible library name extensions
      tryexts="a so"
      # Now loop over all the possibilities and see if anything
      # turns up
      echo
      echo "Searching for libraries with LAPACK and BLAS:"
      for testdir in $trydirs
      do
        for testlib in $trylapack
        do
          for ext in $tryexts
          do
            if test ! "$LAPACKLIB"; then
              if test -s "$testdir/lib$testlib.$ext" ; then
                echo "...found LAPACK library: $testdir/lib$testlib.$ext"
                # Now try and link to a test program
                # This is really for IRIX where libraries can be
                # o32 or n32
                echo "   Testing: try to link library against test program"
                if test -f testlink.f || test -f testlink ; then
                  rm -f testlink*
                fi
                cat > testlink.f <<EOF
c Test fortran program to link against library
      PROGRAM TESTLINK
      IMPLICIT NONE
      INTEGER A
      A = 1
      STOP
      END
EOF
                test_compile="$FC $FOPTIM $XFFLAGS -o testlink testlink.f -L$testdir -l$testlib"
                echo $test_compile
                if {(eval $test_compile) 2>&1;} && test -s testlink ; then
                # This one is okay
                  LAPACKLIB="$testlib"
                  LAPACKDIR="$testdir"
                  echo "Link ok - using lib$LAPACKLIB from $LAPACKDIR"
                else
                # Keep looking
                  echo "   link failed - cannot use lib$testlib"
                fi
              fi
            fi
          done
        done
        if test ! "$LAPACKLIB"; then
          echo "...nothing in $testdir"
        fi
      done
    fi
    # If LAPACKLIB hasn't been set at this point then no LAPACK library
    # was found 
    if test ! "$LAPACKLIB" ; then
      echo
      echo "No pre-existing LAPACK library found - NetLib LAPACK will be built instead"
      make_lapack=lapacklib
      # Look for possible BLAS
      if test "$tryblas" ; then
        echo
        echo "Possible BLAS library names for this system:"
        for libname in $tryblas
        do
          echo "   lib$libname"
        done
        # Possible library name extensions
        tryexts="a so"
        # Now loop over all the possibilities and see if anything
        # turns up
        echo
        echo "Searching for libraries with BLAS:"
        for testdir in $trydirs
        do
          for testlib in $tryblas
          do
            for ext in $tryexts
            do
              if test ! "$BLASLIB"; then
                if test -s "$testdir/lib$testlib.$ext" ; then
                  echo "...found BLAS library: $testdir/lib$testlib.$ext"
                  # Now try and link to a test program
                  # This is really for IRIX where libraries can be
                  # o32 or n32
                  echo "   Testing: try to link library against test program"
                  if test -f testlink.f || test -f testlink ; then
                    rm -f testlink*
                  fi
                  cat > testlink.f <<EOF
c Test fortran program to link against library
      PROGRAM TESTLINK
      IMPLICIT NONE
      INTEGER A
      A = 1
      STOP
      END
EOF
                  test_compile="$FC $FOPTIM $XFFLAGS -o testlink testlink.f -L$testdir -l$testlib"
                  echo $test_compile
                  if {(eval $test_compile) 2>&1;} && test -s testlink ; then
                    # This one is okay
                    BLASLIB="$testlib"
                    BLASDIR="$testdir"
                    BLASEXT="$ext"
                    echo "Link ok - using lib$BLASLIB from $BLASDIR"
                  else
                  # Keep looking
                    echo "   link failed - cannot use lib$testlib"
                  fi
                fi
              fi
            done
          done
          if test ! "$BLASLIB"; then
            echo "...nothing in $testdir"
          fi
        done
      fi
      # Do we need to build BLAS too?      
      if test ! "$BLASLIB" ; then
        echo
        echo "No pre-existing BLAS library was found - NetLib BLAS will be built instead"
        echo "This may result in poorer performance of the LAPACK routines"
        make_blas=blaslib
        BLASLIB=blas
        BLASDIR="$CCP4_LIB/lapack"
        BLASEXT="a"
      fi
    else
      # SunOs is a special case
      if test $system = sunos ; then
        echo
        echo "SUNOS: will use -xlic_lib=sunperf"
        lapackdir=
        XLAPACK_LIB="-xlic_lib=sunperf"
      else
      # Don't build anything - use the LAPACK library you've already found
        lapackdir=
        XLAPACK_LIB="-L$LAPACKDIR -l$LAPACKLIB"
      fi
    fi
  # Otherwise force building of NetLib BLAS and LAPACK libs
  else
    echo
    echo "! Force building of NetLib BLAS and LAPACK..."
    make_blas=blaslib
    make_lapack=lapacklib
    BLASLIB=blas
    BLASDIR="$CCP4_LIB/lapack"
    BLASEXT="a"
  fi
  #
  # Generate makefiles
  if (test -n "$make_lapack" || test -n "$make_blas") ; then
    # No options for shared libraries yet
    if test "$shared_lib" = yes; then
      echo
      echo "! Sorry... cannot configure make to build shared BLAS or"
      echo "! LAPACK libraries at present"
    fi
    #
    # Create the Makefile header for the LAPACK build
    cd lib/lapack
    echo
    echo "Creating make.inc header file for BLAS and/or LAPACK Makefiles..."
    cat > make.inc <<EOF
#
SHELL = /bin/sh
#
MAKE     = make
FORTRAN  = ${FC}
OPTS     = ${FOPTIM} ${XFFLAGS}
DRVOPTS  = $(OPTS)
NOOPT    = ${XFFLAGS}
LOADER   = 
#
ARCH     = ar
ARCHFLAGS= r
RANLIB   = ${RANLIB}
INSTALL_DATA = ${INSTALL_DATA}
libdir   = $libdir
#
BLASLIB     = lib${BLASLIB}.${BLASEXT}
LAPACKLIB   = liblapack.a
#
# These variables define targets in the main Makefile
blaslib   = ${make_blas}
lapacklib = ${make_lapack}
EOF
    echo "...done"
  #
  # Create the necessary Makefiles
  # BLAS:
    if test "$make_blas" = blaslib; then
      cd blas/src
      cat ../../make.inc Makefile.in > Makefile
      cd ../..
      echo
      echo "Created lib/blas/src/Makefile for BLAS compilation"
    fi
  # LAPACK
    if test "$make_lapack" = lapacklib; then
      cd src
      cat ../make.inc Makefile.in > Makefile
      cd ..
      echo
      echo "Created src/Makefile for LAPACK compilation"
    fi
  # Top level Makefile
    cat make.inc Makefile.in > Makefile
    echo
    echo "Created top-level LAPACK Makefile"
    echo "Only the single (real) precision, double precision, and complex"
    echo "precision routines will be built."
    cd ../..
    #
    lapackdir=lib/lapack
    XLAPACK_LIB="-L$srcdir/lib/lapack -llapack -L$BLASDIR -l$BLASLIB"
  fi
  # Clean up
  if test -f testlink.f || test -f testlink ; then
    rm -f testlink*
  fi
  echo 
  echo "***** BLAS AND LAPACK CONFIGURATION FINISHED *******"
else
# make sure we don't try to build LAPACK
  lapackdir=
  XLAPACK_LIB=
fi

### Build makefiles in the sub-directories
for i in $DIRS ; do

# this section checks to see if the compiler is gcc, you are dooing shared libs
# and you are currently creating lib/src/Makefile. otherwise will skip
if test $i = lib/src && test "$CC" = gcc && test "$shared_lib" = yes; then
   XFFLAGS=$XFFLAGS" -fPIC"
   XCFLAGS=$XCFLAGS" -fPIC"
fi

  cat >$i/Makefile <<END
# This file was generated by configure -- don't edit it!

TMPDIR = $tmpdir
top_srcdir = $srcdir
libdir = $libdir
ccifdir = $ccifdir
lapackdir = $lapackdir
bindir = $bindir
RANLIB = $RANLIB
FC     = $FC
FOPTIM = $FOPTIM
COPTIM = $COPTIM
XFFLAGS = $XFFLAGS
XCFLAGS = $XCFLAGS
FFLAGS = \$(FOPTIM) \$(XFFLAGS)
XCIF_LIB = $XCIF_LIB
XLAPACK_LIB = $XLAPACK_LIB
LDFLAGS = $LDFLAG -lccp4 $XLDFLAGS \$(XCIF_LIB) \$(XLAPACK_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
TIDY   = $TIDY
$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
  # It is important for some systems that the files
  # configure.in, Makefile.am, aclocal.m4, configure,
  # and Makefile.in have the correct timestamp relative
  # to each other (Clemens Vonrhein)
  echo "Updating modification times for configuration files"
  echo "Please wait..."
  for i in configure.in Makefile.am aclocal.m4 configure Makefile.in; do
    touch $i && sleep 1
  done
  echo "...done."
  echo
  echo "configure $xopts --libdir=${libdir}"
  ./configure $xopts --libdir=${libdir} 
  echo
  cd ../../libjwc/libjwc_c
  echo "Running separate configure for libjwc_c lib"
  echo "configure $xopts --libdir=$(libdir)"
  ./configure $xopts --libdir=${libdir}
  echo
  cd ../libjwc_f
  echo "Running separate configure for libjwc_f lib"
  echo "configure $xopts --libdir=$(libdir)"
  ./configure $xopts --libdir=${libdir}
  echo
  cd ../../..
  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" 
    echo "* instead of sfch_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
test "$with_lapack" = yes && opts="$opts --with-lapack" || true
test "$force_lapack" = yes && opts="$opts=FORCE"

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" \\
TIDY="$TIDY" \\
$srcdir/configure --srcdir=$srcdir --bindir=$bindir --libdir=$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

##########
# FSPLIT
##########
# PJX: fsplit.c is included in the src/fsplit_ directory, since some
# OSFs and Linux apparently don't have their own.
#
# We could check for the presence of a system or pre-installed fsplit
# using `if fsplit </dev/null >/dev/null; then true' though this
# may not be 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'
#
# However let's not even look for an existing fsplit - just build it in
# bindir and use ${bindir}/fsplit in lib/src/Makefile and src/Makefile 
if test ! -x ${bindir}/fsplit ; then
  echo "! Attempting to build fsplit ...."
  cd src/fsplit_
  $CC -o fsplit fsplit.c
  if ./fsplit </dev/null >/dev/null; then
    mv fsplit $bindir
    echo "! fsplit installed in $bindir"
  else
    echo "! Automatic installation of fsplit failed"
    echo "! The CCP4 library cannot be built without it"
    echo "! You will need to install fsplit into $bindir manually"
    echo "! before attempting the rest of the installation"
  fi
  cd ../..
fi
# The following is commented out (since even if they have a locally
# available fsplit, it won't be used now) but not removed at present
# for the sake of reference - pjx.
#    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

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

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


#

