#!/bin/sh
# Use any argument given so that we can use the same guess for preconfigured stuff
# Copied from configure
if test -n "$1"; then
    echo $1
    exit 0
fi

# Stolen from AC_CANONICAL_HOST
CONFIG_AUX_DIR="$PETSC_DIR/config"
if test ! -x "$CONFIG_AUX_DIR/config.sub"; then
    CONFIG_AUX_DIR="/usr/share/automake"
fi
ac_config_sub="$CONFIG_AUX_DIR/config.sub"
ac_config_guess="$CONFIG_AUX_DIR/config.guess"
host="NONE"
nonopt="NONE"

# Make sure we can run config.sub.
if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then
    :
else
    echo "Can not run $ac_config_sub"
    exit 1
fi

# Set host_alias.
host_alias=$host
case "$host_alias" in
NONE)
    case $nonopt in
    NONE)
        if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then
            :
        else
            echo "Can not guess host type, you must specify one"
            exit 1
        fi
        ;;
    *)
        host_alias=$nonopt
        ;;
    esac
    ;;
esac

# Set the other host vars
host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias`
host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`

echo "$host_os"