Merge branch 'debian'
[hcoop/debian/exim4.git] / scripts / os-type
CommitLineData
420a0d19
CE
1#! /bin/sh
2
3# Shell script to determine the operating system type. Some of the heuristics
4# herein have accumulated over the years and may not strictly be needed now,
5# but they are left in under the principle of "If it ain't broke, don't fix
6# it."
7
8# For some OS there are two variants: a full name, which is used for the
9# build directory, and a generic name, which is used to identify the OS-
10# specific scripts, and which can be the same for different versions of
11# the OS. Solaris 2 is one such OS. The option -generic specifies the
12# latter type of output.
13
14# If EXIM_OSTYPE is set, use it. This allows a manual override.
15
16case "$EXIM_OSTYPE" in ?*) os="$EXIM_OSTYPE";; esac
17
18# Otherwise, try to get a value from the uname command. Use an explicit
19# option just in case there are any systems where -s is not the default.
20
21case "$os" in '') os=`uname -s`;; esac
22
23# Identify Glibc systems under different names.
24
25case "$os" in GNU) os=GNU;; esac
26case "$os" in GNU/*|Linux) os=Linux;; esac
27
28# It is believed that all systems respond to uname -s, but just in case
29# there is one that doesn't, use the shell's $OSTYPE variable. It is known
30# to be unhelpful for some systems (under IRIX is it "irix" and under BSDI
31# 3.0 it may be "386BSD") but those systems respond to uname -s, so this
32# doesn't matter.
33
34case "$os" in '') os="$OSTYPE";; esac
35
36# Failed to find OS type.
37
38case "$os" in
39'') echo "" 1>&2
40 echo "*** Failed to determine the operating system type." 1>&2
41 echo "" 1>&2
42 echo UnKnown
43 exit 1;;
44esac
45
46# Clean out gash characters
47
48os=`echo $os | sed 's,[^-+_.a-zA-Z0-9],,g'`
49
50# A value has been obtained for the os. Some massaging may be needed in
51# some cases to get a uniform set of values. In earlier versions of this
52# script, $OSTYPE was looked at before uname -s, and various shells set it
53# to things that are subtly different. It is possible that some of this may
54# no longer be needed.
55
56case "$os" in
57aix*) os=AIX;;
58AIX*) os=AIX;;
59bsdi*) os=BSDI;;
60BSDOS) os=BSDI;;
61BSD_OS) os=BSDI;;
62CYGWIN*) os=CYGWIN;;
63dgux) os=DGUX;;
64freebsd*) os=FreeBSD;;
65gnu) os=GNU;;
66Irix5) os=IRIX;;
67Irix6) os=IRIX6;;
68IRIX64) os=IRIX6;;
69irix6.5) os=IRIX65;;
70IRIX) version=`uname -r`
71 case "$version" in
72 5*) os=IRIX;;
73 6.5) version=`uname -R | awk '{print $NF}'`
74 version=`echo $version | sed 's,[^-+_a-zA-Z0-9],,g'`
75 os=IRIX$version;;
76 6*) os=IRIX632;;
77 esac;;
78HI-OSF1-MJ) os=HI-OSF;;
79HI-UXMPP) os=HI-OSF;;
80hpux*) os=HP-UX;;
81linux) os=Linux;;
82linux-*) os=Linux;;
83Linux-*) os=Linux;;
84netbsd*) os=NetBSD;;
85NetBSD*) os=NetBSD;;
86openbsd*) os=OpenBSD;;
87osf1) os=OSF1;;
88qnx*) os=QNX;;
89solaris*) os=SunOS5;;
90sunos4*) os=SunOS4;;
91UnixWare) os=Unixware7;;
92Ultrix) os=ULTRIX;;
93ultrix*) os=ULTRIX;;
94esac
95
96# In the case of SunOS we need to distinguish between SunOS4 and Solaris (aka
97# SunOS5); in the case of BSDI we need to distinguish between versions 3 and 4;
98# in the case of HP-UX we need to distinguish between version 9 and later.
99
100case "$os" in
101SunOS) case `uname -r` in
102 5*) os="${os}5";;
103 4*) os="${os}4";;
104 esac;;
105
106BSDI) case `uname -r` in
107 3*) os="${os}3";;
108 4.2*) os="${os}4.2";;
109 4*) os="${os}4";;
110 esac;;
111
112HP-UX) case `uname -r` in
113 A.09*) os="${os}-9";;
114 esac;;
115esac
116
117# Need to distinguish Solaris from the version on the HAL (64bit sparc,
118# CC=hcc -DV7). Also need to distinguish different versions of the OS
119# for building different binaries.
120
121case "$os" in
122SunOS5) case `uname -m` in
123 sun4H) os="${os}-hal";;
124 *) os="${os}-`uname -r`";;
125 esac
126 ;;
127
128# In the case of Linux we used to distinguish which libc was used so that
129# the old libc5 was supported as well as the current glibc. This support
130# was giving some people problems, so it was removed in June 2005, under
131# the assumption that nobody would be using libc5 any more (it is over seven
132# years old).
133
134# In the case of NetBSD we need to distinguish between a.out, ELF
135# and COFF binary formats. However, a.out and COFF are the same
136# for our purposes, so both of them are defined as "a.out".
137# Todd Vierling of Wasabi Systems reported that NetBSD/sh3 (the
138# only NetBSD port that uses COFF binary format) will switch to
139# ELF soon.
140
141NetBSD) if echo __ELF__ | ${CC-cc} -E - | grep -q __ELF__ ; then
142 # Non-ELF system
143 os="NetBSD-a.out"
144 fi
145 ;;
146
147esac
148
149# If a generic OS name is requested, some further massaging is needed
150# for some systems.
151
152if [ "$1" = '-generic' ]; then
153 case "$os" in
154 SunOS5*) os=SunOS5;;
155 BSDI*) os=BSDI;;
156 IRIX65*) os=IRIX65;;
157 esac
158fi
159
160# OK, the script seems to have worked. Pass the value back.
161
162echo "$os"
163
164# End of os-type