1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#! /bin/sh
# Shell script to determine the operating system type by various heuristics.
# For some OS there are two variants: a full name, which is used for the
# build directory, and a generic name, which is used to identify the OS-
# specific scripts, and which can be the same for different versions of
# the OS. Solaris 2 is one such OS. The option -generic specifies the
# latter type of output.
# If OSTYPE is set, use it. This allows a manual override.
case "$OSTYPE" in ?*) os="$OSTYPE";; esac
# For some shells running under IRIX the value of $OSTYPE is just "irix",
# which isn't very helpful. We know that uname works under IRIX, so in
# this case just unset os and fall through. BSDI 3.0 sets $OSTYPE to
# "386BSD" which is something other OS may also use, so unset that too.
case "$os" in
irix) os='';;
386BSD) os='';;
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
aix*) os=AIX;;
AIX*) os=AIX;;
bsdi) os=BSDI;;
BSDOS) os=BSDI;;
BSD_OS) os=BSDI;;
dgux) os=DGUX;;
freebsd*) os=FreeBSD;;
Irix5) os=IRIX;;
Irix6) os=IRIX6;;
IRIX64) os=IRIX6;;
irix6.5) os=IRIX65;;
IRIX) version=`uname -r`
case "$version" in
5*) os=IRIX;;
6.5) os=IRIX65;;
6*) os=IRIX632;;
esac;;
HI-OSF1-MJ) os=HI-OSF;;
HI-UXMPP) os=HI-OSF;;
hpux*) os=HP-UX;;
linux) os=Linux;;
linux-*) os=Linux;;
Linux-*) os=Linux;;
openbsd*) os=OpenBSD;;
osf1) os=OSF1;;
qnx*) os=QNX;;
solaris*) os=SunOS5;;
sunos4) os=SunOS4;;
Ultrix) os=ULTRIX;;
ultrix*) os=ULTRIX;;
esac
# In the case of SunOS we need to distinguish between SunOS4 and SunOS5,
# and in the case of BSDI we need to distinguish between versions 3 and 4.
case "$os" in
SunOS) case `uname -r` in
5*) os="${os}5";;
4*) os="${os}4";;
esac;;
BSDI) case `uname -r` in
3*) os="${os}3";;
4*) os="${os}4";;
esac;;
esac
# Need to distinguish SunOS5 from the version on the HAL (64bit sparc,
# CC=hcc -DV7). Also need to distinguish different versions of the OS
# for building different binaries.
case "$os" in
SunOS5) case `uname -m` in
sun4H) os="${os}-hal";;
*) os="${os}-`uname -r`";;
esac;;
esac
# In the case of Linux we need to distinguish which libc is used.
# This is more cautious than it needs to be. In practice libc5 will always
# be a symlink, and libc6 will always be a linker control file, but it's
# easy enough to do a better check, and check the symlink destination or the
# control file contents and make sure.
case "$os" in
Linux) if [ -L /usr/lib/libc.so ]; then
if [ x"$(file /usr/lib/libc.so | grep "libc.so.5")"x != xx ]; then
os=Linux-libc5
fi
else
if grep -q libc.so.5 /usr/lib/libc.so; then
os=Linux-libc5
fi
fi
;;
esac
# If a generic OS name is requested, some further massaging is needed
# for some systems.
if [ "$1" = '-generic' ]; then
case "$os" in
SunOS5*) os=SunOS5;;
BSDI*) os=BSDI;;
esac
fi
# OK, the script seems to have worked. Pass the value back.
echo "$os"
# End of os-type
|