xref: /freebsd/contrib/bmake/machine.sh (revision a0409676120c1e558d0ade943019934e0f15118d)
1:
2# derrived from /etc/rc_d/os.sh
3
4# RCSid:
5#	$Id: machine.sh,v 1.18 2017/08/13 19:11:28 sjg Exp $
6#
7#	@(#) Copyright (c) 1994-2002 Simon J. Gerraty
8#
9#	This file is provided in the hope that it will
10#	be of use.  There is absolutely NO WARRANTY.
11#	Permission to copy, redistribute or otherwise
12#	use this file is hereby granted provided that
13#	the above copyright notice and this notice are
14#	left intact.
15#
16#	Please send copies of changes and bug-fixes to:
17#	sjg@crufty.net
18#
19
20OS=`uname`
21OSREL=`uname -r`
22OSMAJOR=`IFS=.; set $OSREL; echo $1`
23machine=`uname -p 2>/dev/null || uname -m`
24MACHINE=
25
26# there is at least one case of `uname -p` outputting
27# a bunch of usless drivel
28case "$machine" in
29unknown|*[!A-Za-z0-9_-]*)
30        machine=`uname -m`
31        ;;
32esac
33
34# Great! Solaris keeps moving arch(1)
35# we need this here, and it is not always available...
36Which() {
37	# some shells cannot correctly handle `IFS`
38	# in conjunction with the for loop.
39	_dirs=`IFS=:; echo ${2:-$PATH}`
40	for d in $_dirs
41	do
42		test -x $d/$1 && { echo $d/$1; break; }
43	done
44}
45
46case $OS in
47AIX)	# from http://gnats.netbsd.org/29386
48	OSMAJOR=`uname -v`
49	OSMINOR=`uname -r`
50	MACHINE=$OS$OSMAJOR.$OSMINOR
51	MACHINE_ARCH=`bootinfo -T`
52	;;
53OpenBSD)
54	MACHINE=$OS$OSMAJOR.$machine
55	arch=`Which arch /usr/bin:/usr/ucb:$PATH`
56	MACHINE_ARCH=`$arch -s`;
57	;;
58Bitrig)
59	MACHINE=$OS$OSMAJOR.$machine
60	MACHINE_ARCH=`uname -m`;
61	;;
62*BSD)
63	MACHINE=$OS$OSMAJOR.$machine
64	;;
65SunOS)
66	arch=`Which arch /usr/bin:/usr/ucb:$PATH`
67	test "$arch" && machine_arch=`$arch`
68
69	case "$OSREL" in
70	4.0*) MACHINE_ARCH=$machine_arch MACHINE=$machine_arch;;
71	4*) MACHINE_ARCH=$machine_arch;;
72	esac
73	;;
74HP-UX)
75	MACHINE_ARCH=`IFS="/-."; set $machine; echo $1`
76	;;
77Interix)
78	MACHINE=i386
79	MACHINE_ARCH=i386
80	;;
81UnixWare)
82	OSREL=`uname -v`
83	OSMAJOR=`IFS=.; set $OSREL; echo $1`
84	MACHINE_ARCH=`uname -m`
85	;;
86Linux)
87        case "$machine" in
88	i?86) MACHINE_ARCH=i386;;# does anyone really care about 686 vs 586?
89	esac
90        ;;
91esac
92
93MACHINE=${MACHINE:-$OS$OSMAJOR}
94MACHINE_ARCH=${MACHINE_ARCH:-$machine}
95
96(
97case "$0" in
98arch*)	echo $MACHINE_ARCH;;
99*)
100	case "$1" in
101	"")	echo $MACHINE;;
102	*)	echo $MACHINE_ARCH;;
103	esac
104	;;
105esac
106) | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
107