#!/bin/csh -f

set path = ( /usr/lang /usr/bsd /usr/ucb /usr/bin /bin /usr/etc /etc . $path )

set TEMPDIR = /tmp

if (! $?KHOROS_HOME) then
   echo ""
   echo "installit: Error, The environment variable KHOROS_HOME has not"
   echo "           been set. Please set the KHOROS_HOME environment variable"
   echo "           to the top level directory of Khoros, and re-execute"
   echo "           the installit program"
   echo " 	    For more information, please consult the installation"
   echo "           manual file KHOROS_HOME/release/install"
   exit 0
endif


echo ""
echo "                  Khoros 1.0 Installation"
echo "   This script prompts you for installation directories"
echo "   and BOOTSTRAP flags necessary to compile Khoros."
echo "   The compile will take approximately 3 to 5 hours."
echo "   The compile status for Khoros will be logged to the file"
echo "   KHOROS_HOME/src/make.World. You can use the command"
echo "    % tail -f make.World  to watch the compile."
echo ""
echo "    ################################################################"
echo "    # Did you remember to check the Imake configuration            #"
echo "    # parameters in the directory:                                 #" 
echo "    # KHOROS_HOME/repos/config/imake_conf                          #"
echo "    #                                                              #"
echo "    # For information on configuring the Khoros Imake parameters,  #"
echo "    # consult the file 'chapter9' in the directory:                #"
echo "    # KHOROS_HOME/release                                          #"
echo "    ################################################################"
echo ""
echo -n "Do you wish to continue the installation (y/n) [y]: "
set resp = $<
if ($resp == "n" || $resp == "N") then
   echo ""
   echo ""
   echo "Exiting the Khoros installation script...."
   echo ""
   exit 0
endif


if  (! -e Makefile.org) then
    \mv Makefile Makefile.org
endif
#
# Get and Set the directory for the Khoros binaries
#
echo ""
echo ""
echo ""
echo "Enter the directory for Khoros binaries or return for the default:"
echo ""
echo -n  "Default [$KHOROS_HOME/bin]: "
set bindir = $<
if ($bindir == "") set bindir = $KHOROS_HOME/bin

touch $TEMPDIR/bindir.$$
echo $bindir >>  $TEMPDIR/bindir.$$
set new = `sed -e "s/\//\\\//g" $TEMPDIR/bindir.$$`

touch $TEMPDIR/binsed.$$
touch Makefile.bin
echo "/ BINDIR/s/BINDIR = .*/BINDIR = $new/" >> $TEMPDIR/binsed.$$
sed -f $TEMPDIR/binsed.$$ Makefile.org >> Makefile.bin

\rm -f $TEMPDIR/bindir.$$ $TEMPDIR/binsed.$$

if (! -d $bindir) then
  mkdir $bindir
endif

#
# Get and Set the directory for the Khoros libraries
#
echo ""
echo ""
echo ""
echo "Enter the directory for Khoros libraries or return for the default:"
echo ""
echo -n  "Default [$KHOROS_HOME/lib]: "
set libdir = $<
if ($libdir == "") set libdir = $KHOROS_HOME/lib

touch $TEMPDIR/libdir.$$
echo $libdir >>  $TEMPDIR/libdir.$$
set new = `sed -e "s/\//\\\//g" $TEMPDIR/libdir.$$`

touch $TEMPDIR/libsed.$$
touch Makefile.lib
echo "/ LIBDIR/s/LIBDIR = .*/LIBDIR = $new/" >> $TEMPDIR/libsed.$$
sed -f $TEMPDIR/libsed.$$ Makefile.bin >> Makefile.lib

\rm -f $TEMPDIR/libdir.$$ $TEMPDIR/libsed.$$

if (! -d $libdir) then
  mkdir $libdir
endif

#
# Get and Set the directory for the Khoros includes
#

echo ""
echo ""
echo ""
againinc:
echo "Enter the directory for Khoros include files or return for the default:"
echo ""
echo -n  "Default [$KHOROS_HOME/include]: "
set incdir = $<
if ($incdir == "") set incdir = $KHOROS_HOME/include

touch $TEMPDIR/incdir.$$
echo $incdir >>  $TEMPDIR/incdir.$$
set new = `sed -e "s/\//\\\//g" $TEMPDIR/incdir.$$`

touch $TEMPDIR/incsed.$$
touch Makefile.inc
echo "/ INCROOT/s/INCROOT = .*/INCROOT = $new/" >> $TEMPDIR/incsed.$$
sed -f $TEMPDIR/incsed.$$ Makefile.lib >> Makefile.inc

\rm -f $TEMPDIR/incdir.$$ $TEMPDIR/incsed.$$

if (! -d $incdir) then
  echo ""
  echo "Cannot find the Khoros include directory"
  echo "Please re-enter the directory name"
  echo ""
  goto againinc
endif


#
# Get and Set the bootstrap flags
#
echo ""
echo ""
echo ""
echo "Enter any Bootstrapflags necessary to compile Khoros."
echo "The following is a list of known bootstrap flags necessary"
echo "for different architectures."
echo ""
echo "For Mips Machine Use:     -DMips"
echo "For IBM 6000 Machine Use: -D_IBMR2"
echo "For 486 Machine Use:      -DSYSV"
echo "For Ultrix Machine Use:    (none)"
echo "For Apollo Machine Use:    (none)"
echo "For Next Machine Use:      (none)"
echo "For SGI Machine Use:       (none)"
echo "For Sun Machine Use:     -Bstatic {compiling w/ HasSharedLibraries = NO}"
echo "                       or  (none) (compiling w/ HasSharedLibraries = YES}"
echo ""
echo ""
echo -n  "Default []: "
set bot = $<

touch $TEMPDIR/botsed.$$
touch Makefile.bot
echo "/ BOOTSTRAPCFLAGS/s/BOOTSTRAPCFLAGS =.*/BOOTSTRAPCFLAGS = $bot/" >> $TEMPDIR/botsed.$$
sed -f $TEMPDIR/botsed.$$ Makefile.inc >> Makefile.bot

\rm -f $TEMPDIR/botsed.$$


#
# Set the top level src directory for the Khoros includes
#
set topsrc = $KHOROS_HOME/src
touch $TEMPDIR/topsrc.$$
echo $topsrc >>  $TEMPDIR/topsrc.$$
set new = `sed -e "s/\//\\\//g" $TEMPDIR/topsrc.$$`

touch $TEMPDIR/topsed.$$
touch Makefile.top
echo "/ TOP/s/TOP = .*/TOP = $new/" >> $TEMPDIR/topsed.$$
sed -f $TEMPDIR/topsed.$$ Makefile.bot >> Makefile.top

\rm -f $TEMPDIR/topsrc.$$ $TEMPDIR/topsed.$$


\mv Makefile.top Makefile
\rm -f  Makefile.top Makefile.bin Makefile.lib Makefile.inc Makefile.bot

echo ""
echo ""
echo "....Starting the Khoros System Compile...."
echo -n "Do you wish to continue (y/n) [y]: "
set resp = $<
if ($resp == "n" || $resp == "N") then
   echo ""
   echo ""
   echo "Exiting the Khoros installation script...."
   echo ""
   exit 0
endif

set path = ( $KHOROS_HOME/bin $path )

echo ""
echo ""
echo "Configuring the Khoros Manual Pages..."
echo ""
echo ""

#  generate the tmac files so that vman will work 
$KHOROS_HOME/man/utils/tmac/customize &

make -k World KHOROS_HOME=$KHOROS_HOME >& make.World &
