4.3BSD/usr/contrib/icon/Icon-setup

modfiles="tran/Makefile iconx/Makefile bin/Makefile h/config.h \
	samples/Test test/Test port/Runtest port/Trantest port/Linktest \
	libtest/Proctest src/cmd/Makefile \
	src/lib/Makefile samples/Test test/Test \
	icon-pi Pimakefile"
editor="ed - "
iroot=`pwd`
echo Icon root directory is $iroot .
echo Getting generic copies of all files ...
for i in $modfiles
do
	cp $i.gen $i
done
rm -f functions/ranlib operators/ranlib lib/ranlib rt/ranlib pilib/ranlib
wholist=
ldlist=
hoststr=
somehost=
hzrate=60
nofp=
sys=
fork=fork
interpex=
ibin="$iroot/bin"
echo "#define OPTIONS \"$*\"" >>h/config.h
echo Scanning arguments ...
while test $1
do
	case $1 in
		-pdp11)
			if test -n "$sys"
			then
				echo "Only one of -vax, -pdp11, or -port is allowed."
				echo "Try again."
			exit
			fi
			sys=pdp11
			wholist="$wholist PDP11"
			ldlist="$ldlist -i";;
		-vax)
			if test -n "$sys"
			then
				echo "Only one of -vax, -pdp11, or -port is allowed."
				echo "Try again."
			exit
			fi
			sys=vax
			wholist="$wholist VAX";;
		-port)
			if test -n "$sys"
			then
				echo "Only one of -vax, -pdp11, or -port is allowed."
				echo "Try again."
			exit
			fi
			sys=port
			wholist="$wholist PORT";;
		-xpx)
			xpx=yes
			wholist="$wholist XPX";;
		-nofp)
			wholist="$wholist NOFP"
			nofp=yes;;
		-interpex)
			interpex=yes
			wholist="$wholist DIREX";;
		-host)
			somehost=x
			shift
			case $1 in
				gethost*)
					wholist="$wholist GETHOST";;
				uname)
					wholist="$wholist UNAME";;
				whoami)
					wholist="$wholist WHOHOST";;
				*)
					hoststr=$1;;
			esac;;
		-hz)
			shift
			hzrate=$1;;
		-vfork)
			fork=vfork;;
		-usg)
			UsG=yes;;
		-az)
			ArizonA=yes;;
		-ibin)
			shift
			ibin=$1;;
		-iconx)
			shift
			IconX=$1;;
		-sets)
			wholist="$wholist SETS";;
		-debug)
			wholist="$wholist DEBUG";;
			
		*)
			echo Bad option \"$1\"
			exit;;
	esac
	shift
done
if test -z "$sys"
then
	echo You must specify -vax, -pdp11, or -port.  Try again.
	exit
fi
if test -z "$somehost"
then
	echo You must specify a value for -host.  Try again.
	exit
fi
IconX=${IconX-"$ibin/iconx"}
if test -n "$interpex"
then
	echo -n $IconX >/tmp/$$
	set xx `/bin/ls -l /tmp/$$`
	rm -f /tmp/$$
	if test $5 -gt 29
	then
		echo "The pathname for iconx, \"$IconX\", is too long."
		echo " It must not exceed 29 characters (it is currently $5)"
		echo " or execution of the interpretable files will mysteriously"
		echo " fail.  See Section 3.1 in the installation document and"
		echo " the -iconx option of icon-setup, and try again."
		exit
	fi
fi
if test -r /usr/include/sys/time.h
then
	echo '#define SYSTIME' >>h/config.h
fi
echo Editing files ...
for i in h/config.h
do
	for def in $wholist
	do
		echo "#define $def" >>$i
	done
	echo "#define IntBin \"$ibin\"" >>$i
	echo "#define Iconx \"$IconX\"" >> $i
	echo "#define IconxHdr \"$ibin/iconx.hdr\"" >>$i
	echo "#define FORK $fork" >>$i
	if test -n "$UsG"
	then
		echo "#define index strchr" >>$i
		echo "#define rindex strrchr" >>$i
	fi
	if test -n "$ArizonA"
	then
		echo "#define AZ" >> $i
	fi
done
for i in h/config.h
do
	echo "#define HZ $hzrate" >>$i
	if test -n "$hoststr"
	then
		echo "#define HOSTSTR \"$hoststr\"" >>$i
	fi
done
for i in iconx/Makefile tran/Makefile Pimakefile
do
	$editor $i <<EOF >/dev/null
	/LDFLAGS/s/LDFLAGS=/LDFLAGS=$ldlist/
	w
	q
EOF
done
$editor Pimakefile <<EOF >/dev/null
/QFORK/
.s:QFORK:$fork:p
w
q
EOF
if test -n "$nofp"
then
	$editor iconx/Makefile <<EOF >/dev/null
	/-lc$/s/$/ -lfpsim/
	w
	q
EOF
fi
if test $sys = "pdp11"
then
	$editor bin/Makefile <<EOF >/dev/null
	/cc -O -N/s/-N//
	w
	q
EOF
fi
for i in port/Runtest port/Trantest port/Linktest libtest/Proctest \
	src/cmd/Makefile src/lib/Makefile \
	samples/Test test/Test
do
	$editor $iroot/$i <<EOF >/dev/null
	/PATH/
	.s:PATH:$ibin:p
	w
	q
EOF
done
if test -n "$UsG"
then
	echo Making dummy ranlib programs for System III/V compatibility ...
	for i in functions operators lib rt pilib
	do
		echo ...$i/ranlib
		cat >$i/ranlib <<EOF
EOF
		chmod 755 $i/ranlib
	done
fi
for i in icon-pi Pimakefile
do
	$editor $iroot/$i <<EOF >/dev/null
	/PATH/
	.s:PATH:$iroot:p
	w
	q
EOF
done
echo Setup is complete.