: # derrived from /etc/rc_d/os.sh # RCSid: # $Id: machine.sh,v 1.17 2015/05/05 00:10:54 sjg Exp $ # # @(#) Copyright (c) 1994-2002 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 # setglobal OS = $[uname] setglobal OSREL = $[uname -r] setglobal OSMAJOR = $[setglobal IFS = '.'; set $OSREL; echo $1] setglobal machine = $[uname -p 2>/dev/null || uname -m] setglobal MACHINE = '' # there is at least one case of `uname -p` outputting # a bunch of usless drivel match $machine { with unknown|*[!A-Za-z0-9_-]* setglobal machine = $[uname -m] } # Great! Solaris keeps moving arch(1) # we need this here, and it is not always available... proc Which { # some shells cannot correctly handle `IFS` # in conjunction with the for loop. setglobal _dirs = $[setglobal IFS = ':'; echo $(2:-$PATH)] for d in [$_dirs] { test -x $d/$1 && do { echo $d/$1; break; } } } match $OS { with OpenBSD setglobal MACHINE = "$OS$OSMAJOR.$machine" setglobal arch = $[Which arch /usr/bin:/usr/ucb:$PATH] setglobal MACHINE_ARCH = $[$arch -s]; with Bitrig setglobal MACHINE = "$OS$OSMAJOR.$machine" setglobal MACHINE_ARCH = $[uname -m]; with *BSD setglobal MACHINE = "$OS$OSMAJOR.$machine" with SunOS setglobal arch = $[Which arch /usr/bin:/usr/ucb:$PATH] test $arch && setglobal machine_arch = $[$arch] match $OSREL { with 4.0* setglobal MACHINE_ARCH = $machine_arch, MACHINE = $machine_arch with 4* setglobal MACHINE_ARCH = $machine_arch } with HP-UX setglobal MACHINE_ARCH = $[setglobal IFS = '"/-.'"; set $machine; echo $1] with Interix setglobal MACHINE = 'i386' setglobal MACHINE_ARCH = 'i386' with UnixWare setglobal OSREL = $[uname -v] setglobal OSMAJOR = $[setglobal IFS = '.'; set $OSREL; echo $1] setglobal MACHINE_ARCH = $[uname -m] with Linux match $machine { with i?86 setglobal MACHINE_ARCH = 'i386'# does anyone really care about 686 vs 586? } } setglobal MACHINE = $(MACHINE:-$OS$OSMAJOR) setglobal MACHINE_ARCH = $(MACHINE_ARCH:-$machine) shell { match $0 { with arch* echo $MACHINE_ARCH with * match $1 { with "" echo $MACHINE with * echo $MACHINE_ARCH } } } | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz