#!/bin/sh
# Khoros 1.0.5 installation script for Linux
# by Wolfram Gloger (wmglo@dent.med.uni-muenchen.de) 1994
if [ -z $KHOROS_HOME ] || [ ! -d $KHOROS_HOME ]; then
 echo "Please set the KHOROS_HOME environment variable."
 echo "( e.g. with: export KHOROS_HOME=/usr/local/khoros )"
 exit 0
fi
PATH=$KHOROS_HOME/bin:$PATH
# determine location of the patch file
khoros_linux_dir=`pwd`
if [ ! -f $khoros_linux_dir/patch.Linux ]; then
 echo "Please start the install.Linux script from the"
 echo "directory the patch.Linux file is stored in."
 exit 0
fi
# determine gcc location
# (a neat gcc option, isn't it)
gcc_dir=`gcc -print-libgcc-file-name`
gcc_inc_dir=`dirname $gcc_dir`/include
echo
echo "Khoros for Linux installation"
echo
# check for /lib/cpp
if [ ! -x /lib/cpp ]; then
 echo "Please create a symbolic link:"
 echo "ln -sf `dirname $gcc_dir`/cpp /lib/cpp"
 echo "(as root)  Then try again."
 exit 0
fi
# apply the patch
cd $KHOROS_HOME
if grep Linux src/PatchLevel; then
 echo "Patch to source seems to be already applied."
else
 echo "Make sure you have the following installed:"
 echo "- Khoros 1.0.5 source"
 echo "- Xfree86 binaries & development package"
 echo "- f2c Fortran to C converter"
 echo "- flex, yacc, /bin/csh (a link to tcsh will do)"
 echo "- Linux DLL tools in /usr/dll"
 echo
 echo "Apply the Linux patches to Khoros now (Y/N)?"
 read ans;
 if [ x$ans = xY ] || [ x$ans = xy ]; then
  rm -f $KHOROS_HOME/man/utils/tmac/tmac.anc
  if patch -p0 < $khoros_linux_dir/patch.Linux; then
   echo "Patch successfully applied."
  else
   echo "Patch failed !  Look at the .rej files."
   echo "They should indicate what went wrong."
   find . -name "*.rej" -print
   exit 0
  fi
 else
  echo "Patch not applied.  Installation aborted."
  exit 0
 fi
fi
# check for the DLL jump configuration files
if [ ! -d src/Lib/jump ]; then
 echo "Extracting DLL configuration files from jump.tar..."
 tar xvf $khoros_linux_dir/jump.tar
fi
# create directories
if [ ! -d bin ]; then
 mkdir bin;
fi
if [ ! -d lib ]; then
 mkdir lib;
fi
# install the f77 shell script
if [ -f $khoros_linux_dir/f77 ]; then
 echo "Would you like to use the supplied \"f77\" shell script (Y/N)?"
 read ans;
 if [ x$ans = xY ] || [ x$ans = xy ]; then
  cp $khoros_linux_dir/f77 bin
  chmod a+x bin/f77
  echo "f77 script installed in $KHOROS_HOME/bin".
 else
  echo "f77 script not installed - you must have your own one."
 fi
fi
# vman macros
if [ ! -f $KHOROS_HOME/man/utils/tmac/tmac.anc ]; then
 echo "Creating macros for vman..."
 $KHOROS_HOME/man/utils/tmac/customize
 echo "Done."
fi
echo
echo "You've now reached the point of no return."
echo "Enter 'A' to abort, anything else to continue..."
read ans;
if [ x$ans = xA ] || [ x$ans = xa ]; then
 echo "Install script aborted."
 exit 0
fi
# now we start the compilation...
cd src
nohup nice make World KHOROS_HOME=$KHOROS_HOME BOOTSTRAPCFLAGS="-DSYSV\
 -DSYSV386 -DGCC_INC_DIR='\\\"$gcc_inc_dir\\\"'" > make.World 2>&1 &
echo
echo "You can now execute:"
echo "tail -f $KHOROS_HOME/src/make.World"
echo "to watch the compiling progress."
echo "It takes several hours to complete !"
exit 0
