summaryrefslogtreecommitdiffstats
path: root/contrib/bmake/os.sh
blob: 1dd394f3837f1edff0ab3f98b29a92f222395fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
:
# NAME:
#	os.sh - operating system specifics
#
# DESCRIPTION:
#	This file is included at the start of processing. Its role is
#	to set the variables OS, OSREL, OSMAJOR, MACHINE and MACHINE_ARCH to
#	reflect the current system.
#	
#	It also sets variables such as MAILER, LOCAL_FS, PS_AXC to hide
#	certain aspects of different UNIX flavours. 
#
# SEE ALSO:
#	site.sh,funcs.sh
#
# AUTHOR:
#	Simon J. Gerraty <sjg@crufty.net>

# RCSid:
#	$Id: os.sh,v 1.50 2015/12/17 17:06:29 sjg Exp $
#
#	@(#) Copyright (c) 1994 Simon J. Gerraty
#
#	This file is provided in the hope that it will
#	be of use.  There is absolutely NO WARRANTY.
#	Permission to copy, redistribute or otherwise
#	use this file is hereby granted provided that 
#	the above copyright notice and this notice are
#	left intact. 
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net
#

# this lets us skip sourcing it again
_OS_SH=:

OS=`uname`
OSREL=`uname -r`
OSMAJOR=`IFS=.; set $OSREL; echo $1`
MACHINE=`uname -m`
MACHINE_ARCH=`uname -p 2>/dev/null || echo $MACHINE`

# there is at least one case of `uname -p` outputting
# a bunch of usless drivel
case "$MACHINE_ARCH" in
unknown|*[!A-Za-z0-9_-]*) MACHINE_ARCH="$MACHINE";;
esac
        
# we need this here, and it is not always available...
Which() {
	case "$1" in
	-*) t=$1; shift;;
	*) t=-x;;
	esac
	case "$1" in
	/*)	test $t $1 && echo $1;;
	*)
		# some shells cannot correctly handle `IFS`
		# in conjunction with the for loop.
		_dirs=`IFS=:; echo ${2:-$PATH}`
		for d in $_dirs
		do
			test $t $d/$1 && { echo $d/$1; break; }
		done
		;;
	esac
}

# tr is insanely non-portable wrt char classes, so we need to
# spell out the alphabet. sed y/// would work too.
toUpper() {
	${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
}

toLower() {
	${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}

K=
case $OS in
AIX)	# everyone loves to be different...
	OSMAJOR=`uname -v`
	OSREL="$OSMAJOR.`uname -r`"
	LOCAL_FS=jfs
	PS_AXC=-e
	SHARE_ARCH=$OS/$OSMAJOR.X
	;;
SunOS)
	CHOWN=`Which chown /usr/etc:/usr/bin`
	export CHOWN
	
	# Great! Solaris keeps moving arch(1)
	# should just bite the bullet and use uname -p
	arch=`Which arch /usr/bin:/usr/ucb`
	
	MAILER=/usr/ucb/Mail
	LOCAL_FS=4.2
	
	case "$OSREL" in
	4.0*)
		# uname -m just says sun which could be anything
		# so use arch(1).
		MACHINE_ARCH=`arch`
		MACHINE=$MACHINE_ARCH
		;;
	4*)
		MACHINE_ARCH=`arch`
		;;
	5*)
		K=-k
		LOCAL_FS=ufs
		MAILER=mailx
		PS_AXC=-e
		# can you believe that ln on Solaris defaults to
		# overwriting an existing file!!!!! We want one that works!
		test -x /usr/xpg4/bin/ln && LN=${LN:-/usr/xpg4/bin/ln}
		# wonderful, 5.8's tr again require's []'s
		# but /usr/xpg4/bin/tr causes problems if LC_COLLATE is set!
		# use toUpper/toLower instead.
		;;
	esac
	case "$OS/$MACHINE_ARCH" in
	*sun386)	SHARE_ARCH=$MACHINE_ARCH;;
	esac
	;;
*BSD)
	K=-k
	MAILER=/usr/bin/Mail
	LOCAL_FS=local
	: $-,$ENV
	case "$-,$ENV" in
	*i*,*) ;;
	*,|*ENVFILE*) ;;
	*) ENV=;;
	esac
	# NetBSD at least has good backward compatibility
	# so NetBSD/i386 is good enough
	case $OS in
	NetBSD)
		HOST_ARCH=$MACHINE
		SHARE_ARCH=$OS/$HOST
		;;
	OpenBSD)
		arch=`Which arch /usr/bin:/usr/ucb:$PATH`
		MACHINE_ARCH=`$arch -s`
		;;
	esac
	NAWK=awk
	export NAWK
	;;
HP-UX)
	TMP_DIRS="/tmp /usr/tmp"
	LOCAL_FS=hfs
	MAILER=mailx
	# don't rely on /bin/sh, its broken
	_shell=/bin/ksh; ENV=
	# also, no one would be interested in OSMAJOR=A
	case "$OSREL" in
	?.09*)	OSMAJOR=9; PS_AXC=-e;;
	?.10*)	OSMAJOR=10; PS_AXC=-e;;
	esac
	;;
IRIX)
	LOCAL_FS=efs
	;;
Interix)
	MACHINE=i386
	MACHINE_ARCH=i386
	;;
UnixWare)
	OSREL=`uname -v`
	OSMAJOR=`IFS=.; set $OSREL; echo $1`
	MACHINE_ARCH=`uname -m`
	;;
Linux)
	# Not really any such thing as Linux, but
	# this covers red-hat and hopefully others.
	case $MACHINE in
	i?86)	MACHINE_ARCH=i386;; # we don't care about i686 vs i586
	esac
	LOCAL_FS=ext2
	PS_AXC=axc
	[ -x /usr/bin/md5sum ] && { MD5=/usr/bin/md5sum; export MD5; }
	;;
QNX)
	case $MACHINE in
	x86pc)	MACHINE_ARCH=i386;;
	esac
	;;
Haiku)
	case $MACHINE in
	BeBox)	MACHINE_ARCH=powerpc;;
	BeMac)	MACHINE_ARCH=powerpc;;
	BePC)	MACHINE_ARCH=i386;;
	esac
	;;
esac

HOSTNAME=${HOSTNAME:-`( hostname ) 2>/dev/null`}
HOSTNAME=${HOSTNAME:-`( uname -n ) 2>/dev/null`}
case "$HOSTNAME" in
*.*)	HOST=`IFS=.; set -- $HOSTNAME; echo $1`;;
*)	HOST=$HOSTNAME;;
esac

TMP_DIRS=${TMP_DIRS:-"/tmp /var/tmp"}
MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH}
# we mount server:/share/arch/$SHARE_ARCH as /usr/local
SHARE_ARCH=${SHARE_ARCH:-$OS/$OSMAJOR.X/$HOST_ARCH}
LN=${LN:-ln}
TR=${TR:-tr}

# Some people like have /share/$HOST_TARGET/bin etc.
HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
export HOST_TARGET

case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac

Echo() {
	case "$1" in
	-n) _n=$N _c=$C; shift;;
	*) _n= _c=;;
	esac
	echo $_n "$@" $_c
}

export HOSTNAME HOST	    
export OS MACHINE MACHINE_ARCH OSREL OSMAJOR LOCAL_FS TMP_DIRS MAILER N C K PS_AXC
export LN SHARE_ARCH TR

case /$0 in
*/os.sh)
	for v in $*
	do
		eval vv=\$$v
		echo "$v='$vv'"
	done
	;;
esac

OpenPOWER on IntegriCloud