#
#	$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.
#	Configure and make the UNIX Operating System with various devices
# 	if called with no arguments then build any kernel it can find
#	otherwise look for a configuration directory of the corresponding
#	name.
#
#	$Header: :mkuts 1.21 90/02/22 $
#
# trap "exit 1" 1 2 3 15
MAKE=${MAKE:-make}
CONFIG=${CONFIG:-config}
SRCDIR=${SRC:-$ROOT/usr/src}/uts

if [ ! -d ${SRCDIR} ]
then
	SRCDIR=$ROOT/etc/conf/uts
fi

# Make sure there really is work to be done in this view
#
if [ ! -d ${SRCDIR} ]
then
        exit 0
fi

if [ $# = 1 ]
then
	GENERIC=$1
	MACHS=""
	CONFS=""
elif [ $# = 2 ]
then
	GENERIC=""
	MACHS="$1"
	CONFS="$2"
else
	GENERIC=symmetry
	MACHS=""
	CONFS="std"
fi
echo $GENERIC $MACHS $CONFS

# build all machines
cd $SRCDIR
for MACHINE in ${MACHS}
do
	if [ -d ${MACHINE} ]
	then
		for CONFIG_TYPE in ${CONFS}
		do
			if [ -f ${MACHINE}/system.${CONFIG_TYPE} ]
			then
				${CONFIG} -s -m ${MACHINE} -c ${CONFIG_TYPE}
				UNIX=${MACHINE}.${CONFIG_TYPE}
				cd ${UNIX}
				if [ ${CONFIG_TYPE} = std ]
				then
					$MAKE -i -f Makefile install UNIX=unix_${UNIX}
					$MAKE -i -f Makefile lint
				else
					$MAKE -i -f Makefile all UNIX=unix_${UNIX}
				fi
				if [ $? -ne 0 ]
				then
					echo ":mkuts: *** MAKE of ${UNIX} failed"
				fi
				cd ..
			fi
		done
	else
		echo ":mkuts: **** MAKE of ${MACHINE} skipped"
	fi
done

for CONFIG_TYPE in ${CONFS}
do
	if [ -f ${GENERIC}/system.${CONFIG_TYPE} ]
	then
		${CONFIG} -m ${GENERIC} -c ${CONFIG_TYPE}
		if [ $? -ne 0 ]
		then
			echo ":mkuts: *** ${CONFIG_TYPE} config failed"
		else
			UNIX=${GENERIC}.${CONFIG_TYPE}
			cd ${UNIX}
			if [ ${CONFIG_TYPE} = std ]
			then
				$MAKE -i -f Makefile install.binary UNIX=unix
				$MAKE -i -f Makefile clean UNIX=unix
			else
				$MAKE -i -f Makefile build.binary \
						UNIX=unix.${CONFIG_TYPE}
				$MAKE -i -f Makefile_clean \
						UNIX=unix.${CONFIG_TYPE}
			fi
			if [ $? -ne 0 ]
			then
				echo ":mkuts: *** MAKE of ${UNIX} failed"
			fi
			cd ..
		fi
	fi
done

date
exit 0
