SRI-NOSC/compile-old

: Modified from Gregs version by substituting /nosc for /usr/sys.
: Also added a test for c.c and l.s existing in SYSTEM-DIR,
: so that the use of mkconf can be subverted entirely.
: This MUST be run with /nosc/conf as current directory
: because the sh and cc needed are special and kept in /nosc/conf.

: compile [ SYSTEM-DIR ] [ load [ UNIX-NAME ] ]
: SYSTEM-DIR may not be "load"
: SYSTEM-DIR is the directory to which the compile will be relative
: load [ UNIX-NAME ] causes an attempt to load a system via loadit

if -r /nosc/conf/mkconf -a -r /nosc/conf/isconf -a \
   -r /nosc/conf/sysfix goto setup
echo "To compile, the files mkconf, isconf, and sysfix must be in the"
echo "/nosc/conf directory.  At least one of these files is missing."
exit
: begin

set A = wk
if $1x = x goto startit
if $1 = load goto startit
set A = $1
shift
: startit


echo configuring $A
date
if ! -r $A mkdir $A
if ! -r $A exit;: it failed
chmod 751 $A
if -r $A/configuration goto std
echo "rk" >$A/configuration
if -r $A/configuration goto std
echo "couldn't create default configuration file -- quitting"
exit
: std
if -r $A/lib rm -f $A/lib
if -r $A/l.s -a -r $A/c.c goto skipmkconf
/nosc/conf/mkconf <$A/configuration
if -r $A/conf.mod sh -c "ed - <"$A"/conf.mod"
echo l.o:
	as l.s
	if -r $A/l.o rm -f $A/l.o
	mv a.out $A/l.o
	rm -f l.s
echo c.o:
	cc -c -O c.c
	if -r $A/c.o rm -f $A/c.o
	mv c.o $A/c.o
	rm -f c.c
sh /tmp/:compile: $A conf -P mch
chmod 644 $A/l.o $A/c.o $A/lib
goto kercompile

: skipmkconf
echo Using $A/l.s and $A/c.c
echo $A/l.o:
if { /nosc/conf/isconf $A/configuration split } as /nosc/conf/data.s $A/l.s
if ! { /nosc/conf/isconf $A/configuration split } as $A/l.s
	if -r $A/l.o rm -f $A/l.o
	mv a.out $A/l.o
echo $A/c.o:
	cc -c -O $A/c.c
	if -r $A/c.o rm -f $A/c.o
	mv c.o $A/c.o
sh /tmp/:compile: $A conf -P mch
chmod 644 $A/l.o $A/c.o $A/lib

: kercompile
echo Unix kernel code:
date
sh /tmp/:compile: $A ken \
	main	alloc	iget	prf	rdwri	slp	subr	text	\
	trap	sig	sysent	clock	fio	malloc	nami	pipe	\
	sys1	sys2	sys3	sys4	acct	badint

echo NCP resident code:
date
sh /tmp/:compile: $A ncpk nrdwr nopcls contab kerbuf ncpio btest
sh /tmp/:compile: $A ncpk -P itol

echo Unix device drivers:
date
: default device drivers -- always present
sh /tmp/:compile: $A dmr bio tty partab kl mem sys
: block device drivers -- disks and tapes
if { /nosc/conf/isconf $A/configuration rk } sh /tmp/:compile: $A dmr rk
if { /nosc/conf/isconf $A/configuration si } sh /tmp/:compile: $A dmr si
if { /nosc/conf/isconf $A/configuration rp } sh /tmp/:compile: $A dmr rp
if { /nosc/conf/isconf $A/configuration hp } sh /tmp/:compile: $A dmr hp
if { /nosc/conf/isconf $A/configuration rf } sh /tmp/:compile: $A dmr rf
if { /nosc/conf/isconf $A/configuration hs } sh /tmp/:compile: $A dmr hs
if { /nosc/conf/isconf $A/configuration rl } sh /tmp/:compile: $A dmr rl
if { /nosc/conf/isconf $A/configuration rx } sh /tmp/:compile: $A dmr rx
if { /nosc/conf/isconf $A/configuration tm } sh /tmp/:compile: $A dmr tm
if { /nosc/conf/isconf $A/configuration ht } sh /tmp/:compile: $A dmr ht
if { /nosc/conf/isconf $A/configuration tc } sh /tmp/:compile: $A dmr tc
sh /tmp/:compile: $A dmr devstart rhstart
: character device drivers -- tty-like devices
if { /nosc/conf/isconf $A/configuration dh } sh /tmp/:compile: $A dmr dhdm dh dhfdm
if { /nosc/conf/isconf $A/configuration dj } sh /tmp/:compile: $A dmr dj
if { /nosc/conf/isconf $A/configuration dz } sh /tmp/:compile: $A dmr dz
if { /nosc/conf/isconf $A/configuration dc } sh /tmp/:compile: $A dmr dc
if { /nosc/conf/isconf $A/configuration ptyc } sh /tmp/:compile: $A dmr pty
: character device drivers -- communication line drivers
if { /nosc/conf/isconf $A/configuration dq } sh /tmp/:compile: $A dmr dq
if { /nosc/conf/isconf $A/configuration du } sh /tmp/:compile: $A dmr du
if { /nosc/conf/isconf $A/configuration dp } sh /tmp/:compile: $A dmr dp
: character device drivers -- all other devices
if { /nosc/conf/isconf $A/configuration lp } sh /tmp/:compile: $A dmr lp
if { /nosc/conf/isconf $A/configuration cr } sh /tmp/:compile: $A dmr cr
if { /nosc/conf/isconf $A/configuration pc } sh /tmp/:compile: $A dmr pc
if { /nosc/conf/isconf $A/configuration dn } sh /tmp/:compile: $A dmr dn

echo IMP driver code:
date
if ! { /nosc/conf/isconf $A/configuration vdh } goto notvdh
	sh /tmp/:compile: $A dvr vdhio vdh
	sh /tmp/:compile: $A dvr -P vdh_swabuf vdh_clock
	goto vdhdone
: notvdh
	sh /tmp/:compile: $A dvr impio
	if { /nosc/conf/isconf $A/configuration acc } \
		sh /tmp/:compile: $A dvr acc
	: LATER ill
	if { /nosc/conf/isconf $A/configuration imp } \
		sh /tmp/:compile: $A dvr imp11a
: vdhdone

: this should be at the very end of the last archive library
sh /tmp/:compile: $A dvr -P CKSUM TRACE

rm -f /tmp/:compile:

if $1x = loadx sh loadit $A $2
echo done!
date
exit

: setup
cat >/tmp/:compile:;goto begin
set A = $1
set B = $2
if $B != dvr goto notdvr
set B = ncpk/drivers
: notdvr
if $3x != -Px goto loop
set P = -P
shift
: loop
if $3x = x exit
shift
set D = $A/
if -r $D$2.c goto compile
set D = $B/
if -r $D$2.c goto compile
set D = /nosc/$D
if -r $D$2.c goto compile
echo $B/$2.c: module not found -- dummy module included
: comperr
as /dev/null
mv a.out $2.o
goto comptest
: compile
echo $B/$2: found as $D$2.c
cc -O -c -L$A:h:$B:/nosc/h:/nosc/$B:/usr/include $P $D$2.c
if $Px != -Px goto comptest
if ! -r $2.i cp $D$2.c $2.i
as $2.i
rm -f $2.i
if ! -r a.out goto loop
mv a.out $2.o
: comptest
if ! -r $2.o goto compfail
size $2.o
ar r $A/lib $2.o
rm -f $2.o
goto loop
: compfail
echo "Compile failed -- placeholder included"
goto comperr