#!/bin/csh
################################################################
## Copyright (C) 1994,1996,1998,2005 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.
#rm -f shellenv bergman

cat >tmp1 <<EOspecsrc
setenv bmroot $2
setenv proot $1
setenv MACHINE alpha
source $1/dist/psl-names
EOspecsrc

## You must edit next line, if $bmauxil no longer is the same as $bmroot/auxil.
cat auxil/head1 tmp1 auxil/envtail1 >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 $bmauxil/fullversion
cat $bmauxil/fvstart $bmauxil/version $bmauxil/fvend > $bmauxil/fullversion

rm -f bergman* tmp* versmacr.sl
cp -p $bmauxil/versmacr.sl .

## Create the scripts.
cat>tmp2 <<EObergman
source $bmexe/shellenv
#exec $bmexe/$bmvers
exec $pxk/bpsl -td 10000000 -f $bmexe/$bmvers.img
EObergman

cat>tmp3 <<EObergman
source $bmexe/shellenv
#exec $bmexe/$bmvers
exec $pxk/bpsl -td 500000000000 -f $bmexe/$bmvers.img \$*
EObergman

cat $bmauxil/head1 tmp2 >bergman
cat $bmauxil/head1 tmp3 >largebergman

chmod +x bergman largebergman

## 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.

## Set 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

## Compile the binaries.
rm -f comp*
cp -p $bmauxil/compile.sl .
cp -p $bmauxil/compan.sl .
rm -f  $bmlog/alphac*.old
mv $bmlog/alphac.log $bmlog/alphac.old
mv $bmlog/alphaca.log $bmlog/alphaca.old
$psys/pslcomp <compile.sl >$bmlog/alphac.log
$psys/pslcomp <compan.sl >$bmlog/alphaca.log
#rm -f comp*

## Create bergman
rm -f bmtop.sl
cp -p $bmauxil/bmtop.sl .
rm -f  $bmlog/alphabt.old
mv $bmlog/alphabt.log $bmlog/alphabt.old
$psys/psl <bmtop.sl >$bmlog/alphabt.log
#rm -f bmtop.sl

## Clean up, and return.
rm -f tmp*
popd
