]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/os.sh
libedit: update to snapshot 2023-01-06
[FreeBSD/FreeBSD.git] / contrib / bmake / os.sh
1 :
2 # NAME:
3 #       os.sh - operating system specifics
4 #
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. 
12 #
13 # SEE ALSO:
14 #       site.sh,funcs.sh
15 #
16 # AUTHOR:
17 #       Simon J. Gerraty <sjg@crufty.net>
18
19 # RCSid:
20 #       $Id: os.sh,v 1.62 2023/01/17 18:30:21 sjg Exp $
21 #
22 #       @(#) Copyright (c) 1994 Simon J. Gerraty
23 #
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. 
30 #      
31 #       Please send copies of changes and bug-fixes to:
32 #       sjg@crufty.net
33 #
34
35 # this lets us skip sourcing it again
36 _OS_SH=:
37
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`
43
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
49         
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;;
58         *)
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
63                 do
64                         test $t $d/$1 && { echo $d/$1; break; }
65                 done
66                 ;;
67         esac
68 }
69
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
74 }
75
76 toLower() {
77         ${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
78 }
79
80 K=
81 case "$OS" in
82 AIX)    # everyone loves to be different...
83         OSMAJOR=`uname -v`
84         OSMINOR=`uname -r`
85         OSREL="$OSMAJOR.$OSMINOR"
86         LOCAL_FS=jfs
87         PS_AXC=-e
88         SHARE_ARCH=$OS/$OSMAJOR.X
89         ;;
90 Darwin) # a bit like BSD
91         HOST_ARCH=$MACHINE
92         ;;
93 SunOS)
94         CHOWN=`Which chown /usr/etc:/usr/bin`
95         export CHOWN
96         
97         # Great! Solaris keeps moving arch(1)
98         # should just bite the bullet and use uname -p
99         arch=`Which arch /usr/bin:/usr/ucb`
100         
101         MAILER=/usr/ucb/Mail
102         LOCAL_FS=4.2
103         
104         case "$OSREL" in
105         4.0*)
106                 # uname -m just says sun which could be anything
107                 # so use arch(1).
108                 MACHINE_ARCH=`arch`
109                 MACHINE=$MACHINE_ARCH
110                 ;;
111         4*)
112                 MACHINE_ARCH=`arch`
113                 ;;
114         5*)
115                 K=-k
116                 LOCAL_FS=ufs
117                 MAILER=mailx
118                 PS_AXC=-e
119                 # can you believe that ln on Solaris defaults to
120                 # overwriting an existing file!!!!! We want one that works!
121                 test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln}
122                 # wonderful, 5.8's tr again require's []'s
123                 # but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
124                 # use toUpper/toLower instead.
125                 ;;
126         esac
127         case "$OS/$MACHINE_ARCH" in
128         *sun386)        SHARE_ARCH=$MACHINE_ARCH;;
129         esac
130         ;;
131 *BSD)
132         K=-k
133         MAILER=/usr/bin/Mail
134         LOCAL_FS=local
135         : $-,$ENV
136         case "$-,$ENV" in
137         *i*,*) ;;
138         *,|*ENVFILE*) ;;
139         *) ENV=;;
140         esac
141         # NetBSD at least has good backward compatibility
142         # so NetBSD/i386 is good enough
143         case $OS in
144         NetBSD)
145                 LOCALBASE=/usr/pkg
146                 HOST_ARCH=$MACHINE
147                 SHARE_ARCH=$OS/$HOST_ARCH
148                 ;;
149         OpenBSD)
150                 arch=`Which arch /usr/bin:/usr/ucb:$PATH`
151                 MACHINE_ARCH=`$arch -s`
152                 ;;
153         esac
154         NAWK=awk
155         export NAWK
156         ;;
157 HP-UX)
158         TMP_DIRS="/tmp /usr/tmp"
159         LOCAL_FS=hfs
160         MAILER=mailx
161         # don't rely on /bin/sh, its broken
162         _shell=/bin/ksh; ENV=
163         # also, no one would be interested in OSMAJOR=A
164         case "$OSREL" in
165         ?.09*)  OSMAJOR=9; PS_AXC=-e;;
166         ?.10*)  OSMAJOR=10; PS_AXC=-e;;
167         esac
168         ;;
169 IRIX)
170         LOCAL_FS=efs
171         ;;
172 Interix)
173         MACHINE=i386
174         MACHINE_ARCH=i386
175         ;;
176 UnixWare|SCO_SV)
177         OSREL=`uname -v`
178         OSMAJOR=`IFS=.; set $OSREL; echo $1`
179         MACHINE_ARCH=`uname -m`
180         ;;
181 Linux)
182         # Not really any such thing as Linux, but
183         # this covers red-hat and hopefully others.
184         case $MACHINE in
185         i?86)   MACHINE_ARCH=i386;; # we don't care about i686 vs i586
186         esac
187         LOCAL_FS=ext2
188         PS_AXC=axc
189         [ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; }
190         ;;
191 QNX)
192         case $MACHINE in
193         x86pc)  MACHINE_ARCH=i386;;
194         esac
195         ;;
196 Haiku)
197         case $MACHINE in
198         BeBox)  MACHINE_ARCH=powerpc;;
199         BeMac)  MACHINE_ARCH=powerpc;;
200         BePC)   MACHINE_ARCH=i386;;
201         esac
202         ;;
203 esac
204 LOCALBASE=${LOCALBASE:-/usr/local}
205
206 HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`}
207 HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`}
208 case "$HOSTNAME" in
209 *.*)    HOST=`IFS=.; set -- $HOSTNAME; echo $1`;;
210 *)      HOST=$HOSTNAME;;
211 esac
212
213 TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
214 MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
215 HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH}
216 case "$HOST_ARCH" in
217 x86*64|amd64) MACHINE32_ARCH=i386;;
218 *64) MACHINE32_ARCH=`echo $MACHINE_ARCH | sed 's,64,32,'`;;
219 *) MACHINE32_ARCH=$MACHINE_ARCH;;
220 esac
221 HOST_ARCH32=${HOST_ARCH32:-$MACHINE32_ARCH}
222 # we mount server:/share/arch/$SHARE_ARCH as /usr/local
223 SHARE_ARCH_DEFAULT=$OS/$OSMAJOR.X/$HOST_ARCH
224 SHARE_ARCH=${SHARE_ARCH:-$SHARE_ARCH_DEFAULT}
225 LN=${LN:-ln}
226 TR=${TR:-tr}
227
228 # Some people like have /share/$HOST_TARGET/bin etc.
229 HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
230 HOST_TARGET32=`echo ${OS}${OSMAJOR}-$HOST_ARCH32 | tr -d / | toLower`
231 export HOST_TARGET HOST_TARGET32
232
233 case `echo -n .` in -n*) echo_n=; echo_c="\c";; *) echo_n=-n; echo_c=;; esac
234
235 Echo() {
236         case "$1" in
237         -n) shift; echo $echo_n "$@$echo_c";;
238         *)  echo "$@";;
239         esac
240 }
241
242 # for systems that deprecate egrep
243 case "`echo egrep | egrep 'e|g' 2>&1`" in
244 egrep) ;;
245 *) egrep() { grep -E "$@"; };;
246 esac
247
248 export HOSTNAME HOST        
249 export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
250 export LN SHARE_ARCH TR
251 export LOCALBASE
252
253 case /$0 in
254 */os.sh)
255         for v in $*
256         do
257                 eval vv=\$$v
258                 echo "$v='$vv'"
259         done
260         ;;
261 */host_target32) echo $HOST_TARGET32;;
262 */host_target) echo $HOST_TARGET;;
263 esac
264