kgdb(1): Add missing "
[dragonfly.git] / contrib / bmake / os.sh
blobaba9bbdd8a80d3026131d06778d36f3355814528
2 # NAME:
3 # os.sh - operating system specifics
5 # DESCRIPTION:
6 # This file is included at the start of processing. Its role is
7 # to set the variables OS, OSREL, OSMAJOR, MACHINE and MACHINE_ARCH to
8 # reflect the current system.
9 #
10 # It also sets variables such as MAILER, LOCAL_FS, PS_AXC to hide
11 # certain aspects of different UNIX flavours.
13 # SEE ALSO:
14 # site.sh,funcs.sh
16 # AUTHOR:
17 # Simon J. Gerraty <sjg@crufty.net>
19 # RCSid:
20 # $Id: os.sh,v 1.52 2016/06/17 05:15:14 sjg Exp $
22 # @(#) Copyright (c) 1994 Simon J. Gerraty
24 # This file is provided in the hope that it will
25 # be of use. There is absolutely NO WARRANTY.
26 # Permission to copy, redistribute or otherwise
27 # use this file is hereby granted provided that
28 # the above copyright notice and this notice are
29 # left intact.
31 # Please send copies of changes and bug-fixes to:
32 # sjg@crufty.net
35 # this lets us skip sourcing it again
36 _OS_SH=:
38 OS=`uname`
39 OSREL=`uname -r`
40 OSMAJOR=`IFS=.; set $OSREL; echo $1`
41 MACHINE=`uname -m`
42 MACHINE_ARCH=`uname -p 2>/dev/null || echo $MACHINE`
44 # there is at least one case of `uname -p` outputting
45 # a bunch of usless drivel
46 case "$MACHINE_ARCH" in
47 unknown|*[!A-Za-z0-9_-]*) MACHINE_ARCH="$MACHINE";;
48 esac
50 # we need this here, and it is not always available...
51 Which() {
52 case "$1" in
53 -*) t=$1; shift;;
54 *) t=-x;;
55 esac
56 case "$1" in
57 /*) test $t $1 && echo $1;;
59 # some shells cannot correctly handle `IFS`
60 # in conjunction with the for loop.
61 _dirs=`IFS=:; echo ${2:-$PATH}`
62 for d in $_dirs
64 test $t $d/$1 && { echo $d/$1; break; }
65 done
67 esac
70 # tr is insanely non-portable wrt char classes, so we need to
71 # spell out the alphabet. sed y/// would work too.
72 toUpper() {
73 ${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
76 toLower() {
77 ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
81 case $OS in
82 AIX) # everyone loves to be different...
83 OSMAJOR=`uname -v`
84 OSREL="$OSMAJOR.`uname -r`"
85 LOCAL_FS=jfs
86 PS_AXC=-e
87 SHARE_ARCH=$OS/$OSMAJOR.X
89 SunOS)
90 CHOWN=`Which chown /usr/etc:/usr/bin`
91 export CHOWN
93 # Great! Solaris keeps moving arch(1)
94 # should just bite the bullet and use uname -p
95 arch=`Which arch /usr/bin:/usr/ucb`
97 MAILER=/usr/ucb/Mail
98 LOCAL_FS=4.2
100 case "$OSREL" in
101 4.0*)
102 # uname -m just says sun which could be anything
103 # so use arch(1).
104 MACHINE_ARCH=`arch`
105 MACHINE=$MACHINE_ARCH
108 MACHINE_ARCH=`arch`
111 K=-k
112 LOCAL_FS=ufs
113 MAILER=mailx
114 PS_AXC=-e
115 # can you believe that ln on Solaris defaults to
116 # overwriting an existing file!!!!! We want one that works!
117 test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln}
118 # wonderful, 5.8's tr again require's []'s
119 # but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
120 # use toUpper/toLower instead.
122 esac
123 case "$OS/$MACHINE_ARCH" in
124 *sun386) SHARE_ARCH=$MACHINE_ARCH;;
125 esac
127 *BSD)
128 K=-k
129 MAILER=/usr/bin/Mail
130 LOCAL_FS=local
131 : $-,$ENV
132 case "$-,$ENV" in
133 *i*,*) ;;
134 *,|*ENVFILE*) ;;
135 *) ENV=;;
136 esac
137 # NetBSD at least has good backward compatibility
138 # so NetBSD/i386 is good enough
139 case $OS in
140 NetBSD)
141 HOST_ARCH=$MACHINE
142 SHARE_ARCH=$OS/$HOST_ARCH
144 OpenBSD)
145 arch=`Which arch /usr/bin:/usr/ucb:$PATH`
146 MACHINE_ARCH=`$arch -s`
148 esac
149 NAWK=awk
150 export NAWK
152 HP-UX)
153 TMP_DIRS="/tmp /usr/tmp"
154 LOCAL_FS=hfs
155 MAILER=mailx
156 # don't rely on /bin/sh, its broken
157 _shell=/bin/ksh; ENV=
158 # also, no one would be interested in OSMAJOR=A
159 case "$OSREL" in
160 ?.09*) OSMAJOR=9; PS_AXC=-e;;
161 ?.10*) OSMAJOR=10; PS_AXC=-e;;
162 esac
164 IRIX)
165 LOCAL_FS=efs
167 Interix)
168 MACHINE=i386
169 MACHINE_ARCH=i386
171 UnixWare)
172 OSREL=`uname -v`
173 OSMAJOR=`IFS=.; set $OSREL; echo $1`
174 MACHINE_ARCH=`uname -m`
176 Linux)
177 # Not really any such thing as Linux, but
178 # this covers red-hat and hopefully others.
179 case $MACHINE in
180 i?86) MACHINE_ARCH=i386;; # we don't care about i686 vs i586
181 esac
182 LOCAL_FS=ext2
183 PS_AXC=axc
184 [ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; }
186 QNX)
187 case $MACHINE in
188 x86pc) MACHINE_ARCH=i386;;
189 esac
191 Haiku)
192 case $MACHINE in
193 BeBox) MACHINE_ARCH=powerpc;;
194 BeMac) MACHINE_ARCH=powerpc;;
195 BePC) MACHINE_ARCH=i386;;
196 esac
198 esac
200 HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`}
201 HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`}
202 case "$HOSTNAME" in
203 *.*) HOST=`IFS=.; set -- $HOSTNAME; echo $1`;;
204 *) HOST=$HOSTNAME;;
205 esac
207 TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
208 MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
209 HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH}
210 # we mount server:/share/arch/$SHARE_ARCH as /usr/local
211 SHARE_ARCH_DEFAULT=$OS/$OSMAJOR.X/$HOST_ARCH
212 SHARE_ARCH=${SHARE_ARCH:-$SHARE_ARCH_DEFAULT}
213 LN=${LN:-ln}
214 TR=${TR:-tr}
216 # Some people like have /share/$HOST_TARGET/bin etc.
217 HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
218 export HOST_TARGET
220 case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
222 Echo() {
223 case "$1" in
224 -n) _n=$N _c=$C; shift;;
225 *) _n= _c=;;
226 esac
227 echo $_n "$@" $_c
230 export HOSTNAME HOST
231 export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
232 export LN SHARE_ARCH TR
234 case /$0 in
235 */os.sh)
236 for v in $*
238 eval vv=\$$v
239 echo "$v='$vv'"
240 done
242 esac