#!/bin/sh
#       harch - determine canonical processor architecture
#		Nov 1998: first used.
#		May 1999: ensure that small differences (e.g. kernel version)
#			  don't matter.

PROCESSOR=
OS=
REL=

#  Unfortunately, there are a variety of incompatible
#  ways of detecting architecture, so try them all!

if uname >/dev/null 2>&1
then
  if uname -m >/dev/null 2>&1
  then PROCESSOR=`uname -m`
    case "$PROCESSOR" in
    unknown|*\ *)
      PROCESSOR=`uname -m`
      ;;
    esac
  else
    if arch >/dev/null 2>&1
    then PROCESSOR=`arch`
    else PROCESSOR=`uname -m`
    fi
  fi
  OS=`uname -s`
  REL=`uname -r`
else
  if arch >/dev/null 2>&1
  then PROCESSOR=`arch`
  else
    if machine >/dev/null 2>&1
    then PROCESSOR=`machine`
    else PROCESSOR='unknown'
    fi
  fi
  OS=unknown
fi


# Remove whitespace and slashes.
PROCESSOR=`echo $PROCESSOR | tr '/ 	' '.'`
OS=`echo $OS | tr '/ 	' '-'`
REL=`echo $REL | tr '/ 	' '-'`

# Canonicalise equivalent processor families to one representative member.
case $PROCESSOR in
  i[345678]86)	PROCESSOR=ix86;;
  sun3*)	PROCESSOR=sun3;;
  sun4*)	PROCESSOR=sun4;;
  sparc*)	PROCESSOR=sparc;;
esac

# Keep OS release number only if it might be relevant.
case $OS in
  unknown)	;;
  Linux)	;;
  CYGWIN*)      ;;
  *BSD)		;;
# BSD/OS)	OS="BSD-OS"$REL ;;	-- removed by slash->dash translation.
  SunOS)	case $REL in
		  3*) OS=SunOS3;;
		  4*) OS=SunOS4;;
		  5*) OS=solaris2;;
		  6*) OS=solaris3;;
		  7*) OS=solaris7;;
		  *)  OS=SunOS-$REL;;
		esac;;
  IRIX*)	case $REL in
		  5*) OS=IRIX5;;
		  6*) OS=IRIX6;;
		  *)  OS=IRIX-$REL;;
		esac;;
  AIX)		if oslevel >/dev/null 2>&1	# AIX just has to be different
                then OS=$OS-`oslevel`
                else OS=$OS-unknown
                fi
                if /etc/lsattr -EHl proc0 | grep -i powerpc >/dev/null 2>&1
                then PROCESSOR=powerpc
                else PROCESSOR=power
                fi ;;
  *)		OS=$OS-$REL;;
esac

# And that's it.
echo $PROCESSOR-$OS
