#! /bin/sh

# Shell script to determine the architecture type.

# If ARCHTYPE is set, use it. This allows a manual override.

case "$ARCHTYPE" in ?*) arch="$ARCHTYPE";; esac

# Otherwise, as a cheap test, try shell's HOSTTYPE.

case "$arch++$HOSTTYPE" in
++?*) arch="$HOSTTYPE"
      # Fix up disagreements :-)
      case "$arch" in
      sun4*)	arch=sparc;;
      sgi)	arch=mips;;
      MIPSEL)	arch=mips;;
      esac
      ;;
esac

# If arch is still unset, try to get a value from the uname command.

case "$arch" in '') arch=`uname -p 2> /dev/null`;; esac
case "$arch" in '') arch=`uname -m 2> /dev/null`;; esac

# ... what else can be tried? Insert here any other bright ideas that might
# come to mind ...

# Give up if failed to find arch by automatic means.

case "$arch" in
'') echo "" 1>&2
    echo "*** Failed to determine the machine architecture type." 1>&2
    echo "" 1>&2
    echo UnKnown
    exit 1;;
esac

# Get rid of any gash characters in the string

arch=`echo $arch | sed 's,[^-+_.a-zA-Z0-9],,g'`

# Some further fixups needed

case "$arch" in
i[345]86)	    arch=i386;;
RISC)		    arch=mips;;     # MIPS Ultrix
IP22)		    arch=mips;;
9000[78][0-9][0-9]) arch=hp9000s700;;
9000[34][0-9][0-9]) arch=hp9000s400;;
3050R)              arch=3050;;
esac

# OK, the script seems to have worked. Pass the value back.

echo "$arch"

# End of arch-type
