#!/bin/csh
## $local/com/INSTALL_LIKE_BHAM
## $local/popcd.tarfiles/INSTALL_LIKE_BHAM
## Install a linux poplog system to simulate the Birmingham setup
## Aaron Sloman
## 25 Sep 1999

## Revision Notes:
## 22 Apr 2002: changed "rehash" instruction, only needed if not running bash
## 4 Apr 2002 : simplified because of restructuring of tar files
## 28 Oct 2001: corrected minor typos
## Changed 8 Oct 2001, to build saved images like the ones in Birmingham
## Changed 13 Oct 2000, to check before creating links
## Changed 22 Sep 2000, to refer to setup directory
## Also changed to assume poplog already installed.

## Run this in the directory in which popcd.tar has been unpacked
## which could be the poplog CD or the user's hard drive

set tardir=`pwd`

## EDIT THIS LINE IF NECESSARY: location for $poplocal, etc.
set rootdir=/usr/local/poplog

setenv usepop $rootdir/current.poplog

## Location for local saved images
## Version specific
setenv poplocalbin $usepop/poplocalbin

if (! -e $poplocalbin) then
    mkdir $poplocalbin
endif

setenv poplocal $rootdir

setenv local $poplocal/local

if (! -e $rootdir) then
    mkdir $rootdir $rootdir/local

    chmod 755 $rootdir $rootdir/local
endif

# The following should no longer be necessary, as link is now included
# in the poplog tar file
## ## link $local directory to default $poplocal/local
cd $usepop/pop
if (! -e local) then
    echo "creating link to $local in $usepop/pop"
    ln -s $local local
endif

## install link from default location to $poplocalbin
## Poplog system (wrongly) assumes $poplocalbin should be in local
## directory rather than in version specific $usepop directory

if ( ! -e $local/bin ) then
    echo "Creating link to poplocalbin in $local/bin"
    ln -s $poplocalbin $local/bin
endif

echo "links made"
echo "======================================================"
echo "installing packages in $local"

cd $local

cp -p $tardir/COPYRIGHT.html .

mkdir auto lib help teach include data man ref doc

echo "=========================================="
echo ""

echo "YOU SHOULD READ $local/setup/AREADME file"

echo ""
echo "=========================================="
echo ""

echo "Unpacking bham.tar.gz"

zcat $tardir/bham.tar.gz | tar xf -

echo "directories in $poplocal/local/ "

ls -l

echo ""
echo "=========================================="
echo ""

#echo "Unpacking newkit.tar.gz"

#zcat $tardir/newkit.tar.gz | tar xf -

#echo "contents of $poplocal/local/newkit "

#ls -l newkit

## setup  links to newkit startup files
# Make commands: uses prb, uses simlib, uses newkit work in pop11.
#cd $local/lib
#ln -s ../newkit/*.p .
#cd $local

## echo ""
## echo "=========================================="
## echo ""
echo "Unpacking ved_latex.embedded.tar.gz - program files may need to be edited"

zcat $tardir/ved_latex.embedded.tar.gz | tar xf -


## echo ""
## echo "=========================================="
## echo ""
echo "contents of $poplocal/local/com "


echo "READ THESE FILES IN $poplocal/local/com"
echo "README-build-scripts"
echo "README.ENVVARS"


echo ""
echo "=========================================="
echo ""
echo "FINISHED UNPACKING TAR FILES"

echo ""
echo "=========================================="
echo ""
echo "NOW RUNNING mkstartup.local and other build scripts"

source $usepop/pop/com/poplog
echo $poplocalbin

cd com

# Edit as needed
setenv pop_pop11 "-$poplocalbin/startup.psv"

    date
    echo "Building startup.psv"
    echo mkstartup.local
    ./mkstartup.local #1 ESSENTIAL (Make pop11)
    echo "================================================"

    date
    echo mkplog.local
    ./mkplog.local  #2 ESSENTIAL (Make prolog)
##     echo "================================================"
##     date
##     echo mklogic.local
##     ./mklogic.local #3 OPTIONAL (logic tutor for prolog)
    echo "================================================"
    echo ""
    echo ""
    date
    echo mkclisp.local
    echo "IGNORE WARNING MESSAGES WHEN CLISP IS BEING COMPILED"
    echo ""
    echo ""
    ./mkclisp.local #4 ESSENTIAL (Make Common Lisp)
    echo ""
    echo ""
    echo ""
    echo "Ingore all the above warning messages"
    echo ""
    echo ""
    echo "================================================"
##     echo ""
##     echo ""
##     date
##     echo "mkxvedlisp (Xved command for starting in clisp mode)"
##     echo ""
##     ./mkxvedlisp    #5 OPTIONAL (Xved command starting in clisp mode)
##     echo ""
##     echo ""
##     echo ""
##     echo "Ignore all the above warning messages"
##     echo ""
##     echo ""
##     echo "================================================"
    echo ""
    echo ""
    date
    echo "Building pml.psv"
    ./mkpml.local   #6 ESSENTIAL (Make Poplog ML)
    echo ""
    echo ""
    echo "================================================"
    echo ""
    echo ""
    date
    echo "Building xved.psv"
    ./mkxved.local  #7 ESSENITAL (Make Xved starting in pop11 mode)
    echo ""
    echo ""
    echo "================================================"
    date
    echo "Building xvedpro.psv (For starting XVed in prolog mode)"
    ./mkxvedpro     #8 OPTIONAL (Xved command starting in prolog mode)
    echo "================================================"
    echo ""
    echo ""
    date
    echo "Building eliza.psv"
    ./mkeliza.local #9 OPTIONAL
    echo ""
    echo ""
#    echo "================================================"
#    date
#    echo "Building gblocks.psv"
#    ./mkgblocks     #10 OPTIONAL (SHRLDU-type demo simplified)
#    echo "================================================"
#    date
#    echo "Building boole.psv"
#    ./mkboole       #11 OPTIONAL (Propositional logic tutor)
#    echo "================================================"
#    date
#    echo "Building kitchen.psv"
#    ./mkgram.local  #12 OPTIONAL See SHOWLIB gramdemo
#                  ## creates kitchen.psv, for parsing sentences
#                  ## about what went on in the kitchen
#    echo "================================================"
#    date
#    echo "Building poly.psv"
#    ./mkrc_poly   #13  OPTIONAL Poly-spiral demo
#    echo "================================================"
#    date
#    echo "DONE"

    echo "The saved images are in $poplocalbin"

cd ..

echo "BHAM saved images made"
ls -l $poplocalbin

echo ""
echo "=========================================="
echo ""

echo "Setting extra links in $popsys"

ln -s basepop11 $usepop/pop/pop/xvedpro
ln -s basepop11 $usepop/pop/pop/xvedlisp

ls -l $usepop/pop/pop/xved??*

echo ""
echo "=========================================="
echo ""

echo "Building local index files for ENTER sourcefile"

./com/mkind.local

echo "Index files built"

echo ""
echo "=========================================="
echo ""

echo "Setting up up the 'poplog' command in /usr/local/bin"

## If you put poplog somewhere else, you may need to edit this:
ln -s $poplocal/local/setup/bin/poplog /usr/local/bin/poplog


echo ""
echo "=========================================="
echo ""

echo "setting links to poplog 'man' files in /usr/share/man/man1"

## If you put poplog somewhere else, you may need to edit this:
ln -s $poplocal/local/setup/man/man1/*.1 /usr/share/man/man1

echo ""
echo "=========================================="
echo ""
echo "Optional packages not installed"

echo    "emacs.tar.gz"
echo    "newc_dec.tar.gz"
echo    "vedmail.tar.gz"
echo    "pophtmlprimer.tar.gz  (for reading the pop-11 primer in netscape or lynx"

echo ""
echo "=========================================="
echo ""
echo "The following can be fetched from"
echo "http://www.cs.bham.ac.uk/research/poplog/linux-cd"
echo ""
echo    "newkit.tar.gz (SimAgent kit including poprulebase)"
echo    "popvision.tar.gz"
echo    "neural.tar.gz"
echo    "vedgn.tar.gz  (for reading and sending news)"
echo    "contrib.tar.gz (Contributed software and documentation)"
echo   "ctwm-window-manager.tar.gz (A convenient small, fast, tailorable window manager)"
echo    "openmotif-2.1.30-8.i386.rpm (Motif libraries needed for Some tools)"

echo ""
echo "=========================================="
echo ""

echo "Check out poplog by typing"
echo "   rehash (only if you are running tcsh or csh, not if running bash)"
echo "then"
echo "   poplog pop11 "
echo "or"
echo "   poplog xved"
echo "or"
echo '   poplog pop11 ":eliza()"'
echo ""
echo ""

echo ""
echo "=========================================="
echo ""
echo "Look in file checkout.txt, in the original directory"
echo ""
echo ""


cat $tardir/checkout.txt > /dev/tty
