# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#ident	"$Header: :mkstand 1.3 89/12/06 $@(#)mk::mkstand	1.17"
#
PARALLEL=4 export PARALLEL
MAKE=${MAKE:-make}
#	If we are in a cross compilation environment then use cross compiler
if [ "$ROOT" != "" ]
then
	if u3b2 || u3b15
	then
		AS=m32as	export AS
		CC=m32cc	export CC
		LD=m32ld	export LD
	fi
else
	AS=as	export AS
	CC=cc	export CC
	LD=ld	export LD
fi
#	Insure that only one machine type is valid
#	Note: the redirection is needed to handle the possibility
#		of a nonexistent file in the $MACH machine list
MACH="vax pdp11 u3b2 u3b u3b15 i386"
(truecnt=0
for mach in $MACH
do
	`$mach`
	if [ $? -eq 0 ]
	then
		truecnt=`expr $truecnt + 1`
	fi
done
if [ $truecnt -ne 1 ]
then
	echo ":mkstand: **** Only one of the following machine types can"
	echo "		be true: $MACH"
	exit 1
fi ) 2>/dev/null
#
places=${places-$ROOT/etc/places}
if [ -r $places ]
then
	. $places
else
	SRC=${SRC-$ROOT/usr/src}
	LSRC=${LSRC-$ROOT/usr/lsrc}
	BIN=${BIN-$ROOT/bin}
	UBIN=${UBIN-$ROOT/usr/bin}
	LBIN=${LBIN-$ROOT/usr/lbin}
fi

# see if there is really work for us to do in this view
#
if [ ! -d $SRC/stand ]
then
        exit 0
fi


LDFILE=${LDFILE-${SRC}/ldflags}
# Initialize default flag values:
#	fflag	- controls the FFLAG varible. It is set to either null
#		(use hardware floating point) or '-f' (use software
#		simulation floating point).
#	sflag	- shared text, turns off the -i and -n loader options.
#		Saves the intermediate .c file from a yacc or lex in
#		<filename>.x for later :mkcmd runs.
#	ldlibs	- shared library flag. It is either "-lnsl_s" (build w/the
#		shared libnsl_s.a) or "-lc_s -lnsl_s" (build w/both 
#		shared libc_s.a and libnsl_s.a). Default is both.
#	iflag	- seperate I&D space. It is either set to '-i' (when building
#		certain commands on a 16-bit machine (e.g. PDP11/70)
#		or null (for all other cases).
fflag=
sflag=
iflag=
#ldlibs=${LDLIBS:-"-lc_s -lnsl_s"}
ldlibs=
ldflags=
for opt in $*
do
	case $opt in

	-f)	fflag="-f"
		;;

	-s)	sflag=-s
		yaccrm="YACCRM=:"
		iflag=
		;;

	-*)	echo ":mkstand; **** unknown option '$opt' - ignored"
		;;

	*)	break
		;;
	esac
	shift
done
#
#	Process remaining arguments as source that needs to be built.
#	The three interesting variables are:
#	B	- basename of each argument
#	BASE	- basename of each option with its dot suffix removed
#	OBJ	- file to be installed if the build is successful
#
cd $SRC/stand
#	Local version takes precedence over official version
	echo "\n======== stand"
#
		CMD="$MAKE -b -f stand.mk LDLIBS='$ldlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" install"
		if [ "$ldflags" ]
		then	CMD="$CMD LDFLAGS='$ldflags'"
		fi
		echo "$CMD"
		if eval $CMD
		then	ret=0
		else	ret=1
		fi
		CMD="$MAKE -b -f stand.mk LDLIBS='$ldlibs' IFLAG=\"$iflag\" FFLAG=\"$fflag\" $yaccrm clobber"
		echo "$CMD"
		eval $CMD
		if [ $ret -ne 0 ]
		then	echo "**** Build of stand failed ($MAKE)"
		fi
wait
date
