#!/bin/ksh
# Determine the value of CGPLATFORM to use for CONGEN and write it
# to standard output. This procedure is clearly heuristic, but if
# you need it to work for just your machine, look up the appropriate
# value of CGPLATFORM in the Implementation chapter in the CONGEN
# manual, and just write it to standard output and just exit.

doIrix() {
ipnum=`echo $5 | cut -c3-`
if [ $ipnum -le 15 ]
then
  chip=r3k
elif [ $ipnum -le 20 ]
then
  chip=r4k
elif [ $ipnum -le 21 ]
then
  chip=r8k
elif [ $ipnum -le 24 ]
then
  chip=r4k
elif [ $ipnum -le 25 ]
then
  chip=r10k
elif [ $ipnum -le 26 ]
then
  chip=r8k
elif [ $ipnum -le 30 ]
then
  chip=r10k
elif [[ $ipnum = 3[25] ]]
then
  cpu=`hinv -c processor | grep "^CPU" | nawk '{print $3}'`
  if [[ $cpu = R1* ]]
  then
    chip=r10k
  else
    chip=r5k
  fi
else
  chip=r4k
fi

irix=$3

if [ $chip = r3k ]
then
  compiler=5.3
else
  compiler=`showprods -D 1 compiler_dev | grep compiler_dev | cut -f2 -d, | nawk '{print $1}' | cut -f1-2 -d. | sort -r | head -1 `
  if [ -z "$compiler" ]
  then
    compiler=5.3
  fi
fi

if [ $chip = r3k ]
then
  isa=1
elif [ $chip = r4k ]
then
  if [ $irix = 5.3 ]
  then
    isa=2
  else
    isa=3
  fi
else
  isa=4
fi

if [ $irix = 5.3 ]
then
  abi=32
elif [ $chip = r8k ]
then
  abi=64
elif [ $chip = r4k ]
then
  abi=n32
elif [ $chip = r10k ]
then
  if [ $ipnum -eq 32 ]
  then
    abi=n32
  else
    abi=64
  fi
else
  abi=32
fi

answer=sgi_${chip}_i${irix}_c${compiler}_m${isa}_a${abi}
}


if [ `hostname` = tammy ] ; then
  answer=convex
else
  set `uname -a`
  case $1 in
    IRIX* )
      doIrix $* ;;
    SunOS )
      answer=sparc ;;
    AIX )
      answer=rs6000 ;;
    HPUX )
      answer=hpux ;;
    OSF1 )
      if [ $5 = alpha ] ; then
        answer=alphaosf
      fi ;;
    UNIX_System_V )
      if [ $5 = F240 ] ; then
	answer=fujitsu
      fi ;;
    Linux )
      machine=`uname -m`
      if [ $machine = x86_64 ]; then
         answer=linux_x86_64
      elif [ $machine = ia64 ]; then
         answer=linux_itanium
      else
        answer=linux
      fi ;;
    * )
      if [ $5 = CRAY ] ; then
	answer=unicos
      fi ;;
  esac
fi

echo $answer
