trap "" 1
DESTDIR=${DESTDIR-/usr/vaxv7}
CC=cc

: make sure directory hierarchy exists
(	cd $DESTDIR
	for i in bin etc lib sys usr
	do	if [ ! -d $i ]
		then rm -f $i; mkdir $i
		fi
	done
	cd $DESTDIR/usr
	for i in bin dict games lib
	do	if [ ! -d $i ]
		then rm -f $i; mkdir $i
		fi
	done
	cd $DESTDIR/usr/lib
	for i in lex refer struct term uucp
	do	if [ ! -d $i ]
		then rm -f $i; mkdir $i
		fi
	done
)
cd ..

for i in $*
do 	echo "	======== $i"

	CFLAGS='-O -d2'
	case $i in
	dump.c|dumpdir.c|egrep.y|fgrep.c|ncheck.c|restor.c|sa.c|sort.c) CFLAGS=-O ;;
	as|awk|eqn|f77|lex|lint|llx|pcc|plot|refer|sed|struct|tbl|uucp|yacc) CFLAGS=-O ;;
	esac

	case $i in

	clean)	rm -f *.o core y.tab.c lex.yy.c  ;: Clean unwanted files.
		;;

	*.y)	B=`basename $i .y`
		eval D=`grep " $B\$" Admin/destinations`
		   yacc $B.y  \
		&& $CC $CFLAGS -o $B y.tab.c -lln \
		&& install -s $B $DESTDIR$D/$B
		rm -f y.tab.[co] $B
		;;

	*.l)	B=`basename $i .l`
		eval D=`grep " $B\$" Admin/destinations`
		   lex $B.l  \
		&& $CC $CFLAGS -o $B lex.yy.c -lln \
		&& install -s $B $DESTDIR$D/$B
		rm -f lex.yy.[co] $B
		;;

	*.c)	B=`basename $i .c`
		eval D=`grep " $B\$" Admin/destinations`
		   $CC $CFLAGS -o $B $B.c \
		&& install -s $B $DESTDIR$D/$B
		rm -f $B.o $B
		;;

	*.s)	B=`basename $i .s`
		eval D=`grep " $B\$" Admin/destinations`
		   as -o $B.o $B.s \
		&& $CC -o $B $B.o \
		&& install -s $B $DESTDIR$D/$B
		rm -f $B.o $B
		;;

	*.sh)	B=`basename $i .sh`
		eval D=`grep " $B\$" Admin/destinations`
		install -c $B.sh $DESTDIR$D/$B
		;;

	Admin)	echo Do nothing.
		;;

	ALIASES) echo Establish alias names.
		test -f $DESTDIR/test && ln $DESTDIR/test $DESTDIR/[
		test -f $DESTDIR/ed   && ln $DESTDIR/ed   $DESTDIR/e
		;;

	*)	if [ ! -d $i ]
		then	echo "Don't know what to do with $i."
		else
			cd $i
			   make CC=$CC CFLAGS="$CFLAGS" DESTDIR=$DESTDIR \
			&& make install DESTDIR=$DESTDIR \
			&& make clean
			cd ..
		fi

	esac
done
