
#
#	%Z% %M% %I% %D% %Q%
#
#	Copyright (C) Microsoft Corporation, 1983
#
#	This Module contains Proprietary Information of Microsoft
#	Corporation and AT&T, and should be treated as Confidential.
#
:
#***	stackuse --
#
#	stackuse file [ ... ]
#
PATH=/bin:/usr/bin:

USAGE="stackuse [ -a ] [ -m main ] [ -r fakeref ] [ -s libstack ] file [ ... ]"

#lcm=/lib
#P0=$lcm/p0
#P1=$lcm/p1
lsu=/usr/lib/stackuse
P0=$lsu/p0.su
P1=$lsu/p1.su
PSU=$lsu/psu
SUIL=$lsu/suil
COST=$lsu/cost

ILTMP=/tmp/su$$

trap "rm -f ${ILTMP}*; exit 0" 0
trap "rm -f ${ILTMP}*; exit 1" 1 2 3 15

dflags="-DM_I86SM -DM_SDATA -DM_STEXT"
psizes="-psize 2 -isize 2 -fsize 2"
costflags=
fakcg=
faksu=
set -- `getopt I:D:M:am:r:s: $*`
if [ $? -ne 0 ] ; then
    echo $USAGE 1>&2
    exit 2
fi
while [ $# -ne 0 ] ; do
    case $1 in
    -I|-D)
	p0flags="$p0flags $1 $2"
	shift; shift
	;;
    -M)
	case $2 in
	    s|e)
		;;
	    m)	dflags="-DM_I86MM -DM_SDATA -DM_LTEXT"
		psizes="-psize 2 -isize 2 -fsize 4"
		;;
	    l)	dflags="-DM_I86LM -DM_LDATA -DM_LTEXT"
		psizes="-psize 4 -isize 2 -fsize 4"
		;;
	    *)	echo $USAGE 1>&2
		exit 2
		;;
	esac
	shift; shift
	;;
    -a)
	costflags="$costflags -a"
	shift
	;;
    -m)
	costflags="$costflags -m $2"
	shift; shift
	;;
    -r)
	fakcg="$fakcg -c $2"
	shift; shift
	;;
    -s)
	faksu="$faksu -s $2"
	shift; shift
	;;
    --)
	shift
	break
	;;
    -*)
	echo $USAGE 1>&2
	exit 2
	;;
    *)
	break
	;;
    esac
done

p0flags="-compat $p0flags -I /usr/include -DM_XENIX -DM_SYS3 -DM_I86 -DM_I286 -DM_WORDSWAP -DM_BITFIELDS -W 1"

p1flags="-compat -char 1 $psizes"

psuflags="$psizes"

cg=
su=
rmlist=
for f in $* ; do
    echo "$f:"
    case $f in
    *.c)
	;;
    *)
	continue
	;;
    esac
    b=`basename $f .c`
    $P0 $p0flags -il $ILTMP -f $f
    if [ $? -ne 0 ] ; then
	exit 1
    fi
    $P1 $p1flags -il $ILTMP
    if [ $? -ne 0 ] ; then
	exit 1
    fi
    $PSU $psuflags -il $ILTMP -o $b
    if [ $? -ne 0 ] ; then
	exit 1
    fi
    cg="$cg -c $b.cg"
    su="$su -s $b.su"
    rmlist="$rmlist $b.cg $b.su"
done

# Might want to load fakcg and faksu here rather than at COST so that
# they can create recursion.
# $SUIL -o $ILTMP $cg $fakcg $su $faksu
$SUIL -o $ILTMP $cg $su
if [ $? -ne 0 ] ; then
    rm -f $rmlist
    exit 1
fi

$COST $costflags -c $ILTMP.cg $fakcg -s $ILTMP.su $faksu | fgrep -v " .LEAF"
if [ $? -ne 0 ] ; then
    rm -f $rmlist
    exit 1
fi

rm -f $rmlist
exit 0
