goto _begin_

@(#)Kmod.sh	1.1+ (Hacked for /misc/newKernel)
Makes an executable image from the KSOS Kernel source files in a 
    local directory.

SHELL PARAMETERS
  None

SHELL VARIABLES
  m		number of errors from compilation

FILES
  KER.i		saved intermediate code (cpp output) -- read-only
  KER.s		saved compiler output
  KER.epl	Kernel explication file for this version
  a.out         output from various processors; finally contains executable
		program
  a.lst         listing file: only compiler diagnostics
  a.err		compile errors (from a.lst)
  a.log         trace output

: _begin_

log -b a.log "[Kmod]"

onintr clean

= m 0

if -w KER.epl then
    log -e a.log "?Writable KER.epl exists -- remove before building"
    exit 1
endif
if ! -r KER.epl then
    log -e a.log "%Cannot read KER.epl -- building without revision number"
    cp /ksos/bin/data/Mnoepl ./KER.epl
    chmod 444 KER.epl
endif

get -s /misc/newKernel/udf/s.BUILD.mod
log a.log ">cpp"
if -r KER.i rm -f KER.i
/lib/cpp -P KER.mod >KER.i
rm -f BUILD.mod

rm -f a.out a.lst

log a.log ">mfe"
/ksos/distr/mod/V2Fmfe -t430 KER.i >a.lst
= m $r
if $m -ne 0 goto bottom

log a.log ">mbe"
/ksos/distr/mod/V2Fmbe -t430 KER.i >>a.lst
= m $r
if $m -ne 0 goto bottom

if -r KER.s rm -f KER.s
mv a.out KER.s

log a.log ">modsep"
rm -f KER?*.[os]
modsep -p /ksos/bin -v -o KER KER.s

log a.log ">assembly"
ksosas - -o nuc_front.o nuc_front.s
ksosas - -o nuc_end.o nuc_bits.s nuc.s nuc_end.s
ksosld -i nuc_front.o KER*.o nuc_end.o

: bottom
if $m -gt 0 then
    ferr <a.lst >a.err
else
    rm -f a.err
endif

chmod 444 KER.i KER.s
if -r a.lst chmod 444 a.lst

: clean

rm -f mdict mcode mcodeST modtmp3

log -e a.log "[Kmod: $m error(s)]"
exit $m
