aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/os.sh
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bmake/os.sh')
-rwxr-xr-xcontrib/bmake/os.sh52
1 files changed, 36 insertions, 16 deletions
diff --git a/contrib/bmake/os.sh b/contrib/bmake/os.sh
index 1fc66ecc6a63..13b0730464e9 100755
--- a/contrib/bmake/os.sh
+++ b/contrib/bmake/os.sh
@@ -17,7 +17,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
-# $Id: os.sh,v 1.59 2021/11/14 04:18:00 sjg Exp $
+# $Id: os.sh,v 1.67 2025/02/13 21:04:34 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@@ -38,15 +38,23 @@ _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`
+# we want to retain the raw output from uname -m and -p
+OS_MACHINE=`uname -m`
+OS_MACHINE_ARCH=`uname -p 2>/dev/null || echo $OS_MACHINE`
-# there is at least one case of `uname -p` outputting
-# a bunch of usless drivel
+MACHINE=$OS_MACHINE
+MACHINE_ARCH=$OS_MACHINE_ARCH
+
+# there is at least one case of `uname -p`
+# and even `uname -m` outputting usless info
+# fortunately not both together
+case "$MACHINE" in
+*[!A-Za-z0-9_-]*) MACHINE="$MACHINE_ARCH";;
+esac
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
@@ -78,15 +86,20 @@ toLower() {
}
K=
-case $OS in
+case "$OS" in
AIX) # everyone loves to be different...
OSMAJOR=`uname -v`
- OSREL="$OSMAJOR.`uname -r`"
+ OSMINOR=`uname -r`
+ OSREL="$OSMAJOR.$OSMINOR"
LOCAL_FS=jfs
PS_AXC=-e
SHARE_ARCH=$OS/$OSMAJOR.X
;;
-Darwin) # a bit like BSD
+CYGWIN*) # uname -s not very useful
+ # uname -o produces just Cygwin which is better
+ OS=Cygwin
+ ;;
+Darwin) # this is more explicit (arm64 vs arm)
HOST_ARCH=$MACHINE
;;
SunOS)
@@ -139,10 +152,10 @@ SunOS)
esac
# NetBSD at least has good backward compatibility
# so NetBSD/i386 is good enough
+ # recent NetBSD uses x86_64 for MACHINE_ARCH
case $OS in
NetBSD)
LOCALBASE=/usr/pkg
- HOST_ARCH=$MACHINE
SHARE_ARCH=$OS/$HOST_ARCH
;;
OpenBSD)
@@ -214,10 +227,11 @@ MACHINE_ARCH=${MACHINE_ARCH:-$MACHINE}
HOST_ARCH=${HOST_ARCH:-$MACHINE_ARCH}
case "$HOST_ARCH" in
x86*64|amd64) MACHINE32_ARCH=i386;;
-*64) MACHINE32_ARCH=`echo $MACHINE_ARCH | sed 's,64,32,'`;;
+*64) MACHINE32_ARCH=${MACHINE32_ARCH:-`echo $MACHINE_ARCH | sed 's,64,32,'`};;
*) MACHINE32_ARCH=$MACHINE_ARCH;;
esac
HOST_ARCH32=${HOST_ARCH32:-$MACHINE32_ARCH}
+export HOST_ARCH HOST_ARCH32
# we mount server:/share/arch/$SHARE_ARCH as /usr/local
SHARE_ARCH_DEFAULT=$OS/$OSMAJOR.X/$HOST_ARCH
SHARE_ARCH=${SHARE_ARCH:-$SHARE_ARCH_DEFAULT}
@@ -229,16 +243,23 @@ HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
HOST_TARGET32=`echo ${OS}${OSMAJOR}-$HOST_ARCH32 | tr -d / | toLower`
export HOST_TARGET HOST_TARGET32
-case `echo -n .` in -n*) N=; C="\c";; *) N=-n; C=;; esac
+case `echo -e .` in -e*) echo_e=;; *) echo_e=-e;; esac
+case `echo -n .` in -n*) echo_n=; echo_c="\c";; *) echo_n=-n; echo_c=;; esac
Echo() {
case "$1" in
- -n) _n=$N _c=$C; shift;;
- *) _n= _c=;;
+ -e) shift; echo $echo_e "$@";;
+ -n) shift; echo $echo_n "$@$echo_c";;
+ *) echo "$@";;
esac
- echo $_n "$@" $_c
}
+# for systems that deprecate egrep
+case "`echo egrep | egrep 'e|g' 2>&1`" in
+egrep) ;;
+*) egrep() { grep -E "$@"; };;
+esac
+
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
@@ -255,4 +276,3 @@ case /$0 in
*/host_target32) echo $HOST_TARGET32;;
*/host_target) echo $HOST_TARGET;;
esac
-