#!/bin/sh
#
# Simple build script to build all 3 cpu models in one go.
#
# Usage: MAKE-ALL buildtarget
#
# where buildtarget is for example nbaxp (NetBSD for Alpha AXP, or
# any other little-endian 64-bit CPU).

DEFBUILD=nbaxp

# TOP=/some/where/klh10

# Remove "/bld" or "/bld/nbaxp" from current directory, if it's there.
# In the latter case, assume that as the build type by default.
# If none of these current directories apply, this script must be run
# from the $TOP directory, and the build will be for the host as
# indicated on the command line, or nbaxp by default.

case "${PWD}" in
    */bld)
	TOP="${PWD%/bld}"
	;;
    */bld/*)
	DEFBUILD="${PWD##*/}"
	TOP="${PWD%/bld/*}"
	;;
    *)
	TOP="$PWD"
	;;
esac

BUILD=${1-$DEFBUILD}

cd $TOP || exit 1

echo "This script builds all PDP-10 variants for host $BUILD."

buildone() {
(
    model="$1"

    export KLH10_HOME=$TOP/new/${BUILD}-${model}
    mkdir -p ${KLH10_HOME}
    cd bld/$BUILD
    make clean
    make base-${model} CONFFLAGS_AUX=-DKLH10_I_CIRC=1 || exit $?
    make tapedd vdkfmt wxtest enaddr                  || exit $?
    make install
)
}

if [ "x$MODEL" != "x" ]
then
    echo "Building $MODEL"
    buildone "$MODEL"
else
    echo "Building KL"
    buildone kl || exit $?

    echo "Building KS"
    buildone ks || exit $?

    echo "Building KS-ITS"
    buildone ks-its || exit $?
fi

cd bld/$BUILD; make clean
