#!/bin/sh

# converted to sh, (12/14/2007)

# Based on parts of tcsh's tc.vers.c && PVM's aimk

# Originally hacked by Bernd Mohr
# Modified by Pete Beckman (3/2/95)
# Modified by Lars Thomas Hansen (2/27/95); very minor fixes for Solaris

# Command line parameters:
# -x provide cross-development architecture name (for cm?, rs6k, etc)
# -l provide long name
# -s SPECIAL.  Used to differentiate two very similar architectures

#echo foo
ARCHTESTFILE=$0.c
ARCHLISTFILE=$0.txt
ARCH=
XDEV=
SPECIAL=

# TAU_CCOM may be defined by the caller to the name of the c compiler
# for this user and system, as given on the command line.
#
# Not everyone uses gcc.

if [ "x$TAU_CCOM" = "x" ]; then
    TAU_CCOM=cc
fi

if [ `uname -s ` = "Darwin" ];  then
    TAU_CCOM=c++
    ARCH=apple
fi

if [ `uname -s ` = "HI-UX/MPP" ]; then 
      ARCH=`$TAU_CCOM -msg=e -E $ARCHTESTFILE | sed -e '/^#/d' -e '/^[ ]*$/d' -e 's/^ARCH//'` 
else
  if [ "x$ARCH" = "x" ]; then
# ARCH has not been assigned yet.
      ARCH=`$TAU_CCOM -w -E $ARCHTESTFILE | sed -e '/^#/d' -e '/^[ ]*$/d' -e 's/^ARCH//'` 
  fi
fi

# Check for brain-dead solaris compiler
if [ $ARCH = sun4 ]; then
    VER=`uname -r | cut -c0-2`
    if [ $VER = "5." ]; then
	ARCH=solaris2
    fi
fi

# Check for TMC cm5
if [ $ARCH = sun4 -o $ARCH = solaris2 ]; then
    if [ -e /usr/bin/cmmd-ld ]; then
	XDEV="cm5 $XDEV"
    fi
fi

# Check for SGI Symmetric Multiprocessing engine
if [ $ARCH = sgi4k -o $ARCH = sgi8k ]; then
  # Run "hinv" and check for the number of processors
    /bin/hinv 2>&1 | /usr/bsd/head -1 2>&1 | /bin/grep "^1 " &> /dev/null
    if [ $? = 1 ]; then
	XDEV="sgimp $XDEV"
    fi
fi      

# Check for Meiko CS2
if [ $ARCH = solaris2 -a -d /opt/MEIKOcs2 ]; then
    XDEV="cs2 $XDEV"
fi

# Check for cray-t3d xdev environment for Cray C90
if [ $ARCH = c90 -a -d /mpp/bin ]; then
    XDEV="t3d $XDEV"
fi

# Check for Convex SPP engine
if [ $ARCH = hp9000s800 ]; then
    if [ -d /usr/convex ]; then
	XDEV="cnxspp $XDEV"
    fi
fi

# Check for RS6000 based IBM SPx
if [ $ARCH = rs6000 ]; then
    if [ -f /bin/mpcc ]; then
	XDEV="sp1 $XDEV"
    fi
fi

if [ $ARCH = unknown ]; then
#See if users path finds an 'arch' command, it so, use it! (a little sloppy)
    arch &> /dev/null
    if [ $? != 0 ]; then
#This machine does not have an 'arch' command
#Or at least one that correctly sets the arch

#Try another guess....
	if [ -e /usr/bin/getcube ]; then
	    ARCH=i860 
	fi
    else
# 'arch' command found, use it!
	ARCH=`arch`
    fi

    if [ $ARCH = unknown ]; then
	if [ `uname -s` = FreeBSD ]; then
	    ARCH=freebsd
	fi
    fi

    if [ $# = 1 ]; then
	if [ "$1" = "-x" ]; then
	    if [ "x$XDEV" = "x" ]; then
		echo none
		exit 1
	    else
		echo $XDEV
		exit 0
	    fi
	else
	    if [ "$argv[1]" = "-l" ]; then
		grep $ARCH $ARCHLISTFILE
		if [ $ARCH = unknown ]; then
		    exit 1
		else
		    exit 0
		fi
	    else
		if [ "$1" = "-s" ]; then
		    if [ "x$SPECIAL" = "x" ]; then
			echo none
			exit 1
		    else
			echo $SPECIAL
			exit 0
		    fi
		fi
	    fi
	fi
    fi
fi

echo $ARCH
if [ $ARCH = unknown ]; then
    exit 1
else
    exit 0
fi


