#! /bin/sh -f
# $Id: petscarch,v 1.28 2001/06/14 23:41:02 balay Exp balay $ 
#
#   petscarch - Returns the machine's PETSc environmental variable, PETSC_ARCH.
#
#   You can place the command
#       "setenv PETSC_ARCH `$PETSC_DIR/bin/petscarch`"
#   in a .cshrc file if using the csh or tcsh shell.  Thus, if you have several 
#   machines of different types that share the same filesystem, then when 
#   you log into any of them, the PETSC_ARCH will always be set correctly.
# 
if [ -f /bin/uname ]; then
    LARCH=`/bin/uname -s`
    MARCH=`/bin/uname -m`
    VARCH=`/bin/uname -r`
elif [ -f /usr/bin/uname ]; then
    LARCH=`/usr/bin/uname -s`
    MARCH=`/usr/bin/uname -m`
    VARCH=`/usr/bin/uname -r`
else
    echo "Unable to determine architecture"
    LARCH="unknown"
    MARCH="unknown"
    VARCH="unknown"
fi

# change B.10.01 -> 10.01
VARCH=`echo $VARCH | sed 's/[A-Z,.]*//'`
# grab 10 from 10.01
MajorVersion=`expr "$VARCH" : "\([0-9]*\)"`

if [ "$LARCH" = "AIX" ]; then
    LARCH="rs6000"
elif [ "$LARCH" = "RIOS" ]; then
    LARCH="rs6000"
elif [ "$LARCH" = "HP-UX" ]; then
    if [ "$MajorVersion" =  11 ]; then
        LARCH="hpux64"
    else
        LARCH="hpux"
    fi
elif [ "$LARCH" = "FreeBSD" ]; then
    LARCH="freebsd"
elif [ "$MARCH" = "CRAY Y-MP" ]; then  # Crays are funny - using MARCH
    LARCH="t3d"
elif [ "$MARCH" = "CRAY T3E" ]; then
    LARCH="t3e"
elif [ "$LARCH" = "i86pc" ]; then
    LARCH="solaris_x86"
elif [ "$LARCH" = "iris4d" ] || [ "$LARCH" = "IRIX" ]; then
    if [ "$MajorVersion" =  5 ]; then
        LARCH="IRIX5"
    else
        LARCH="IRIX"
    fi
elif [ "$LARCH" = "SunOS" ]; then
    if [ "$MajorVersion" =  4 ]; then
        LARCH="sun4"
    else
        LARCH="solaris"
    fi
elif [ "$LARCH" = "Linux" ]; then
    if [ "$MARCH" = "alpha" ]; then
        LARCH="linux_alpha"
    elif [ "$MARCH" = "ppc" ]; then
        LARCH="linux_ppc"
    else
        LARCH="linux"
    fi
elif [ "$LARCH" = "OSF1" ]; then
    LARCH="alpha"
elif [ "$LARCH" = "Hurd" ]; then
        LARCH="hurd"
elif [ "$LARCH" = "Rhapsody" ] || [ "$LARCH" = "Darwin" ]; then
        LARCH="macx"
elif [ "$LARCH" = "5000" ]; then
        LARCH="UXPV"
else # maybe use a case statement instead of if test for the entire script?
    case "$LARCH" in
        CYGWIN*)
        LARCH="win32_ms"
        ;;
    esac
fi

echo $LARCH
exit 0
