#! /bin/sh

ALL="arcv checknr chfn chsh ckdir clear clock colcrt colrm ctags double \
	expand finger fleece fold from getNAME gets head la last lastcomm \
	leave lock man mkstr more pq printenv prmail pti rewind script \
	setquota soelim sq strings submit sysline tail tod ul unexpand \
	unifdef untmp users vmstat w wc what whereis whoami xstr yes rlogin \
	rsh ruptime rwho telnet groups"
DIRS="Mail compact error ex eyacc l11 m11 msgs ranm tset vgrind vsh whois \
	netstat ftp talk tftp"
IGNORE="lisp pwhash"
REST="pascal"
SCRIPT="astags cxref print pubindex see which"

if [ X$1 = Xclean ]
then
	for each in $DIRS
	do
		(cd $each;make clean)
	done
	(cd pascal/pi;make clean)
	(cd pascal/px;make clean)
	(cd pascal/pxp;make clean)
	rm -f core *.o $ALL
	exit
elif [ X$1 = Xinstall ]
then
	install=1
	shift
fi

. ../DESC

if [ $1 ]
then
	LIST=$*
else
	LIST="$ALL $DIRS $REST $SCRIPT"
fi

if [ $install ]
then
	echo "Installing..."
	for each in $LIST
	do
		echo ===== $each:
		case $each in
			chsh | chfn | vmstat | sysline | me | rlogin | rsh)
				install -s -o root -g su -m 4711 $each /usr/ucb ;;
			w)
				install -s -o root -g su -m 4711 $each /usr/ucb
				rm -f /usr/ucb/uptime
				ln /usr/ucb/w /usr/ucb/uptime ;;
			arcv | checknr | ckdir | clear | clock | ctags | \
			colcrt | colrm | double | expand | finger | fleece | \
			fold | from | getNAME | gets | head | la | last | \
			lastcomm | leave | lock | man | mkstr | more | pq | \
			printenv | prmail | pti | rewind | script | setquota | \
			soelim | sq | strings | submit | tail | tod | ul | \
			unexpand | unifdef | untmp | users | wc | what | \
			whereis | whoami | xstr | yes | ruptime | rwho | \
			telnet | groups)
				install -s -o bin -g bin -m 711 $each /usr/ucb ;;
			Mail | compact | error | ex | eyacc | l11 | m11 | \
			msgs | ranm | tset | vgrind | vsh | whois | ftp | \
			netstat | talk | tftp)
				(cd $each;make install) ;;
			pascal)
				(cd $each/pi;make install)
				(cd $each/px;make install)
				(cd $each/pxp;make install) ;;
			lisp | pwhash)
				echo 'unable to install $each.' ;;
			astags | cxref | print | pubindex | see | which)
				install -c -o bin -g bin -m 755 $each.sh /usr/ucb/$each ;;
			*)
				echo "don't know how to install $each." ;;
		esac
	done
	exit
fi

MK="make LFLAG=$LFLAG FP=$FP"
CDMK="make PDP=$PDP LFLAG=$LFLAG CRT=$CRT FP=$FP all"
CDOVMK="make OV=-V PDP=$PDP LFLAG=$LFLAG CRT=$CRT FP=$FP ovall"

echo 'Compiling...'
for each in $LIST
do
	echo ===== $each:
	case $each in
		arcv | checknr | chfn | chsh | ckdir | clock | colcrt | \
		colrm | ctags | double | expand | finger | fleece | \
		fold | from | getNAME | gets | head | last | leave | lock | \
		man | mkstr | printenv | prmail | pti | rewind | script | \
		setquota | soelim | sq | strings | submit | tail | tod | \
		unexpand | unifdef | untmp | users | vmstat | w | wc | what | \
		whereis | whoami | xstr | yes | lastcomm | pq | la | more | \
		ul | clear | sysline | rlogin | rsh | ruptime | rwho | \
		groups | telnet)
			$MK $each ;;
		astags | cxref | print | pubindex | see | which)
			echo "$each is a shell script ($each.sh)." ;;
		compact | error | l11 | msgs | ranm | tset | vgrind | vsh | \
		whois | ex | ftp | netstat | talk | tftp)
			(cd $each; $CDMK) ;;
		Mail | eyacc)
			if [ $PDP = 70 ] 
			then
				(cd $each; $CDMK)
			else
				(cd $each; $CDOVMK)
			fi ;;
		m11)
			if [ $PDP = 70 ]
			then
				(cd $each; $CDMK)
			else
				"echo at.sml must be edited for nonseparate I/D CPUs"
			fi ;;
		pascal)
			(cd pascal/pi; $CDMK)
			(cd pascal/px; $CDMK)
			(cd pascal/pxp; $CDMK) ;;
		pwhash)
			echo "Look at the pwhash system before making." ;;
		*)
			echo "don't know how to make $each." ;;
	esac
done
