#! /bin/sh

# Shell script to determine the operating system type by various heuristics.

# If OSTYPE is set, use it. This allows a manual override.

case "$OSTYPE" in ?*) os="$OSTYPE";; esac

# If os is still unset, try to get a value from the uname command.

case "$os" in '') os=`uname -s`;; esac

# ... what else can be tried? Insert here any other bright ideas that might
# come to mind ...

# Failed to find OS by automatic means.

case "$os" in
'') echo "" 1>&2
    echo "*** Failed to determine the operating system type." 1>&2
    echo "" 1>&2
    echo UnKnown
    exit 1;;
esac

# Clean out gash characters

os=`echo $os | sed 's,[^-+_.a-zA-Z0-9],,g'`

# A value has been obtained for the os. Some massaging may be needed in
# some cases to get a uniform set of values. Various shells set OSTYPE to
# things that aren't quite the same as each other. It is all a huge mess.

case "$os" in
bsdi)       os=BSDI;;
BSDOS)      os=BSDI;;
BSD_OS)     os=BSDI;;
freebsd*)   os=FreeBSD;;
Irix5)	    os=IRIX;;
IRIX64)     os=IRIX;;
HI-OSF1-MJ) os=HI-OSF;;
HI-UXMPP)   os=HI-OSF;;
hpux*)      os=HP-UX;;
linux)      os=Linux;;
osf1)       os=OSF1;;
solaris*)   os=SunOS5;;
sunos4)     os=SunOS4;;
Ultrix)     os=ULTRIX;;
esac

# In the case of SunOS we need to distinguish between SunOS4 and SunOS5.

case "$os" in
SunOS)	case `uname -r` in
	5*)	os="${os}5";;
	4*)	os="${os}4";;
	esac
esac

# Need to tell SunOS5 from the version on the HAL (64bit sparc, CC=hcc -DV7).

case "$os" in
SunOS5) case `uname -m` in
        sun4H)  os="${os}-hal";;
        esac
esac

# OK, the script seems to have worked. Pass the value back.

echo "$os"

# End of os-type
