#! /bin/sh
#	script to set up a new kernel configuration directory.
#	Usage:	MAKE machineid
#	to make a directory for "machineid"

case $# in
	1) ;;
	*) echo "Usage: MAKE machinename"
		echo " to make a configuration directory ../machinename"
		echo " from the description file ./machinename"
		echo " and copy the necessary files into it."
		exit 1
		;;
esac

:  set defaults
pdp11="GENERIC"
ident="UNKNOWN"
maxusers=4
bootdev="none"
timezone=8
dst=1
rootdev="UNSPECIFIED"
swapdev="UNSPECIFIED"
dumpdev="UNSPECIFIED"
pipedev="UNSPECIFIED"
swplo="UNSPECIFIED"
nswap="UNSPECIFIED"
dumplo="UNSPECIFIED"
dumproutine="UNSPECIFIED"

LOWDM=0 NKL=1
NACC=0 NBK=0 NCAT=0 NCSS=0 NDH=0 NDM=0 NDMC=0 NDN=0 NDR=0 NDVHP=0 NDZ=0
NEC=0 NEN=0 NETH=0 NHK=0 NHP=0 NHS=0 NHT=0 NIL=0 NIMP=0 NLP=0 NPTY=0
NPUP=0 NRF=0 NRK=0 NRL=0 NRM=0 NRP=0 NSRI=0 NTM=0 NTS=0 NUN=0 NVP=0 NVV=0
NXP=0 NXP_CONTROLLER=0 NDMBB=0

machine=$1

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

case $pdp11 in
	GENERIC|40|60)
		splfix=:splfix.movb ;;
	34|23|24)
		splfix=:splfix.mtps ;;
	44|45|70)
		splfix=:splfix.spl ;;
	*)
		echo "Unrecognized PDP11 type"
		exit 1 ;;
esac

if [ $NKL -lt 1 ]
then
	echo "NKL must be at least one (for the console)"
	exit 1
fi

if [ -d ../$machine ]
then
	echo "../$machine: directory exists"
	exit 1
fi
echo "Making ../$machine."
mkdir ../$machine

: copy in the standard configuration files, etc.
: copy in the cpu-dependent files and modify as necessary

echo "Copying in configuration files."

cp c.c genassym.c ioconf.c l.s param.c whoami.h localopts.h param.h \
	:comm-to-bss $splfix ../$machine
cp includes/* ../$machine

echo "Setting up boot.s, Makefile, whoami.h, param.c, ioconf.c."

if [ $bootdev = "none" ]
then
	bootdev="no"
fi

: copy in boot program and makefiles, set the mode

cp boot/${bootdev}boot.s ../$machine/boot.s
cp makefiles/* ../$machine

chmod 664 ../$machine/*

ed - ../$machine/Makefile << EOF
/%SPLFIX%/s//$splfix/
/%MAXUSERS%/s//$maxusers/
w
q
EOF

ed - ../$machine/whoami.h << EOF
/%PDP%/s//$pdp11/
g/%IDENT%/s//$ident/
w
q
EOF

ed - ../$machine/param.c << EOF
/%TIMEZONE%/s//$timezone/
/%DST%/s//$dst/
w
q
EOF

ed - ../$machine/ioconf.c << EOF
/%ROOTDEV%/s//$rootdev/
/%SWAPDEV%/s//$swapdev/
/%PIPEDEV%/s//$pipedev/
/%DUMPDEV%/s//$dumpdev/
/%NSWAP%/s//$nswap/
/%SWPLO%/s//$swplo/
/%DUMPLO%/s//$dumplo/
g/%DUMPROUTINE%/s//$dumproutine/
w
q
EOF

:  Now edit all of the device header files.

echo "Setting up device header files."

ed - ../$machine/acc.h << EOF
/%NACC%/s//$NACC/
w
q
EOF

ed - ../$machine/bk.h << EOF
/%NBK%/s//$NBK/
w
q
EOF

ed - ../$machine/cat.h << EOF
/%NCAT%/s//$NCAT/
w
q
EOF

ed - ../$machine/css.h << EOF
/%NCSS%/s//$NCSS/
w
q
EOF

ed - ../$machine/dmbb.h << EOF
/%NDMBB%/s//$NDMBB/
w
q
EOF

ed - ../$machine/dh.h << EOF
/%NDH%/s//$NDH/
/%NDM%/s//$NDM/
/%LOWDM%/s//$LOWDM/
w
q
EOF

ed - ../$machine/dmc.h << EOF
/%NDMC%/s//$NDMC/
w
q
EOF

ed - ../$machine/dn.h << EOF
/%NDN%/s//$NDN/
w
q
EOF

ed - ../$machine/dr.h << EOF
/%NDR%/s//$NDR/
w
q
EOF

ed - ../$machine/dvhp.h << EOF
/%NDVHP%/s//$NDVHP/
w
q
EOF

ed - ../$machine/ec.h << EOF
/%NEC%/s//$NEC/
w
q
EOF

ed - ../$machine/en.h << EOF
/%NEN%/s//$NEN/
w
q
EOF

ed - ../$machine/eth.h << EOF
/%NETH%/s//$NETH/
w
q
EOF

ed - ../$machine/dz.h << EOF
/%NDZ%/s//$NDZ/
w
q
EOF

ed - ../$machine/hk.h << EOF
/%NHK%/s//$NHK/
w
q
EOF

ed - ../$machine/hp.h << EOF
/%NHP%/s//$NHP/
w
q
EOF

ed - ../$machine/hs.h << EOF
/%NHS%/s//$NHS/
w
q
EOF

ed - ../$machine/ht.h << EOF
/%NHT%/s//$NHT/
w
q
EOF

ed - ../$machine/il.h << EOF
/%NIL%/s//$NIL/
w
q
EOF

ed - ../$machine/imp.h << EOF
/%NIMP%/s//$NIMP/
w
q
EOF

ed - ../$machine/kl.h << EOF
/%NKL%/s//$NKL/
w
q
EOF

ed - ../$machine/lp.h << EOF
/%NLP%/s//$NLP/
w
q
EOF

ed - ../$machine/pty.h << EOF
/%NPTY%/s//$NPTY/
w
q
EOF

ed - ../$machine/pup.h << EOF
/%NPUP%/s//$NPUP/
w
q
EOF

ed - ../$machine/rf.h << EOF
/%NRF%/s//$NRF/
w
q
EOF

ed - ../$machine/rk.h << EOF
/%NRK%/s//$NRK/
w
q
EOF

ed - ../$machine/rl.h << EOF
/%NRL%/s//$NRL/
w
q
EOF

ed - ../$machine/rm.h << EOF
/%NRM%/s//$NRM/
w
q
EOF

ed - ../$machine/rp.h << EOF
/%NRP%/s//$NRP/
w
q
EOF

ed - ../$machine/sri.h << EOF
/%NSRI%/s//$NSRI/
w
q
EOF

ed - ../$machine/tm.h << EOF
/%NTM%/s//$NTM/
w
q
EOF

ed - ../$machine/ts.h << EOF
/%NTS%/s//$NTS/
w
q
EOF

ed - ../$machine/un.h << EOF
/%NUN%/s//$NUN/
w
q
EOF

ed - ../$machine/vp.h << EOF
/%NVP%/s//$NVP/
w
q
EOF

ed - ../$machine/vv.h << EOF
/%NVV%/s//$NVV/
w
q
EOF

ed - ../$machine/xp.h << EOF
/%NXP%/s//$NXP/
/%NXP_CONTROLLER%/s//$NXP_CONTROLLER/
w
q
EOF

echo ""
echo "Now edit the header files in ../$machine to change any local options"
echo "or parameters in localopts.h, param.c and the device headers."
echo "Remember to edit \"Makefile\" if you need to add optional device"
echo "drivers, then \"make depend\".  You will also have to add any optional"
echo "files to the load rules in Makefile.  If you are going to run an"
echo "overlaid kernel you will probably also have to edit the overlay"
echo "definitions in the Makefile."
