#! /bin/csh -f
#set echo
#
#  Returns the arch of the machine
#
set LARCH = ""
#
# Try to find uname
set UNAME = ""
foreach dir (/bin /usr/bin /usr/local/bin) 
    if (-x $dir/uname) then
	set UNAME = "$dir/uname"
        break
    endif
end

# For some reason, AIX 4.x sets ARCH to blank in some cases.
if ($?ARCH) then
    if ("$ARCH" != "") set LARCH = $ARCH
endif
if ("$LARCH" == "") then
    # Get a candidate value
    if (-e /bin/arch) then
        set LARCH = `/bin/arch`
    else if (-x "$UNAME") then
	set LARCH = `$UNAME -s`
    else if (-e /usr/local/bin/arch) then
        set LARCH = `/usr/local/bin/arch`
    else
        set LARCH = "unknown"
    endif
    # Map to cannonical values
    if ("$LARCH" == "AIX") then
        set LARCH = "rs6000"
    else if ("$LARCH" == "ULTRIX") then
        set LARCH = `$UNAME -m`
        if ("$LARCH" == "RISC") then
            set LARCH = "dec5000"
        endif
    else if ("$LARCH" == "HP-UX") then
	    set LARCH = "hpux"
    else if ("$LARCH" == "IRIX64") then
	    set LARCH = "IRIX64"
    else if ("$LARCH" == "Linux") then
        true
#    else if ("$LARCH" != "IRIX") then 
#        set LARCH = `$UNAME -m`
    endif
endif
if ("$LARCH" == "i586" || "$LARCH" == "i486" || "$LARCH" == "i86pc") then
    # Arch is telling us the HARDWARE architecture when we want the SYSTEM
    # architecture
    if (-e $UNAME) then
	set TA = `$UNAME -s`
        if ("$TA" == "Linux") then
	    set LARCH = "LINUX"
        endif
    endif
endif
#
# Remove blanks from the value of LARCH (another fix for AIX 4.x)
# Note that this means that the tests below must have no blanks in them
# (this affects CRAY xxx)
#
set LARCH = `echo $LARCH | sed 's/ //g'`
set SunOSTest = `expr "$LARCH" : "\(....\)"`
set HPOSTest = `expr "$LARCH" : "\(......\)"`
if ("$SunOSTest" == "sun4") then
  set LARCH = sun4
  set Version = `$UNAME -r`
  # In "improving" SunOS, the useful feature of "substr" was withdrawn 
  # from expr.  Can't let the users have life too easy, can we?  This 
  # means that we can't just use 
  #   set MajorVersion = `expr substr $Version 1 1`
  # because it won't work on Solaris systems.  The following should work on
  # both:
  set MajorVersion = `expr "$Version" : "\(.\)"`
  if ("$MajorVersion" ==  5) then
    set LARCH = "solaris"
  endif
else if ("$HPOSTest" == "hp9000") then
   set LARCH = "hpux"
else if ("$LARCH" == "AIX") then
   set LARCH = "rs6000"
else if ("$LARCH" == "RIOS") then
   set LARCH = "rs6000"
else if ("$LARCH" == "mips") then
   set LARCH = "dec5000"
else if ("$LARCH" == "dec-5000") then
   set LARCH = "dec5000"
else if ("$LARCH" == "IP12") then
  set LARCH = "IRIX"
else if ("$LARCH" == "i386") then
  set LARCH = "ipsc2"
else if ("$LARCH" == "cray") then
  set LARCH = "CRAY"
else if ("$LARCH" == "CRAYY-MP") then
  set LARCH = "CRAY"
else if ("$LARCH" == "CRAYC90") then
  set LARCH = "CRAY"
else if ("$LARCH" == "CRAYJ90") then
  set LARCH = "CRAY"
else if ("$LARCH" == "CRAYT90") then
  set LARCH = "CRAY"
else if ("$LARCH" == "CRAYTS") then
  set LARCH = "CRAY"
else if ("$LARCH" == "CRAY-2") then
  set LARCH = "CRAY"
else if ("$LARCH" == "sun4m") then
  set LARCH = "sun4"
else if ("$LARCH" == "iris4d") then
  set LARCH = "IRIX"
else if ("$LARCH" == "next") then
  set LARCH = "NeXT"
else if ("$LARCH" == "KSR1") then
  set LARCH = "ksr"
else if ("$LARCH" == "FreeBSD") then
  set LARCH = "freebsd"
else if (-e "/dev/elan") then
  set LARCH = "meiko"
else if (-f /usr/bin/uxpm) then
  set LARCH = "UXPM"
endif
#
echo $LARCH
exit 0
