#! /bin/sh
#
#$Header:make.ws 12.0$
#$ACIS:make.ws 12.0$
#$Source: /ibm/acis/usr/sys/conf/RCS/make.ws,v $
#
# shell script to generate a workstation binary with the debugger and
# symbol table merged in.
#
input=vmunix
output=$input.dbg
VMRDB=../rtstand/obj/rdb.out
VMRDB=../rtstand/rdb.out
OMERGE=/usr/ibm/omerge

rm -f $output

echo "Linking kernel with debugger in $VMRDB"

nm -n $input > $input.nm || exit 1
echo "symbol table produced in $input.nm"

rm -f $input.out
cp $input $input.out || exit 1

# get the offsets and positions of the debugger 
# we use the current makefile to define the appropriate symbols

defined=`grep "IDENT=" Makefile | sed 's;IDENT=;;`
eval `unifdef $defined ../rt/rdb.h | awk ' $1 == "#define" { print $2 "=" substr($3,3) } ' `
echo "Merging debugger (from ${VMRDB}) into $input.out..."
${OMERGE} -p2048 -o0x${RDB_RELOC?} -e0x${RDB_END?} ${VMRDB} $input.out || exit 1

# convert NCS symbols if necessary
../conf/fixsyms $input.nm $input.snm || exit 1

# following sed makes the 'int' routines visable and also changes the
# virtual kernel addresses back into real addresses
( sed -e 's;^e;0;' -e 's; int; _int;' -e 's;mcount;_mcount;' $input.snm ) |
	/usr/ibm/makesym -h > $input.sym || exit 1

echo "Merging symbol table (from $input.sym) into $input.out..."
${OMERGE} -p2048 -o0x${RDB_SYMTAB?} -l0x${RDB_SYMLEN?} $input.sym $input.out || exit 1

mv $input.out $output || exit 1
echo "Kernel linked with debugger now in $output"
