diff --git a/bin/package b/bin/package index d3aeba5f5..30376e4c6 100755 --- a/bin/package +++ b/bin/package @@ -43,11 +43,31 @@ case $0 in *) echo "this script must live in bin/" >&2 exit 1 ;; esac - cd .. || exit + case $mydir in + */arch/*/*/bin) + cd .. ;; + */arch/*/bin) + cd ../../.. ;; + *) cd .. ;; + esac || exit unset mydir ;; package) - echo "this script must be invoked with a direct path, e.g. bin/package" >&2 - exit 1 ;; + me=`command -v package` || me=`which package` || exit + mydir=`echo "$me" | sed 's,/package$,,'` + cd "$mydir" || exit + case $PWD in + */bin) ;; + *) echo "this script must live in bin/" >&2 + exit 1 ;; + esac + case $mydir in + */arch/*/*/bin) + cd .. ;; + */arch/*/bin) + cd ../../.. ;; + *) cd .. ;; + esac || exit + unset me mydir ;; *) echo "this script must be named 'package'" >&2 exit 1 ;; diff --git a/src/cmd/INIT/iffe.sh b/src/cmd/INIT/iffe.sh index 00ce0dbad..9c0426e5d 100644 --- a/src/cmd/INIT/iffe.sh +++ b/src/cmd/INIT/iffe.sh @@ -31,7 +31,7 @@ AIX) unset LIBPATH ;; esac command=iffe -version=2012-07-17 # update in USAGE too # +version=2021-02-03 # update in USAGE too # compile() # $cc ... { @@ -95,11 +95,45 @@ is_hdr() # [ - ] [ file.c ] hdr pkg() # package { case $1 in - '') pth=`getconf PATH 2>/dev/null` + '') # Determine default system path, store in $pth. + pth=` + PATH=/run/current-system/sw/bin:/usr/xpg7/bin:/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin:$PATH + exec getconf PATH 2>/dev/null + ` case $pth in - '') pth="/bin /usr/bin" ;; + '' | [!/]* | *:[!/]* | *: ) + pth="/bin /usr/bin /sbin /usr/sbin" ;; *:*) pth=`echo "$pth" | sed 's/:/ /g'` ;; esac + # Fix for NixOS. Not all POSIX standard utilities come with the default system, + # e.g. 'bc', 'file', 'vi'. The command that NixOS recommends to get missing + # utilities, e.g. 'nix-env -iA nixos.bc', installs them in a default profile + # directory that is not in $(getconf PATH). So add this path to the standard path. + # See: https://github.com/NixOS/nixpkgs/issues/65512 + if test -e /etc/NIXOS && + nix_profile_dir=/nix/var/nix/profiles/default/bin && + test -d "$nix_profile_dir" + then case " $pth " in + *" $nix_profile_dir "* ) + # nothing to do + ;; + * ) # insert the default profile directory as the second entry + pth=` + set $pth + one=$1 + shift + echo "$one $nix_profile_dir${1+ }$@" + ` ;; + esac + fi + # Fix for AIX. At least as of version 7.1, the system default 'find', 'diff -u' and 'patch' utilities + # are broken and/or non-compliant in ways that make them incompatible with POSIX 2018. However, GNU + # utilities are commonly installed in /opt/freeware/bin, and under standard names (no g- prefix). + if test -d /opt/freeware/bin + then case `uname` in + AIX ) pth="/opt/freeware/bin $pth" ;; + esac + fi return ;; '<') shift @@ -719,11 +753,12 @@ set= case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in 0123) USAGE=$' [-? -@(#)$Id: iffe (AT&T Research) 2012-07-17 $ +@(#)$Id: iffe (ksh 93u+m) 2021-02-03 $ ] [-author?Glenn Fowler ] [-author?Phong Vo ] -[-copyright?Copyright (c) 1994-2012 AT&T Intellectual Property] +[-copyright?(c) 1994-2012 AT&T Intellectual Property] +[-copyright?(c) 2020-2021 Contributors to https://github.com/ksh93/ksh] [-license?http://www.eclipse.org/org/documents/epl-v10.html] [+NAME?iffe - C compilation environment feature probe] [+DESCRIPTION?\biffe\b is a command interpreter that probes the C @@ -915,8 +950,8 @@ case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in [+ver \aname\a \aYYYYMMDD\a?\b#define\b \aNAME\a_VERSION \aYYYYMMDD\a (\aNAME\a is \aname\a converted to upper case).] [+cmd \aname\a?Defines \b_cmd_\b\aname\a if \aname\a is an executable - in one of the standard system directories (\b/bin, /etc, - /usr/bin, /usr/etc, /usr/ucb\b). + in one of the standard system directories + (as output by \bgetconf PATH\b). \b_\b\adirectory\a\b_\b\aname\a is defined for \adirectory\a in which \aname\a is found (with \b/\b translated to \b_\b).] [+dat \aname\a?Defines \b_dat_\b\aname\a if \aname\a is a data symbol @@ -3617,34 +3652,30 @@ int main(){printf("hello");return(0);} esac is $o $a k=1 - for j in "" usr - do case $j in - "") d= s= ;; - *) d=/$j s=_$j ;; - esac - for i in bin etc ucb - do if test -f $d/$i/$a - then case $k in - 1) k=0 - case $M in - *-*) ;; - *) usr="$usr$nl#define $m 1" - case $define in - 1) echo "#define $m 1 /* $a in ?(/usr)/(bin|etc|ucb) */" ;; - n) echo "$m=1" ;; - esac - ;; + pkg $pth # set system default path + for d in $pth + do if test -f "$d/$a" + then s=`echo "$d" | LC_ALL=C sed 's,[^0-9A-Za-z],_,g'` + case $k in + 1) k=0 + case $M in + *-*) ;; + *) usr="$usr$nl#define $m 1" + case $define in + 1) echo "#define $m 1 /* $a in $pth */" ;; + n) echo "$m=1" ;; esac ;; esac - c=${s}_${i}_${v} - usr="$usr$nl#define $c 1" - case $define in - 1) echo "#define $c 1 /* $d/$i/$a found */" ;; - n) echo "$c=1" ;; - esac - fi - done + ;; + esac + c=${s}_${v} + usr="$usr$nl#define $c 1" + case $define in + 1) echo "#define $c 1 /* $d/$a found */" ;; + n) echo "$c=1" ;; + esac + fi done case $k in 0) success ;; diff --git a/src/cmd/INIT/package.sh b/src/cmd/INIT/package.sh index d3aeba5f5..30376e4c6 100644 --- a/src/cmd/INIT/package.sh +++ b/src/cmd/INIT/package.sh @@ -43,11 +43,31 @@ case $0 in *) echo "this script must live in bin/" >&2 exit 1 ;; esac - cd .. || exit + case $mydir in + */arch/*/*/bin) + cd .. ;; + */arch/*/bin) + cd ../../.. ;; + *) cd .. ;; + esac || exit unset mydir ;; package) - echo "this script must be invoked with a direct path, e.g. bin/package" >&2 - exit 1 ;; + me=`command -v package` || me=`which package` || exit + mydir=`echo "$me" | sed 's,/package$,,'` + cd "$mydir" || exit + case $PWD in + */bin) ;; + *) echo "this script must live in bin/" >&2 + exit 1 ;; + esac + case $mydir in + */arch/*/*/bin) + cd .. ;; + */arch/*/bin) + cd ../../.. ;; + *) cd .. ;; + esac || exit + unset me mydir ;; *) echo "this script must be named 'package'" >&2 exit 1 ;; diff --git a/src/lib/libast/comp/conf.tab b/src/lib/libast/comp/conf.tab index 48c5647df..5e59fd9b2 100644 --- a/src/lib/libast/comp/conf.tab +++ b/src/lib/libast/comp/conf.tab @@ -375,9 +375,41 @@ PATH AST CS 1 MU sh{ *) CONF_path=`"$CONF_getconf" PATH` ;; esac case $CONF_path in - '') echo '"/bin:/usr/bin:/sbin:/usr/sbin"' ;; - *) echo "\\"$CONF_path\\"" ;; + '' | [!/]* | *:[!/]* | *: ) + CONF_path=/bin:/usr/bin:/sbin:/usr/sbin ;; esac + # Fix for NixOS. Not all POSIX standard utilities come with the default system, + # e.g. 'bc', 'file', 'vi'. The command that NixOS recommends to get missing + # utilities, e.g. 'nix-env -iA nixos.bc', installs them in a default profile + # directory that is not in $(getconf PATH). So add this path to the standard path. + # See: https://github.com/NixOS/nixpkgs/issues/65512 + if test -e /etc/NIXOS && + nix_profile_dir=/nix/var/nix/profiles/default/bin && + test -d "$nix_profile_dir" + then case ":$CONF_path:" in + *:"$nix_profile_dir":* ) + # nothing to do + ;; + * ) # insert the default profile directory as the second entry + CONF_path=` + set -f + IFS=: + set $CONF_path + one=$1 + shift + echo "$one:$nix_profile_dir${1+:}$*" + ` ;; + esac + fi + # Fix for AIX. At least as of version 7.1, the system default 'find', 'diff -u' and 'patch' utilities + # are broken and/or non-compliant in ways that make them incompatible with POSIX 2018. However, GNU + # utilities are commonly installed in /opt/freeware/bin, and under standard names (no g- prefix). + if test -d /opt/freeware/bin + then case `uname` in + AIX ) CONF_path="/opt/freeware/bin:$CONF_path" ;; + esac + fi + echo "\\"$CONF_path\\"" } PATH_MAX POSIX PC 1 CDLMUX MAXPATHLEN 1024 PBS POSIX SC 2 FUW