#!/bin/sh
#

#
# compile events.hcs via pcemu (don't laugh too hard!)
#  see "README.pcemu" for details
#

PATH=.:/bin:/usr/bin:/usr/local/bin

# tool used to run hcs2's 'compile.exe' dos program under FreeBSD
EMULATOR=HCSpcemu

# 
TARGET=events.bin

#
BACKUP=events.bin.bak

# output of 'compile.exe'
LOG=compile.log

# 'message' from dos when 'compile.exe' is done
FINISH=compile.end

# means of terminating pcemu
KILL=zap\ -u

# specific string returned by hcs2's 'compile.exe' when successful
GOOD=Compile\ complete.\ \ No\ errors.


# remove any previous message
rm -f $FINISH

# backup current events.bin
mv -f $TARGET $BACKUP

# start pcemu in background, its autoexec.bat will run compile
$EMULATOR &

# wait for compile to finish...
until test -f $FINISH
do sleep 1; done

# kill pcemu
$KILL $EMULATOR

# look for errors
if fgrep "$GOOD" $LOG
then
 echo good compile
 exit 0
else
 echo bad compile
 rm -f $TARGET
 exit 1
fi

