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