Start
[exim.git] / src / scripts / os-type
diff --git a/src/scripts/os-type b/src/scripts/os-type
new file mode 100755 (executable)
index 0000000..d747ae9
--- /dev/null
@@ -0,0 +1,170 @@
+#! /bin/sh
+# $Cambridge: exim/src/scripts/os-type,v 1.1 2004/10/06 15:07:40 ph10 Exp $
+
+# Shell script to determine the operating system type. Some of the heuristics
+# herein have accumulated over the years and may not strictly be needed now,
+# but they are left in under the principle of "If it ain't broke, don't fix
+# it."
+
+# 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 EXIM_OSTYPE is set, use it. This allows a manual override.
+
+case "$EXIM_OSTYPE" in ?*) os="$EXIM_OSTYPE";; esac
+
+# Otherwise, try to get a value from the uname command. Use an explicit
+# option just in case there are any systems where -s is not the default.
+
+case "$os" in '') os=`uname -s`;; esac
+
+# It is believed that all systems respond to uname -s, but just in case
+# there is one that doesn't, use the shell's $OSTYPE variable. It is known
+# to be unhelpful for some systems (under IRIX is it "irix" and under BSDI
+# 3.0 it may be "386BSD") but those systems respond to uname -s, so this
+# doesn't matter.
+
+case "$os" in '') os="$OSTYPE";; esac
+
+# Failed to find OS type.
+
+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. In earlier versions of this
+# script, $OSTYPE was looked at before uname -s, and various shells set it
+# to things that are subtly different. It is possible that some of this may
+# no longer be needed.
+
+case "$os" in
+aix*)       os=AIX;;
+AIX*)       os=AIX;;
+bsdi*)      os=BSDI;;
+BSDOS)      os=BSDI;;
+BSD_OS)     os=BSDI;;
+CYGWIN*)    os=CYGWIN;;
+dgux)       os=DGUX;;
+freebsd*)   os=FreeBSD;;
+gnu)        os=GNU;;
+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) version=`uname -R | awk '{print $NF}'`
+                 version=`echo $version | sed 's,[^-+_a-zA-Z0-9],,g'`
+                 os=IRIX$version;;
+            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;;
+netbsd*)    os=NetBSD;;
+openbsd*)   os=OpenBSD;;
+osf1)       os=OSF1;;
+qnx*)       os=QNX;;
+solaris*)   os=SunOS5;;
+sunos4*)    os=SunOS4;;
+UnixWare)   os=Unixware7;;
+Ultrix)     os=ULTRIX;;
+ultrix*)    os=ULTRIX;;
+esac
+
+# In the case of SunOS we need to distinguish between SunOS4 and Solaris (aka
+# SunOS5); in the case of BSDI we need to distinguish between versions 3 and 4;
+# in the case of HP-UX we need to distinguish between version 9 and later.
+
+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.2*)   os="${os}4.2";;
+        4*)     os="${os}4";;
+        esac;;
+
+HP-UX)  case `uname -r` in
+        A.09*)  os="${os}-9";;
+        esac;;
+esac
+
+# Need to distinguish Solaris 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
+        ;;
+
+# 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.
+
+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
+        ;;
+
+# In the case of NetBSD we need to distinguish between a.out, ELF
+# and COFF binary formats.  However, a.out and COFF are the same
+# for our purposes, so both of them are defined as "a.out".
+# Todd Vierling of Wasabi Systems reported that NetBSD/sh3 (the
+# only NetBSD port that uses COFF binary format) will switch to
+# ELF soon.
+
+NetBSD) if echo __ELF__ | ${CC-cc} -E - | grep -q __ELF__ ; then
+           # Non-ELF system
+           os="NetBSD-a.out"
+       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;;
+  IRIX65*) os=IRIX65;;
+  esac
+fi
+
+# OK, the script seems to have worked. Pass the value back.
+
+echo "$os"
+
+# End of os-type