#!/bin/csh -f
#
#  mk-lisp -- script for building full lisp cores.
#
# $Header: mk-lisp,v 1.16 93/08/03 11:08:42 ram Exp $

if ($#argv) then
    if ($argv[1] == "-now") then
	set later = 0
	shift
    else
	set later = 1
    endif
else
    set later = 1
endif

if ($later) then
    set delay = (205 45 15 0)
    set msg = ("in 5 minutes" "in 1 minute" "in 15 seconds" "now")
  nextmsg:
    foreach name (`who | sed -e 's/\([^ ]*\)  *\([^ ]*\) .*/\1:\2/'`)
	echo Building core $msg[1] | write `echo $name | sed -e 's/:/ /'`
    end
    sleep $delay[1]
    shift delay
    shift msg
    if ($#delay) goto nextmsg
endif

if ($#argv) then
	set subdir = $argv[1]
	set features = ($argv[2-])
else
	set subdir = alpha
	set features = ()
endif

if $?CMUCL_ROOT then
	set root = $CMUCL_ROOT
else
	set root = /afs/cs/project/clisp
endif

set dest = $root/build/@sys/$subdir
set src = $root/src/$subdir

if (-e $dest/lisp/kernel.core) then
	set core = $dest/lisp/kernel.core
else
	if (-e /usr/tmp/kernel.core) then
		set core = /usr/tmp/kernel.core
	else
		echo Can\'t find the kernel.core
	endif
endif

if (-e $src/VERSION) then
	set version = `cat $src/VERSION`
else
	set version = `/bin/date | awk '{print $3 "-" $2 "-" $6}'`
endif

if (-e $src/FEATURES) then
	set features = ($features `cat $src/FEATURES`)
endif

echo Building lisp.core version $version from the \`\`$subdir\'\' subdir.
echo "Features: $features"

$dest/lisp/lisp -core $core << EOF
(setf *features* (list* $features *features*))
(setf (search-list "target:") '("$dest/" "$src/"))
(in-package "USER")
(load (open "target:tools/worldload.lisp"))
$version
(quit)
EOF

echo 
