#! /.bin.SYSV/sh

Syslist=$ROOT/etc/syslist
if [ ! -f $Syslist ] ; then
	echo "ERROR: can't make commands without $Syslist"
	exit 1
fi
cd $ROOT/usr/src/cmd

for i in $* ; do
	echo "================ Building $i ================"
	if [ ! -d $i ] ; then
		echo "ERROR: $i is not a directory"
		continue
	fi
	InstallDir=`egrep /$i\$ $Syslist`
	if [ "$InstallDir" = "" ] ; then
		InstallDir=$ROOT/usr/bin
	else
		InstallDir=$ROOT/`echo $InstallDir | sed -n -e 's;\(.*/\).*;\1;p'`
	fi
	if [ -f $i/$i.mk ] ; then
		cd $i
		make -e -f $i.mk install INSDIR=$InstallDir
		if [ $? -ne 0 ] ; then
			echo "ERROR: failed to build $i"
		else
			make -e -f $i.mk clobber
		fi
		cd ..
	else
		echo "WARNING: No makefile found in $i"
	fi
	echo "================ Finished $i ================"
done
