xref: /freebsd/contrib/bmake/machine.sh (revision fed1ca4b719c56c930f2259d80663cd34be812bb)
1:
2# derrived from /etc/rc_d/os.sh
3
4# RCSid:
5#	$Id: machine.sh,v 1.17 2015/05/05 00:10:54 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
47OpenBSD)
48	MACHINE=$OS$OSMAJOR.$machine
49	arch=`Which arch /usr/bin:/usr/ucb:$PATH`
50	MACHINE_ARCH=`$arch -s`;
51	;;
52Bitrig)
53	MACHINE=$OS$OSMAJOR.$machine
54	MACHINE_ARCH=`uname -m`;
55	;;
56*BSD)
57	MACHINE=$OS$OSMAJOR.$machine
58	;;
59SunOS)
60	arch=`Which arch /usr/bin:/usr/ucb:$PATH`
61	test "$arch" && machine_arch=`$arch`
62
63	case "$OSREL" in
64	4.0*) MACHINE_ARCH=$machine_arch MACHINE=$machine_arch;;
65	4*) MACHINE_ARCH=$machine_arch;;
66	esac
67	;;
68HP-UX)
69	MACHINE_ARCH=`IFS="/-."; set $machine; echo $1`
70	;;
71Interix)
72	MACHINE=i386
73	MACHINE_ARCH=i386
74	;;
75UnixWare)
76	OSREL=`uname -v`
77	OSMAJOR=`IFS=.; set $OSREL; echo $1`
78	MACHINE_ARCH=`uname -m`
79	;;
80Linux)
81        case "$machine" in
82	i?86) MACHINE_ARCH=i386;;# does anyone really care about 686 vs 586?
83	esac
84        ;;
85esac
86
87MACHINE=${MACHINE:-$OS$OSMAJOR}
88MACHINE_ARCH=${MACHINE_ARCH:-$machine}
89
90(
91case "$0" in
92arch*)	echo $MACHINE_ARCH;;
93*)
94	case "$1" in
95	"")	echo $MACHINE;;
96	*)	echo $MACHINE_ARCH;;
97	esac
98	;;
99esac
100) | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
101