1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

build system: fix detection of default system directories

src/cmd/INIT/iffe.sh:
- Fix "standard system directories" for the cmd test, which were
  hardcoded as bin, /etc, /usr/bin, /usr/etc, /usr/ucb. That's both
  unportable and antiquated. Replace this with the path output by
  'getconf PATH'.
- Add fixes from modernish for 'getconf PATH' output to compensate
  for bugs/shortcomigns in NixOS and AIX. Source:
  9e4bf5eb/lib/modernish/aux/defpath.sh
  Ref.: https://github.com/NixOS/nixpkgs/issues/65512

src/lib/libast/comp/conf.tab: PATH:
- Add the NixOS and AIX default path fixes here too; this fixes
  'command -p' and the builtin 'getconf PATH' on these systems.

bin/package, src/cmd/INIT/package.sh:
- Re-support being launched with just the command name 'package' in
  the command line (if the 'package' command is in $PATH). At least
  one other script in the build system does this. (re: 6cc2f6a0)
- Go back three levels (../../..) if we were invoked from
  arch/*/bin/package, otherwise we won't find src/cmd/ksh93/SHOPT.sh.
This commit is contained in:
Martijn Dekker 2021-02-03 16:58:35 +00:00
parent be33942415
commit f5eaf217ed
4 changed files with 143 additions and 40 deletions

View file

@ -43,11 +43,31 @@ case $0 in
*) echo "this script must live in bin/" >&2 *) echo "this script must live in bin/" >&2
exit 1 ;; exit 1 ;;
esac esac
cd .. || exit case $mydir in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*) cd .. ;;
esac || exit
unset mydir ;; unset mydir ;;
package) package)
echo "this script must be invoked with a direct path, e.g. bin/package" >&2 me=`command -v package` || me=`which package` || exit
exit 1 ;; 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 echo "this script must be named 'package'" >&2
exit 1 ;; exit 1 ;;

View file

@ -31,7 +31,7 @@ AIX) unset LIBPATH ;;
esac esac
command=iffe command=iffe
version=2012-07-17 # update in USAGE too # version=2021-02-03 # update in USAGE too #
compile() # $cc ... compile() # $cc ...
{ {
@ -95,11 +95,45 @@ is_hdr() # [ - ] [ file.c ] hdr
pkg() # package pkg() # package
{ {
case $1 in 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 case $pth in
'') pth="/bin /usr/bin" ;; '' | [!/]* | *:[!/]* | *: )
pth="/bin /usr/bin /sbin /usr/sbin" ;;
*:*) pth=`echo "$pth" | sed 's/:/ /g'` ;; *:*) pth=`echo "$pth" | sed 's/:/ /g'` ;;
esac 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 return
;; ;;
'<') shift '<') shift
@ -719,11 +753,12 @@ set=
case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
0123) USAGE=$' 0123) USAGE=$'
[-? [-?
@(#)$Id: iffe (AT&T Research) 2012-07-17 $ @(#)$Id: iffe (ksh 93u+m) 2021-02-03 $
] ]
[-author?Glenn Fowler <gsf@research.att.com>] [-author?Glenn Fowler <gsf@research.att.com>]
[-author?Phong Vo <kpv@research.att.com>] [-author?Phong Vo <kpv@research.att.com>]
[-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] [-license?http://www.eclipse.org/org/documents/epl-v10.html]
[+NAME?iffe - C compilation environment feature probe] [+NAME?iffe - C compilation environment feature probe]
[+DESCRIPTION?\biffe\b is a command interpreter that probes the C [+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 [+ver \aname\a \aYYYYMMDD\a?\b#define\b \aNAME\a_VERSION \aYYYYMMDD\a
(\aNAME\a is \aname\a converted to upper case).] (\aNAME\a is \aname\a converted to upper case).]
[+cmd \aname\a?Defines \b_cmd_\b\aname\a if \aname\a is an executable [+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, in one of the standard system directories
/usr/bin, /usr/etc, /usr/ucb\b). (as output by \bgetconf PATH\b).
\b_\b\adirectory\a\b_\b\aname\a is defined for \adirectory\a \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).] 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 [+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 esac
is $o $a is $o $a
k=1 k=1
for j in "" usr pkg $pth # set system default path
do case $j in for d in $pth
"") d= s= ;; do if test -f "$d/$a"
*) d=/$j s=_$j ;; then s=`echo "$d" | LC_ALL=C sed 's,[^0-9A-Za-z],_,g'`
esac case $k in
for i in bin etc ucb 1) k=0
do if test -f $d/$i/$a case $M in
then case $k in *-*) ;;
1) k=0 *) usr="$usr$nl#define $m 1"
case $M in case $define in
*-*) ;; 1) echo "#define $m 1 /* $a in $pth */" ;;
*) usr="$usr$nl#define $m 1" n) echo "$m=1" ;;
case $define in
1) echo "#define $m 1 /* $a in ?(/usr)/(bin|etc|ucb) */" ;;
n) echo "$m=1" ;;
esac
;;
esac esac
;; ;;
esac esac
c=${s}_${i}_${v} ;;
usr="$usr$nl#define $c 1" esac
case $define in c=${s}_${v}
1) echo "#define $c 1 /* $d/$i/$a found */" ;; usr="$usr$nl#define $c 1"
n) echo "$c=1" ;; case $define in
esac 1) echo "#define $c 1 /* $d/$a found */" ;;
fi n) echo "$c=1" ;;
done esac
fi
done done
case $k in case $k in
0) success ;; 0) success ;;

View file

@ -43,11 +43,31 @@ case $0 in
*) echo "this script must live in bin/" >&2 *) echo "this script must live in bin/" >&2
exit 1 ;; exit 1 ;;
esac esac
cd .. || exit case $mydir in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*) cd .. ;;
esac || exit
unset mydir ;; unset mydir ;;
package) package)
echo "this script must be invoked with a direct path, e.g. bin/package" >&2 me=`command -v package` || me=`which package` || exit
exit 1 ;; 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 echo "this script must be named 'package'" >&2
exit 1 ;; exit 1 ;;

View file

@ -375,9 +375,41 @@ PATH AST CS 1 MU sh{
*) CONF_path=`"$CONF_getconf" PATH` ;; *) CONF_path=`"$CONF_getconf" PATH` ;;
esac esac
case $CONF_path in case $CONF_path in
'') echo '"/bin:/usr/bin:/sbin:/usr/sbin"' ;; '' | [!/]* | *:[!/]* | *: )
*) echo "\\"$CONF_path\\"" ;; CONF_path=/bin:/usr/bin:/sbin:/usr/sbin ;;
esac 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 PATH_MAX POSIX PC 1 CDLMUX MAXPATHLEN 1024
PBS POSIX SC 2 FUW PBS POSIX SC 2 FUW