freebsd-src/contrib/bmake/os.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

273 lines
6 KiB
Bash
Raw Normal View History

:
# 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:
Import bmake-20240430 Intersting/relevant changes since bmake-20240309 ChangeLog since bmake-20240309 2024-04-30 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240430 Merge with NetBSD make, pick up o main.c: ensure '.include <makefile>' respects MAKESYSPATH. Dir_FindFile will search .CURDIR first unless ".DOTLAST" is seen. 2024-04-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240428 Merge with NetBSD make, pick up o simplify freeing of lists o arch.c: trim pointless comments o var.c: delay variable assignments until actually needed don't reallocate memory after evaluating an expression, result is almost always short-lived. 2024-04-26 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240426 Merge with NetBSD make, pick up o job.c: in debug output, print the directory in which a job failed at same time as failed target so it is more easily found in build log. 2024-04-24 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240424 Merge with NetBSD make, pick up o clean up comments, code and tests 2024-04-23 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240422 Merge with NetBSD make, pick up o var.c: avoid LazyBuf for :*time modifiers. LazyBuf's are not nul terminated so not suitable for passing to functions that expect that. These modifiers are used sparingly so an extra allocation is not a problem. 2024-04-20 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240420 Merge with NetBSD make, pick up o provide more context information for parse/evaluate errors 2024-04-14 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240414 Merge with NetBSD make, pick up o parse.c: print -dp debug info earlier so we see which .if or .for line is being parsed. 2024-04-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240404 Merge with NetBSD make, pick up o fix some unit tests for Cygwin o parse.c: exit immediately after reading a null byte from a makefile * fix generation of bmake.cat1 2024-03-19 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240314 Add/Improve support for Cygwin o uname -s output isn't useful so allow configure to set FORCE_MAKE_OS - to force the value of .MAKE.OS and use Cygwin which matches uname -o o fix some unit-tests for Cygwin * configure.in: use_makefile=no for Cygwin et al. NOTE: bmake does not support Cygwin and likely never will, mk/ChangeLog since bmake-20240309 2024-04-24 Simon J Gerraty <sjg@beast.crufty.net> * meta.autodep.mk: do not override start_utc 2024-04-18 Simon J Gerraty <sjg@beast.crufty.net> * sys.dirdeps.mk: set defaults for DEP_* at level 0 too. These help when first include of Makefile.depend happens in a leaf dir. * install-mk (MK_VERSION): 20240414 2024-04-09 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240408 * init.mk: allow for _ as well as . to join V and Q from QUALIFIED_VAR_LIST and VAR_QUALIFIER_LIST. * progs.mk: avoid overlap between PROG_VARS and init.mk's QUALIFIED_VAR_LIST since PROG would also match its VAR_QUALIFIER_LIST, libs.mk does not have the same issue. * subdir.mk: _SUBDIRUSE for realinstall should run install remove include of ${.CURDIR}/Makefile.inc that can be done via local.subdir.mk where needed * own.mk: do not conflict with man.mk 2024-03-19 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240314 * add sys/Cygwin.mk from Christian Franke
2024-05-03 22:43:12 +00:00
# $Id: os.sh,v 1.64 2024/03/19 16:03:23 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`
# 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
2015-12-07 22:51:25 +00:00
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;;
*)
2015-12-25 08:09:48 +00:00
# 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() {
2015-12-25 08:09:48 +00:00
${TR:-tr} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
}
toLower() {
2015-12-25 08:09:48 +00:00
${TR:-tr} ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}
K=
case "$OS" in
AIX) # everyone loves to be different...
OSMAJOR=`uname -v`
OSMINOR=`uname -r`
OSREL="$OSMAJOR.$OSMINOR"
LOCAL_FS=jfs
PS_AXC=-e
SHARE_ARCH=$OS/$OSMAJOR.X
;;
Import bmake-20240430 Intersting/relevant changes since bmake-20240309 ChangeLog since bmake-20240309 2024-04-30 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240430 Merge with NetBSD make, pick up o main.c: ensure '.include <makefile>' respects MAKESYSPATH. Dir_FindFile will search .CURDIR first unless ".DOTLAST" is seen. 2024-04-28 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240428 Merge with NetBSD make, pick up o simplify freeing of lists o arch.c: trim pointless comments o var.c: delay variable assignments until actually needed don't reallocate memory after evaluating an expression, result is almost always short-lived. 2024-04-26 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240426 Merge with NetBSD make, pick up o job.c: in debug output, print the directory in which a job failed at same time as failed target so it is more easily found in build log. 2024-04-24 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240424 Merge with NetBSD make, pick up o clean up comments, code and tests 2024-04-23 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240422 Merge with NetBSD make, pick up o var.c: avoid LazyBuf for :*time modifiers. LazyBuf's are not nul terminated so not suitable for passing to functions that expect that. These modifiers are used sparingly so an extra allocation is not a problem. 2024-04-20 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240420 Merge with NetBSD make, pick up o provide more context information for parse/evaluate errors 2024-04-14 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240414 Merge with NetBSD make, pick up o parse.c: print -dp debug info earlier so we see which .if or .for line is being parsed. 2024-04-04 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240404 Merge with NetBSD make, pick up o fix some unit tests for Cygwin o parse.c: exit immediately after reading a null byte from a makefile * fix generation of bmake.cat1 2024-03-19 Simon J Gerraty <sjg@beast.crufty.net> * VERSION (_MAKE_VERSION): 20240314 Add/Improve support for Cygwin o uname -s output isn't useful so allow configure to set FORCE_MAKE_OS - to force the value of .MAKE.OS and use Cygwin which matches uname -o o fix some unit-tests for Cygwin * configure.in: use_makefile=no for Cygwin et al. NOTE: bmake does not support Cygwin and likely never will, mk/ChangeLog since bmake-20240309 2024-04-24 Simon J Gerraty <sjg@beast.crufty.net> * meta.autodep.mk: do not override start_utc 2024-04-18 Simon J Gerraty <sjg@beast.crufty.net> * sys.dirdeps.mk: set defaults for DEP_* at level 0 too. These help when first include of Makefile.depend happens in a leaf dir. * install-mk (MK_VERSION): 20240414 2024-04-09 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240408 * init.mk: allow for _ as well as . to join V and Q from QUALIFIED_VAR_LIST and VAR_QUALIFIER_LIST. * progs.mk: avoid overlap between PROG_VARS and init.mk's QUALIFIED_VAR_LIST since PROG would also match its VAR_QUALIFIER_LIST, libs.mk does not have the same issue. * subdir.mk: _SUBDIRUSE for realinstall should run install remove include of ${.CURDIR}/Makefile.inc that can be done via local.subdir.mk where needed * own.mk: do not conflict with man.mk 2024-03-19 Simon J Gerraty <sjg@beast.crufty.net> * install-mk (MK_VERSION): 20240314 * add sys/Cygwin.mk from Christian Franke
2024-05-03 22:43:12 +00:00
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)
CHOWN=`Which chown /usr/etc:/usr/bin`
export CHOWN
# Great! Solaris keeps moving arch(1)
2015-12-25 08:09:48 +00:00
# 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*)
2015-12-25 08:09:48 +00:00
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
2015-12-25 08:09:48 +00:00
# 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
2014-07-02 21:24:54 +00:00
: $-,$ENV
case "$-,$ENV" in
*i*,*) ;;
*,|*ENVFILE*) ;;
*) ENV=;;
esac
2014-07-02 21:24:54 +00:00
# NetBSD at least has good backward compatibility
# so NetBSD/i386 is good enough
# recent NetBSD uses x86_64 for MACHINE_ARCH
case $OS in
2015-10-21 22:14:23 +00:00
NetBSD)
LOCALBASE=/usr/pkg
SHARE_ARCH=$OS/$HOST_ARCH
2015-10-21 22:14:23 +00:00
;;
OpenBSD)
2015-12-25 08:09:48 +00:00
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|SCO_SV)
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
LOCALBASE=${LOCALBASE:-/usr/local}
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}
case "$HOST_ARCH" in
2017-03-06 19:54:54 +00:00
x86*64|amd64) MACHINE32_ARCH=i386;;
*64) MACHINE32_ARCH=`echo $MACHINE_ARCH | sed 's,64,32,'`;;
*) MACHINE32_ARCH=$MACHINE_ARCH;;
esac
HOST_ARCH32=${HOST_ARCH32:-$MACHINE32_ARCH}
# 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}
LN=${LN:-ln}
TR=${TR:-tr}
# Some people like have /share/$HOST_TARGET/bin etc.
2015-12-07 22:51:25 +00:00
HOST_TARGET=`echo ${OS}${OSMAJOR}-$HOST_ARCH | tr -d / | toLower`
2017-03-06 19:54:54 +00:00
HOST_TARGET32=`echo ${OS}${OSMAJOR}-$HOST_ARCH32 | tr -d / | toLower`
export HOST_TARGET HOST_TARGET32
case `echo -n .` in -n*) echo_n=; echo_c="\c";; *) echo_n=-n; echo_c=;; esac
2015-12-25 08:09:48 +00:00
Echo() {
case "$1" in
-n) shift; echo $echo_n "$@$echo_c";;
*) echo "$@";;
2015-12-25 08:09:48 +00:00
esac
}
# for systems that deprecate egrep
case "`echo egrep | egrep 'e|g' 2>&1`" in
egrep) ;;
*) egrep() { grep -E "$@"; };;
esac
2015-12-25 08:09:48 +00:00
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
export LOCALBASE
case /$0 in
*/os.sh)
2015-12-25 08:09:48 +00:00
for v in $*
do
2015-12-25 08:09:48 +00:00
eval vv=\$$v
echo "$v='$vv'"
done
2015-12-25 08:09:48 +00:00
;;
*/host_target32) echo $HOST_TARGET32;;
*/host_target) echo $HOST_TARGET;;
esac