#! /bin/sh
#	2.11BSD script to set up a new kernel configuration directory.
#
#	1997/2/14 - LINEHZ removed from localopts.h.  The clock rate is
#		    now known in _exactly 1_ place in the kernel (param.c)
#		    rather than having references scattered all over the 
#		    place.  Patching 'hz' (and 'mshz') will now do the right 
#		    thing (i.e. change the clock rate on the fly).
#	1996/6/8 - New spl massaging scripts.  They are now 'sed' scripts
#		   rather than 'ed' scripts and are about twice as fast.
#	1995/07/21 - remove XP_PROBE, the kernel no longer probes for disk
#		     type because that information is obtained from the 
#		     disklabel.
#	2/28/95	- fixed errors introduced earlier.  remove the chmod at the
#		  end, rely instead on the system administrator's choice of
#		  umask.
#	2/14/95 - added ingres lock driver.  removed vax cruft.
#
#	1995/11/22 - added software map (SOFUB_MAP) option.

LO=../h/localopts.h

if [ $# -ne 1 ]; then
	echo "usage: $0 machinename"
	exit 1
fi

MACHINE=$1
if [ ! -s $MACHINE ]; then
	echo "$0: unable to read $MACHINE."
	exit 1
fi

if mkdir ../$MACHINE; then
	echo "Creating ../$MACHINE."
	chmod 775 ../$MACHINE
fi

# read in specification file
eval `awk '/^#/ || /^$/ || /^	/ {next} $1 != "" { printf "%s=\\"%s\\"\\n", $1, $2 }' $MACHINE`

if [ ! "$MAXUSERS" ]; then
	MAXUSERS=1
	exit 1
fi

if [ ! "$TIMEZONE" ]; then
	TIMEZONE=480
fi

if [ ! "$DST" ]; then
	DST=1
fi

cat << EOF > $LO
/*
 * This file is generated by the configuration script sys/conf/config.
 *
 * It contains a list the kernel options not prepended to the Makefile
 * as -Dxxxx commands to the compiler.  MAXMEM was moved to param.h leaving
 * only EXTERNALITIMES to be placed in localopts.h
 */

EOF

case $PDP11 in
	GENERIC)
		KERN_NONSEP=NO
		NETFIX=splfix.movb.sed
		SPLFIX=splfix.movb.sed;;
	53|73|83|84|93|94)
		KERN_NONSEP=NO
		NETFIX=splfix.movb+mfps.sed
		SPLFIX=splfix.mfps.sed;;
	44|45|50|55|70)
		KERN_NONSEP=NO
		NETFIX=splfix.movb.sed
		SPLFIX=splfix.spl.sed;;
	*)
		echo "$0: unrecognized PDP11 type $PDP11."
		echo 'use GENERIC, 44, 70, 73'
		exit 1;;
esac

if [ $NKL -lt 1 ]; then
	NKL=1
fi

# Copy in the standard configuration files, boot program,
# makefiles, and cpu-dependent files.

echo "Copying standard files to ../$MACHINE."
if [ $NEC = 0 ]; then
	if [ $INET = YES ]; then
		cp spl/$NETFIX ../$MACHINE/NETSPLFIX
	fi
	cp spl/$SPLFIX ../$MACHINE/SPLFIX
else
	if [ $INET = YES ]; then
		cp spl_3com/$NETFIX ../$MACHINE/NETSPLFIX
	fi
	cp spl_3com/$SPLFIX ../$MACHINE/SPLFIX
fi
cp boot/${BOOTDEV}boot.s ../$MACHINE/boot.s

sed	-e "s/%ROOTDEV%/$ROOTDEV/" \
	-e "s/%SWAPDEV%/$SWAPDEV/" \
	-e "s/%PIPEDEV%/$PIPEDEV/" \
	-e "s/%DUMPDEV%/$DUMPDEV/" \
	-e "s/%DUMPLO%/$DUMPLO/" \
	-e "s/%DUMPROUTINE%/$DUMPROUTINE/" < ioconf.c > ../$MACHINE/ioconf.c

sed	-e "s/%TIMEZONE%/$TIMEZONE/" \
	-e "s/%LINEHZ%/$LINEHZ/g" \
	-e "s/%DST%/$DST/" \
	-e "s/%NBUF%/$NBUF/" \
	-e "s/%MAXUSERS%/$MAXUSERS/" < param.c > ../$MACHINE/param.c

echo "Setting configuration options for $MACHINE."

OPTS="-D${IDENT}"
if [ $FPSIM = YES ]; then
	OPTS="$OPTS -DFPSIM"
fi

if [ $KERN_NONSEP = YES ]; then
	OPTS="$OPTS -DKERN_NONSEP"
fi

if [ $EXTERNALITIMES = YES ]; then
	echo "#define EXTERNALITIMES 1"	>> $LO
fi
if [ $UCB_METER = YES ]; then
	OPTS="$OPTS -DUCB_METER"
fi
if [ $INET = YES ]; then
	OPTS="$OPTS -DINET"
	echo "#define NLOOP	1"	> ../$MACHINE/loop.h
else
	echo "#define NLOOP	0"	> ../$MACHINE/loop.h
fi
if [ $BADSECT = YES ]; then
	OPTS="$OPTS -DBADSECT"
fi
if [ $CHECKSTACK = YES ]; then
	OPTS="$OPTS -DCHECKSTACK"
fi
if [ $DIAGNOSTIC = YES ]; then
	OPTS="$OPTS -DDIAGNOSTIC -DICMPPRINTFS"
fi
if [ $QUOTA = YES ]; then
	OPTS="$OPTS -DQUOTA"
fi
if [ $UCB_CLIST = YES ]; then
	OPTS="$OPTS -DUCB_CLIST"
fi
if [ $PROFILE = YES ]; then
	OPTS="$OPTS -DPROFILE"
fi
if [ $SOFUB_MAP = YES ]; then
	OPTS="$OPTS -DSOFUB_MAP"
fi

echo "Creating device header files."

echo "#define NCSS	$NCSS"		> ../$MACHINE/css.h
echo "#define NDE	$NDE"		> ../$MACHINE/de.h
echo "#define NDH	$NDH"		> ../$MACHINE/dh.h
if [ $CS02 = YES ]; then
	echo "#define CS02 	1"	>> ../$MACHINE/dh.h
fi
echo "#define NDM	$NDM"		>> ../$MACHINE/dh.h
echo "#define NDN	$NDN"		> ../$MACHINE/dn.h
echo "#define NDHU	$NDHU"		> ../$MACHINE/dhu.h
echo "#define NDHV	$NDHV"		> ../$MACHINE/dhv.h
echo "#define NDMC	$NDMC"		> ../$MACHINE/dmc.h
echo "#define NDR	$NDR"		> ../$MACHINE/dr.h
echo "#define NDZ	$NDZ"		> ../$MACHINE/dz.h
echo "#define NEC	$NEC"		> ../$MACHINE/ec.h
echo "#define NEN	$NEN"		> ../$MACHINE/en.h
echo "#define NETHER	$NETHER"	> ../$MACHINE/ether.h
echo "#define NHT	$NHT"		> ../$MACHINE/ht.h
echo "#define NHY	$NHY"		> ../$MACHINE/hy.h
echo "#define NIL	$NIL"		> ../$MACHINE/il.h
echo "#define NIMP	$NIMP"		> ../$MACHINE/imp.h
echo "#define NKL	$NKL"		> ../$MACHINE/cn.h
echo "#define NLP	$NLP"		> ../$MACHINE/lp.h
echo "#define LP_MAXCOL	$LP_MAXCOL"	>> ../$MACHINE/lp.h
echo "#define NPTY	$NPTY"		> ../$MACHINE/pty.h
if [ $INGRES = YES ]; then
	echo "#define NINGRES	1"	> ../$MACHINE/ingres.h
else
	echo "#define NINGRES	0"	> ../$MACHINE/ingres.h
fi
echo "#define NQE	$NQE"		> ../$MACHINE/qe.h
echo "#define NQT	$NQT"		> ../$MACHINE/qt.h
echo "#define NRAM	$NRAM"		> ../$MACHINE/ram.h
echo "#define NRK	$NRK"		> ../$MACHINE/rk.h
echo "#define NRX	$NRX"		> ../$MACHINE/rx.h
echo "#define NSL	$NSL"		> ../$MACHINE/sl.h
echo "#define NSRI	$NSRI"		> ../$MACHINE/sri.h
echo "#define NTB	$NTB"		> ../$MACHINE/tb.h
echo "#define NTS	$NTS"		> ../$MACHINE/ts.h
echo "#define NTMSCP	$NTMSCP"	> ../$MACHINE/tms.h
echo "#define NTMS	$NTMS"		>> ../$MACHINE/tms.h
if [ $TMSCP_DEBUG = YES ]; then
	echo "#define TMSCP_DEBUG"	>> ../$MACHINE/tms.h
fi
if [ $DUMPROUTINE = tmsdump ]; then
	echo "#define TMSCP_DUMP 1"	>> ../$MACHINE/tms.h
fi

echo "#define NVV	$NVV"		> ../$MACHINE/vv.h

echo "#define NACC	$NACC"		> ../$MACHINE/acc.h
if [ $PLI = YES ]; then
	echo "#define PLI 1"		>> ../$MACHINE/acc.h
fi

echo "#define NHK	$NHK"		> ../$MACHINE/hk.h
if [ $DUMPROUTINE = hkdump ]; then
	echo "#define HK_DUMP 1"	>> ../$MACHINE/hk.h
fi

echo "#define NRAC	$NRAC"		> ../$MACHINE/ra.h
echo "#define NRAD	$NRAD"		>> ../$MACHINE/ra.h
if [ $DUMPROUTINE = radump ]; then
	echo "#define RA_DUMP 1"	>> ../$MACHINE/ra.h
fi

echo "#define NRL	$NRL"		> ../$MACHINE/rl.h
if [ $DUMPROUTINE = rldump ]; then
	echo "#define RL_DUMP 1"	>> ../$MACHINE/rl.h
fi

echo "#define NBR	$NBR"		> ../$MACHINE/br.h
if [ $DUMPROUTINE = brdump ]; then
	echo "#define BR_DUMP 1"	>> ../$MACHINE/br.h
fi

echo "#define NSI	$NSI"		> ../$MACHINE/si.h
if [ $DUMPROUTINE = sidump ]; then
	echo "#define SI_DUMP 1"	>> ../$MACHINE/si.h
fi

echo "#define NTM	$NTM"		> ../$MACHINE/tm.h
if [ $AVIVTM = YES ] ; then
	echo "#define AVIVTM 1"		>> ../$MACHINE/tm.h
fi

echo "#define NXPD	$NXPD"		> ../$MACHINE/xp.h
echo "#define NXPC	$NXPC"		>> ../$MACHINE/xp.h
if [ $DUMPROUTINE = xpdump ]; then
	echo "#define XP_DUMP 1"	>> ../$MACHINE/xp.h
fi

echo "Creating Makefile for $MACHINE".
if [ -s ../$MACHINE/Makefile ]; then
	echo "Saving ../$MACHINE/Makefile to ../$MACHINE/Makefile.old"
	cp -p ../$MACHINE/Makefile ../$MACHINE/Makefile.old
fi

echo "OPTS=$OPTS" > ../$MACHINE/Makefile

cp Make.sys Make.pdp Make.pdpuba Make.pdpmba ../$MACHINE

if   [ $INET = YES ]; then
     cat Make.nsunix >> ../$MACHINE/Makefile
     cp Make.net Make.pdpnet ../$MACHINE
elif [ $KERN_NONSEP = NO ]; then
     cat Make.sunix >> ../$MACHINE/Makefile
else
     cat Make.unix >> ../$MACHINE/Makefile
fi

# install copy of localopts.h and make it readable for applications
cp $LO ../$MACHINE
chmod a+r ../$MACHINE
