Listener/Listener/make/orca-asm
2021-07-16 12:37:38 -04:00

103 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
TMPFILE=/tmp/orca-macgen.$$
ERROUTPUT=/tmp/orca-asm-errs.$$
FILENAME="$1"
shift
DESTBASENAME="$1"
shift
if echo $FILENAME | grep -v '\.s$' > /dev/null
then
echo Expected second argument to be a *.s file but got $FILENAME
exit 1
fi
SRCBASENAME=`echo $FILENAME | sed 's/\.s$//'`
SRCMACROSNAME="${SRCBASENAME}.macros"
SRCROOTNAME="${SRCBASENAME}.ROOT"
SRCOBJNAME="${SRCBASENAME}.a"
DESTMACROSNAME="${DESTBASENAME}.macros"
DESTDEPSNAME="${DESTBASENAME}.macros.d"
DESTROOTNAME="${DESTBASENAME}.ROOT"
DESTOBJNAME="${DESTBASENAME}.a"
$ORCA --trace-gsos macgen $MACGENFLAGS "$FILENAME" "$SRCMACROSNAME" $MACGENMACROS < /dev/null 2> $TMPFILE
RESULT=$?
sed '/^[A-Za-z][A-Za-z]*(.*)$/d' $TMPFILE >&2
if [ "$RESULT" -ne 0 ]
then
rm -f "$TMPFILE"
rm -f "$SRCMACROSNAME"
exit $RESULT
fi
DEPS=`awk '
/^FastFileLoad/ {
sub(/^FastFileLoad\(/, "");
sub(/\)$/, "");
print}' $TMPFILE | sort -u | while read FILE
do
if [ -f "$FILE" ]
then
echo $FILE
fi
done | tr '\012' ' '`
rm -f $TMPFILE
DIRNAME=`dirname $FILENAME`
BASENAME=`basename $FILENAME .s`
pushd "$DIRNAME" > /dev/null
$ORCA assemble $* keep="${BASENAME}" "${BASENAME}.s" 2> $ERROUTPUT
RESULT=$?
popd > /dev/null
if [ -s $ERROUTPUT ]
then
RESULT=1
awk '
{
print $0
}
/^Error /{
$1=""
$2=""
LINENO=$3
$3=""
printf("%s/%s:%d:0: error: %s\n", PWD, FILE, LINENO, $0)
}
' "PWD=`pwd`" "FILE=${BASENAME}.s" $ERROUTPUT
fi
rm -f $ERROUTPUT
if [ "$RESULT" -ne 0 ]
then
rm -f "$SRCROOTNAME"
rm -f "$SRCMACROSNAME"
rm -f "$SRCOBJNAME"
rm -f "$DESTROOTNAME"
rm -f "$DESTMACROSNAME"
rm -f "$DESTOBJNAME"
rm -f "$DESTDEPSNAME"
exit 1
fi
mkdir -p `dirname "$DESTROOTNAME"`
mv -f "$SRCROOTNAME" "$DESTROOTNAME" 2> /dev/null
mv -f "$SRCMACROSNAME" "$DESTMACROSNAME" 2> /dev/null
mv -f "$SRCOBJNAME" "$DESTOBJNAME" 2> /dev/null
cat > $DESTDEPSNAME << EOF
$DESTROOTNAME: $DEPS
EOF
exit 0