#!/bin/csh
################################################################
## Copyright (C) 1994,1995,1997,1998 Joergen Backelin
##
## Bergman is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY.  No author or distributor
## accepts responsibility to anyone for the consequences of using it
## or for whether it serves any particular purpose or works at all,
## unless (s)he says so in writing.  Refer to the Bergman General
## Public License for full details.

## Everyone is granted permission to copy, modify and redistribute
## bergman, but only under the conditions described in the
## Bergman General Public License.   A copy of this license is
## supposed to have been given to you along with bergman so you
## can know your rights and responsibilities.  It should be in a
## file named copyright.  Among other things, the copyright notice
## and this notice must be preserved on all copies.
################################################################
pushd $2


## Set variables.

cat >tmp1 <<EOspecsrc
setenv bmroot $2
setenv reduce $1
setenv MACHINE alpha
EOspecsrc

## You must edit next line, if $bmauxil no longer is the same as $bmroot/auxil.
cat auxil/head1 tmp1 auxil/envtail2 >shellenv

source shellenv


## Clean up the exe directory, and move there.

##### RISKY!
#rm $bmexe/*
rm tmp*
rm -f $bmexe/shellenv
mv shellenv $bmexe
cd $bmexe
rm -f bergman* tmp* versmacr.sl
cp -p $bmauxil/versmacr.sl .


echo Creating the scripts

cat>tmp2 <<EObergman
source $bmexe/shellenv
#exec $bmexe/$bmvers
exec $reduce/psl/bpsl -td 8000000 -f $bmexe/$bmvers.img
EObergman

cat $bmauxil/head1 tmp2 >bergman

chmod +x bergman


## Set up the specific (context depending) extra source files.
## specmode, speclisp are mandatory; the others just ignored if non-existing.

rm -f specmode.sl specmacr.sl speccmp1.sl speccmp2.sl speclisp.sl
rm -f specbrg1.sl specbrg2.sl specbrg3.sl
cp -p $bmmkdir/setmode.sl specmode.sl
cp -p $bmmkdir/setmacr.sl specmacr.sl
cp -p $bmmkdir/setlisp.sl speclisp.sl
#cp -p $bmmkdir/setbrg1.sl specbrg1.sl
cp -p $bmmkdir/setbrg2.sl specbrg2.sl
#cp -p $bmmkdir/setbrg3.sl specbrg3.sl
cp -p $bmmkdir/setcmp1.sl speccmp1.sl
cp -p $bmmkdir/setcmp2.sl speccmp2.sl

## alg2lsp.sl might not be able to run in some set-ups, since it uses
## table driven scanners.
rm -f $bmload/alg2lsp.b alg2lsp.sl
cp -p $bmsrc/alg2lsp.sl alg2lsp.sl

## You may have added patches.sl and/or local.sl.


echo Setting up auxiliary files.
rm -f $bmshells/mkprimefile.old
mv $bmshells/mkprimefile $bmshells/mkprimefile.old
cat $bmauxil/head3 $bmauxil/head2 $bmauxil/mkprimefile>$bmshells/mkprimefile
chmod a+x $bmshells/mkprimefile


echo Compiling the binaries ...

rm -f comp*
cat $bmauxil/hook1 $bmauxil/compile.sl > compile.sl
cat $bmauxil/hook1 $bmauxil/compan.sl > compan.sl
rm -f $bmlog/ralphac*.old
mv $bmlog/ralphac.log $bmlog/ralphac.old
mv $bmlog/ralphaca.log $bmlog/ralphaca.old
$reduce/reduce <compile.sl >$bmlog/ralphac.log
$reduce/reduce <compan.sl >$bmlog/ralphaca.log

echo / / ... done.


echo Creating bergman ($bmvers)

rm -f bmtop.sl
cat $bmauxil/hook1 $bmauxil/bmtop.sl >bmtop.sl
rm -f $bmlog/ralphabt.old
mv $bmlog/ralphabt.log $bmlog/ralphabt.old
$reduce/reduce <bmtop.sl >$bmlog/ralphabt.log


## Clean up, and return

rm -f tmp*
popd
