#!/bin/csh -f

###########################################################################
# 02/05/93 James Created - get machine type using file/hinv/uname.
# 02/12/93 James check for sun/solaris.
# 03/01/93 James Fix for nec_risc r4000
# 04/05/93 Pete  added alpha_unix
# 04/17/93 James Removed quotes around hinv_out.
# 06/21/93 jmichaud Allow for IRIX 5.0 sgi and sgi_r4k (ELF 32-bit).
# 08/27/93 James sun4_solaris.
# 11/17/93 James R4000->R4..0
# 11/19/93 James IBM PowerPC fix.
# 12/08/93 $$1 James hitachi.
# 04/26/94 $$2 James handle jap sgi.
# 05/16/95 $$3 Pete  set LANG C at top, all platforms work well with this
# 06/22/95 $$4 true R4..0->R[48]..0 to allow for SGI R8000 systems.
# 11/27/95 $$5 Pete  added sgi_elf2 for 5.3 and beyond
# 02/01/96 $$6 Pete  added R5000 support for sgi (for Tom True)
# 18-Jun-96 Pete   $$7  revised by Joe Michaud and tweaked by me
# 20-Jun-96 Pete   $$8  fixed bug in previous subm comment block
# 05-Dec-96 Pete   $$9  added hp8k
# 30-Dec-96 Jane   $$10 distinguish hp700 and hp8k properly
# 08-Sep-97 JJE    $$11 Just hp8k now for 19
# 27-Mar-98 jmichaud $$12 added sgi_mips4
# 08-Mar-00 MAZ           Get rid of env os_name
# 04-Aug-00 TWH      $$13 Add hpux11_pa32
# 01-Dec-00 TWH      $$14 Add sun4_solaris_64
# 16-May-01 TWH      $$15 Add hpux_pa64
# 10-Aug-01 MAZ      $$16 Introduce FORCE_PMT
# 21-Nov-01 TWH      $$17 Add sgi_elf4
# 01-AUG-02 MTP      $$18 Add i486_linux
# 25-OCT-05 MTP      $$19 Add sun_solaris_x64
###########################################################################

setenv LANG C

set id = "UNKNOWN"

switch (`uname -s`)
    case "IRIX":
    case "IRIX64":
        #
        # There are three different platform types for SGI:
        #   sgi_elf4  - built -64  -mips4
        #   sgi_mips4 - built -n32 -mips4 (older)
        #   sgi_elf2  - built -32  -mips2 (oldest)
        #
        # IRIX OS can handle only 32-bit programs.
        # IRIX64 OS can handle 32-bit and 64-bit programs.
        #
        # Machines with R2000 and R3000 CPUs are obsolete.
        # Machines with R4XXX CPUs can't handle MIPS4 ISA, and so can
        # only deal with sgi_elf2.  Machines with all other CPUs can
        # handle MIPS4 ISA, but only those running IRIX64 OS can handle
        # sgi_elf4.  Others run sgi_mips4.
        #
        set cpu = (`hinv -t cpu`)
        if ("`expr $cpu[3] : 'R[23]*'`" > "1") then
            # Not supported.
        else if ("`expr $cpu[3] : 'R4*'`" > "1") then
            set id = "sgi_elf2"
        else
	    if ("`uname -s`" == "IRIX64") then
                set id = "sgi_elf4"
            else
                set id = "sgi_mips4"
            endif
        endif
    breaksw

    case "OSF1":
        set id = "alpha_unix"
    breaksw

    case "Linux":
        set id = "i486_linux"
    breaksw

    case "HP-UX":
        set rev = `uname -r`
        if ("`expr $rev : '[A-Z].11.*'`" > "1") then
	  if ("`file /stand/vmunix | grep 'ELF-64'`" == "") then
            set id = "hpux11_pa32"
          else
            set id = "hpux_pa64"
          endif
        else
            set id = "hp8k"
        endif
    breaksw

    case "AIX":
        set id = "ibm_rs6000"
    breaksw

    case "SunOS":
        set rev = `isalist |grep sparcv9 | wc -c`
        if ("$rev" > "0") then
	   set id = "sun4_solaris_64"
        else
           set rev = `isalist |grep amd64 | wc -c`
           if ("$rev" > "0") then
              set id = "sun_solaris_x64"
           else
              set id = "sun4_solaris"
           endif
        endif
    breaksw

    case "HI-UX":
        set id = "hitachi"
    breaksw

    case "UNIX_SV":
        set id = "nec_mips"
    breaksw
endsw

if( $?FORCE_PMT ) then
    echo $FORCE_PMT 
else
    echo $id 
endif

