#sccs "@(#)ksh/sh:makesh	1.1"

CMD=${CMD-/bin/make}
ARK=${ARK-lib.a}
#
# This script will make various version of ksh for different machines
# You can invoke this command with a few flags and one argument which
# is the name of the object file for the shell
#
JOBLIB= DBSD= U370= D4_1c= D4_2= DATA=data FIXDATA=text DEVFD= INT16= SXT= NOBUF= VENIX=
MYIO= JOBS=${JOBS-jobs.o} LFLAGS=-n
if	test "$JOBS"
then	JOBS=jobs.o DJOBS=-DJOBS
fi
while	true
do	case $1 in
	-m*)	# job monitor
		shift
		DJOBS=-DJOBS JOBS=jobs.o
		;;
	-r*)	# vi raw only mode
		shift
		VIRAW=-DRAWONLY
		;;
	-4.1c)	# BSD 4.1c
		shift
		JOBLIB=-ljobs DBSD=-DBSD LFLAGS=-z DJOBS=-DJOBS JOBS=jobs.o \
		D4_2=-DBSD_4_2 \
		D4_1c=-DBSD_4_1c
		;;
	-4.2)	# BSD 4_2
		shift
		DBSD=-DBSD LFLAGS=-z DJOBS=-DJOBS JOBS=jobs.o \
		D4_2=-DBSD_4_2
		;;
	-s)	# use stdio routines in stdio.c instead of libc.a
		shift
		MYIO=stdio.o
		;;
	-*)
		echo "USAGE: $0 [-m] [-r] [-4.2] [-s] [name]"
		exit 1
		;;
	*)
		break
		;;
	esac
done
sh=${1-ksh}
if	test -d /dev/fd		# new research UNIX feature
then	DEVFD=-DDEVFD
fi
# if	test -d /dev/sxt	# sxt driver available
# then	SXT=-DSXT
# fi
if	test -f /bin/pdp11 && /bin/pdp11  #pdp11 type machine
then	LDFLAGS=-i INT16=-DINT16 MYIO=stdio.o
fi
if	test -f /vmunix		# true for BSD unix
then	JOBLIB=-ljobs DJOBS=-DJOBS JOBS=jobs.o DBSD=-DBSD LFLAGS=-z
	if	test -f /etc/networks #BSD 4.2
	then	D4_2=-DBSD_4_2 JOBLIB=
	fi
	if	test ! -f /etc/gettytab #BSD 4.1c
	then	D4_1c=-DBSD_4_1c  JOBLIB="$JOBLIB libc.a"
	fi
	if	test -d /usr/suntool #sun workstations
	then	NOBUF=-DNOBUF DATA='data$$'
	fi
elif	test -f /usr/include/sys/stream.h	# true for 8th edition
then	JOBLIB="-ljobs" DJOBS=-DJOBS JOBS=jobs.o DBSD=-DBSD LFLAGS=-z
elif	test -f /venix
then	LFLAGS=-i INT16=-DINT16 FIXDATA="" VIRAW=-DRAWONLY DJOBS= JOBS= VENIX=-DVENIX MYIO=stdio.o
elif	test -f /sys/apollo_logo		# true for APOLLO DOMAIN
then	FIXDATA= DJOBS= JOBLIB= JOBS=  LFLAGS= VIRAW=-DRAWONLY MYIO=apollo.o
elif	test -f /bin/uts && /bin/uts	# uts system
then	if	test -f /bin/u370	# true for u370 on uts
	then	FIXDATA=code DATA=idat U370=U370 NOBUF=-DNOBUF
	fi
elif	test -f /bin/pdp11 && /bin/pdp11
then	INT16=-DINT16 LFLAGS=-i FIXDATA= MYIO=stdio.o
else	if	uname -m 2> /dev/null > /dev/null
	then	set -- `uname -m`
		case "$1" in
		pdp*)
			INT16=-DINT16
			LFLAGS=-i
			FIXDATA=""
			;;
		*370*)
			U370=U370 FIXDATA=code DATA=idat
			VIRAW='-DRAWONLY'
			NOBUF=-DNOBUF
			;;
		ibm-pc*)
			LFLAGS=-i
			INT16=-DINT16
			FIXDATA=""
			VIRAW=-DRAWONLY
			;;
		esac
	else	set -- `uname -r`
		case "$1" in
		[23].*)
			LFLAGS='-i'
			FIXDATA=""
			VIRAW='-DRAWONLY'
			;;
		esac
	fi
fi
$CMD JOBLIB=$JOBLIB DJOBS=$DJOBS JOBS=$JOBS DBSD=$DBSD U370=$U370 \
	LFLAGS=$LFLAGS ARK=$ARK VIRAW=$VIRAW DEVFD=$DEVFD NOBUF=$NOBUF\
	D4_1c=$D4_1c D4_2=$D4_2 FIXDATA=$FIXDATA INT16=$INT16 SXT=$SXT \
	MYIO=$MYIO DATA=$DATA VENIX=$VENIX sh=$sh
