#!/bin/csh -f

# mkreduce --- Make basic REDUCE executable file.

# Author: Anthony C. Hearn.

# source $reduce/util/reduce-names

setenv rexec $reduce/lisp/psl/$MACHINE/red

rm -f $reduce/log/mkreduce.log

if ( -e $rexec/reduce.img ) then
   mv $rexec/reduce.img $rexec/,reduce.img
  else if ( -e $rexec/reduce && `wc -c < $rexec/reduce` >> 10000 ) then
   mv $rexec/reduce $rexec/,reduce
 endif

date > $reduce/log/mkreduce.log

pushd $reduce/lisp/psl/$MACHINE/psl

./bpsl -td 12000000 >>& $reduce/log/mkreduce.log << EOF

(setq symbolfilename* "$reduce/lisp/psl/$MACHINE/psl/bpsl")

(setq loaddirectories* '("" "\$reduce/lisp/psl/$MACHINE/red/"
			    "\$reduce/lisp/psl/$MACHINE/psl/"))

(reclaim)

(setq !*init!-stats!* (list (time) (gtheap nil) (free-bps) nextsymbol))

% Load REDUCE code

% (flag '(atsoc) 'lose)

(dskin "$reduce/packages/support/mkredpsl.sl")

(cond ((and (memq 'sparc lispsystem!*) (getd 'supersparc))(supersparc)))

% Print some statistics

(prog nil
   (reclaim)
   (terpri)
   (prin2 "Time for build: ")
   (prin2 (quotient (difference (time) (car !*init!-stats!*)) 1000.0))
   (prin2t " secs")
   (prin2 "Symbols used:   ")
   (prin2t (difference nextsymbol (cadddr !*init!-stats!*)))
   (prin2 "Heap used:      ")
   (prin2t (difference (cadr !*init!-stats!*) (gtheap nil)))
   (prin2 "BPS used:       ")
   (prin2t (difference (caddr !*init!-stats!*) (free-bps)))
   (prin2 "Heap left:      ")
   (prin2t (gtheap nil))
   (prin2 "BPS left:       ")
   (prin2t (free-bps))
  (setq !*init!-stats!* nil))

% Save an executable dump file

(savesystem "REDUCE" "$rexec/reduce" '((read-init-file "reduce")))

(bye)

EOF

popd

if ( -f $rexec/reduce.img )  then
#  $reduce/util/sparsify $rexec/reduce.img
   chmod o+r $rexec/reduce.img
  else if ( -e $rexec/reduce ) then
#  $reduce/util/sparsify $rexec/reduce
   chmod o+x $rexec/reduce 
endif

date >> $reduce/log/mkreduce.log
