#! /bin/sh
#ident	"@(#)as.master	2.6	(Motorola VA Base)"
#ident "@(#)m88k:as	1.4 1/19/89 12:14:46 Copyright 1988 UniSoft Corp. Motorola"
# as  881118 M88000 sgs tools

#
#	Copyright (c) 1988 Motorola Inc.
#	All Rights Reserved
#
#	Copyright (c) 1988 Unisoft Corporation.
#	All Rights Reserved
#
#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
#	AND UNISOFT CORPORATION.
#
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.
#
# This script built with ROOT set to /
# and SGS set to 
#
#  script to call sifilter with assembler call

#  set default value for sifilter options (override with -F option)

#  for rev C silicon, use "-gcpbnmx"
#  rev D.3, use "-gcx"
#  rev D.5, use "-gcjw"
#  rev E.2, use "-gcE"
#  for code to run on multiprocessors, add b option
#  no workarounds at all: use "-0"

#  note that the silicon filter will be called unless SIFOPTS is set to
#  "-0", so don't just set it to null!

	SIFOPTS="-0"

#  set $TOOLDIR, $TMPDIR, if not passed in from environment:

	TOOLDIR=${TOOLDIR:-/};
	TMPDIR=${TMPDIR:-/tmp}

#  set traps for normal, interrupt exits

	trap "rm -f $TMPDIR/sif$$ $TMPDIR/sifx$$ ; exit 0" 0
	trap "rm -f $TMPDIR/sif$$ $TMPDIR/sifx$$ ; exit 0" 2

#  if this as script is prefixed, pull off the prefix for /lib/as call:

	SGS=`basename $0 as`
	if [ x$SGS = xas ]
	then
		SGS=
	fi

#  handle options: -F for sifilter, -N for filehack, other "as" options

	ASOPTS=
	REALNAME=
	while true; do
		case $1 in
			-o)	ASOPTS="$1 $2"
				shift
				shift
				;;
			-N)	shift
				REALNAME=$1
				shift
				;;
			-F)	shift
				SIFOPTS="-$1"
				shift
				;;
			*)	break
				;;
		esac
	done

#  if there was not a -o option on the call, generate one from input file name

	if [ "x$ASOPTS" = x ]
	then
		ONAME=`dirname $1`/`basename $1 .s`.o
		ASOPTS="-o $ONAME"
	fi

#  BEGIN PROCESSING INPUT FILE:  input file is $1

#  from this point on, the input file will always be $TMPDIR/sif$$;
#  work is done into $TMPDIR/sifx$$, which is then moved to $TMPDIR/sif$$
#  for the next "step".  This is a little extra work, but it avoids
#  surprises if you decide to comment out one step of the process...

#  if $REALNAME set, fix up "file" directive in .s file:
#  (required by "sdb")

	if [ x$REALNAME != x ]
	then
		REALNAME=`basename $REALNAME`
		echo "	file \"$REALNAME\"" >$TMPDIR/sif$$
		egrep -v "^	file" $1 >> $TMPDIR/sif$$
	else
		cp $1 $TMPDIR/sif$$
	fi

#  execute silicon filter, if required

	if [ x$SIFOPTS != x-0 ]
	then
		${TOOLDIR}/bin/${SGS}sifilter $SIFOPTS \
			$TMPDIR/sif$$ $TMPDIR/sifx$$ || exit $?
		mv $TMPDIR/sifx$$ $TMPDIR/sif$$
	fi

#  execute actual assembler, using real or generated -o option

	${TOOLDIR}/lib/${SGS}as $ASOPTS $TMPDIR/sif$$ || exit $?

#  traps will remove the temp files, whether we fall out cleanly or interrupt
