]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Port to AIX 7.2 ksh93
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Aug 2024 03:42:57 +0000 (20:42 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Aug 2024 03:44:06 +0000 (20:44 -0700)
Problem reported in <https://savannah.gnu.org/support/?111102>.
* lib/autotest/general.m4:
* lib/m4sugar/m4sh.m4 (_AS_REEXEC_WITH_SHELL):
* tests/wrapper.as:
Port to AIX 7.2 ksh93, whidh mishandles ${1+"$@"}, by not using
that construct.

NEWS
doc/autoconf.texi
lib/Autom4te/FileUtils.pm
lib/autotest/general.m4
lib/m4sugar/m4sh.m4
tests/statesave.m4
tests/wrapper.as

diff --git a/NEWS b/NEWS
index 75d2eef44c78752a5b62af13aff03aceb31d0576..9e68534f0c47ea43a1ae4a1dea5373652d92e64d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,9 @@ GNU Autoconf NEWS - User visible changes.
 *** AC_PROG_OBJC now finds the GNU Objective-C compiler, as packaged in
   EPEL 9, by default, without the user having to set the OBJC variable.
 
+*** Autoconf no longer generates ${1+"$@"} in scripts, working around
+  a bug in AIX 7.2 ksh93.
+
 * Noteworthy changes in release 2.72 (2023-12-22) [release]
 
 ** Backward incompatibilities
index 72166bf5503ed0e4e6bbc9e039894fa940496591..29a9b6fb930fa76353f3e28e71d5515b02ed71aa 100644 (file)
@@ -15302,9 +15302,7 @@ breaking the bracket-matching highlighting from Emacsen.  Note the
 preferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc.  Do
 not escape when it is unnecessary.  Common examples of useless quotation
 are @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),
-etc.  If you add portability issues to the picture, you'll prefer
-@samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do something
-better than hacking Autoconf @code{:-)}.
+etc.
 
 When using @command{sed}, don't use @option{-e} except for indenting
 purposes.  With the @code{s} and @code{y} commands, the preferred
@@ -15685,7 +15683,7 @@ set @code{NULLCMD} to @samp{:}.  @xref{Compatibility, , Compatibility,
 zsh, The Z Shell Manual}, for details.
 
 The default Mac OS X @command{sh} was originally Zsh; it was changed to
-Bash in Mac OS X 10.2.
+Bash in Mac OS X 10.2 (2002) and changed back to Zsh in macOS 10.15 (2019).
 @end table
 
 @node Invoking the Shell
@@ -16460,17 +16458,37 @@ There are also portability pitfalls with particular expansions:
 @table @code
 @item $@@
 @cindex @code{"$@@"}
-One of the most famous shell-portability issues is related to
-@samp{"$@@"}.  When there are no positional arguments, Posix says
-that @samp{"$@@"} is supposed to be equivalent to nothing, but the
-original Unix version 7 Bourne shell treated it as equivalent to
-@samp{""} instead, and this behavior survives in later implementations
-like Digital Unix 5.0.
+Autoconf macros often use the @command{set} command to update
+@samp{$@@}, so if you are writing shell code intended for
+@command{configure} you should not assume that the value of @samp{$@@}
+persists for any length of time.
+
+You may see usages like @samp{$@{1+"$@@"@}} in older shell scripts
+designed to work around a portability problem in ancient shells.
+Unfortunately this runs afoul of bugs in more-recent shells, and
+nowadays it is better to use plain @samp{"$@@"} insteadl.
+
+The portability problem with ancient shells was significant.
+When there are no positional arguments @samp{"$@@"} should be discarded,
+but the original Unix version 7 Bourne shell mistakenly treated it as
+equivalent to @samp{""} instead, and many ancient shells followed its lead.
+
+For many years shell scripts worked around this portability problem by
+using @samp{$@{1+"$@@"@}} instead of @samp{"$@@"}, and you may see this
+usage in older scripts.  Unfortunately, @samp{$@{1+"$@@"@}} does not
+work with @command{ksh93} M 93t+ (2009) as shipped in AIX 7.2 (2015),
+as this shell drops trailing arguments:
+
+@example
+$ @kbd{set a b c ""}
+$ @kbd{set $@{1+"$@@"@}}
+$ @kbd{echo $#}
+3
+@end example
 
-The traditional way to work around this portability problem is to use
-@samp{$@{1+"$@@"@}}.  Unfortunately this method does not work with
-Zsh (3.x and 4.x), which is used on Mac OS X@.  When emulating
-the Bourne shell, Zsh performs word splitting on @samp{$@{1+"$@@"@}}:
+Also, @samp{$@{1+"$@@"@}} does not work with Zsh 4.2.6 (2005) and
+earlier, as shipped in Mac OS X releases before 10.5, as this old Zsh
+incorrectly word splits the result:
 
 @example
 zsh $ @kbd{emulate sh}
@@ -16483,42 +16501,40 @@ World
 !
 @end example
 
-@noindent
-Zsh handles plain @samp{"$@@"} properly, but we can't use plain
-@samp{"$@@"} because of the portability problems mentioned above.
-One workaround relies on Zsh's ``global aliases'' to convert
-@samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:
-
-@example
-test $@{ZSH_VERSION+y@} && alias -g '$@{1+"$@@"@}'='"$@@"'
-@end example
-
-Zsh only recognizes this alias when a shell word matches it exactly;
-@samp{"foo"$@{1+"$@@"@}} remains subject to word splitting.  Since this
-case always yields at least one shell word, use plain @samp{"$@@"}.
-
-A more conservative workaround is to avoid @samp{"$@@"} if it is
-possible that there may be no positional arguments.  For example,
-instead of:
+To work around these problems Autoconf does two things.  First, in the
+shell code that it generates Autoconf avoids @samp{"$@@"} if it is
+possible that there may be no positional arguments.  You can use this
+workaround in your own code, too, if you want it to be portable to
+ancient shells.  For example, instead of:
 
 @example
 cat conftest.c "$@@"
 @end example
 
-you can use this instead:
+you can use this:
 
 @example
 case $# in
-0) cat conftest.c;;
-*) cat conftest.c "$@@";;
+  0) cat conftest.c;;
+  *) cat conftest.c "$@@";;
 esac
 @end example
 
-Autoconf macros often use the @command{set} command to update
-@samp{$@@}, so if you are writing shell code intended for
-@command{configure} you should not assume that the value of @samp{$@@}
-persists for any length of time.
+@noindent
+Second, Autoconf-generated @command{configure} scripts work around most
+of the old Zsh problem by using Zsh's ``global aliases'' to convert
+@samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:
 
+@example
+test $@{ZSH_VERSION+y@} && alias -g '$@{1+"$@@"@}'='"$@@"'
+@end example
+
+This workaround is for the benefit of any instances of
+@samp{$@{1+"$@@"@}} in user-written code appearing in
+@command{configure} scripts.  However, it is not a complete solution, as
+Zsh recognizes the alias only when a shell word matches it exactly,
+which means older Zsh still mishandles more-complicated cases like
+@samp{"foo"$@{1+"$@@"@}}.
 
 @item $@{10@}
 @cindex positional parameters
@@ -18317,20 +18333,14 @@ for arg; do
 done
 @end example
 
-If you want to explicitly refer to the positional arguments, given the
-@samp{$@@} bug (@pxref{Shell Substitutions}), use:
+If you want to explicitly refer to the positional arguments, use:
 
 @example
-for arg in $@{1+"$@@"@}; do
+for arg in "$@@"; do
   echo "$arg"
 done
 @end example
 
-@noindent
-But keep in mind that Zsh, even in Bourne shell emulation mode, performs
-word splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},
-item @samp{$@@}, for more.
-
 Posix requires support for a @command{for} loop with no list after
 @code{in}.  However, Solaris 10 @command{/bin/sh} treats that as a syntax
 error.  It is possible to work around this by providing any shell word
@@ -19730,7 +19740,7 @@ was equivalent to @samp{sources='*.c not found'} in the absence of
 The behavior of @command{ls} on a directory that is being concurrently
 modified is not always predictable, because of a data race where cached
 information returned by @code{readdir} does not match the current
-directory state.  In fact, MacOS 10.5 has an intermittent bug where
+directory state.  In fact, Mac OS X 10.5 had an intermittent bug where
 @code{readdir}, and thus @command{ls}, sometimes lists a file more than
 once if other files were added or removed from the directory immediately
 prior to the @command{ls} call.  Since @command{ls} already sorts its
@@ -19856,7 +19866,7 @@ perfectly portable among Posix hosts.
 @c ---------------
 @prindex @command{od}
 
-In MacOS X versions prior to 10.4.3, @command{od} does not support the
+In Mac OS X versions prior to 10.4.3, @command{od} does not support the
 standard Posix options @option{-A}, @option{-j}, @option{-N}, or
 @option{-t}, or the XSI option, @option{-s}.  The only
 supported Posix option is @option{-v}, and the only supported
@@ -19962,7 +19972,7 @@ than to rely on @samp{[A-Z]}.
 
 Additionally, Posix states that regular expressions are only
 well-defined on characters.  Unfortunately, there exist platforms such
-as MacOS X 10.5 where not all 8-bit byte values are valid characters,
+as Mac OS X 10.5 where not all 8-bit byte values are valid characters,
 even though that platform has a single-byte @samp{C} locale.  And Posix
 allows the existence of a multi-byte @samp{C} locale, although that does
 not yet appear to be a common implementation.  At any rate, it means
@@ -20107,7 +20117,7 @@ should be followed by a newline.  Otherwise some @command{sed}
 implementations (e.g., OpenBSD 3.9) do not append a newline to the
 inserted text.
 
-Many @command{sed} implementations (e.g., MacOS X 10.4,
+Many @command{sed} implementations (e.g., Mac OS X 10.4,
 OpenBSD 3.9, Solaris 10
 @command{/usr/ucb/sed}) strip leading white space from the text of
 @samp{a}, @samp{c}, and @samp{i} commands.  Prepend a backslash to
index e2d8c38baa58baec5bbd4825706c34b34b89a417..13b91745ecedcdca3f3040ce17f153fc7942ee1a 100644 (file)
@@ -359,7 +359,7 @@ same file).
 our %_directory_cache;
 sub dir_has_case_matching_file ($$)
 {
-  # Note that print File::Spec->case_tolerant returns 0 even on MacOS
+  # Note that print File::Spec->case_tolerant returns 0 even on Mac OS
   # X (with Perl v5.8.1-RC3 at least), so do not try to shortcut this
   # function using that.
 
index a0668dde22abe5c37fd9e7728c99ded332412b81..661b2e7714e7dfbd802e36f605e74c3289727c98 100644 (file)
@@ -378,11 +378,13 @@ at_fn_create_debugging_script ()
 {
   {
     echo "#! /bin/sh" &&
-    echo 'test ${ZSH_VERSION+y} dnl
-&& alias -g '\''${1+"$[@]"}'\''='\''"$[@]"'\''' &&
     AS_ECHO(["cd '$at_dir'"]) &&
-    AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
-[$at_debug_args $at_group \${1+\"\$[@]\"}"]) &&
+    AS_ECHO(['case $[#] in']) &&
+    AS_ECHO(["  0) exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
+[$at_debug_args $at_group ;;"]) &&
+    AS_ECHO(["  *) exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
+[$at_debug_args $at_group \"\$[@]\" ;;"]) &&
+    AS_ECHO([esac]) &&
     echo 'exit 1'
   } >"$at_group_dir/run" &&
   chmod +x "$at_group_dir/run"
index ba6d54098acd1afef9ff4724e945ec12513a4e0e..c973f17788205eb63be03a90ca0828742a33fba7 100644 (file)
@@ -108,7 +108,7 @@ m4_define([_AS_BOURNE_COMPATIBLE],
  [emulate sh
   NULLCMD=:
   [#] Pre-4.2 versions of Zsh do word splitting on ${1+"$[@]"}, which
-  # is contrary to our usage.  Disable this feature.
+  # contradicts POSIX and common usage.  Disable this.
   alias -g '${1+"$[@]"}'='"$[@]"'
   setopt NO_GLOB_SUBST],
  [AS_CASE([`(set -o) 2>/dev/null`], [*posix*], [set -o posix])])
@@ -294,7 +294,10 @@ case $- in @%:@ ((((
   *x* ) as_opts=-x ;;
   * ) as_opts= ;;
 esac
-exec $1 $as_opts "$as_myself" ${1+"$[@]"}
+case [$]@%:@ in @%:@ ((
+  0) exec $1 $as_opts "$as_myself" ;;
+  *) exec $1 $as_opts "$as_myself" "$[@]" ;;
+esac
 # Admittedly, this is quite paranoid, since all the known shells bail
 # out after a failed 'exec'.
 AS_ECHO(["$[]0: could not re-execute with $1"]) >&2
index 9c341085c443eb1080ca27348d2a443104c02ca3..50202d9cc2f448e85849888815fa91f730c70ae6 100644 (file)
@@ -23,7 +23,7 @@
 # that tests have the same side effects regardless of caching.
 #
 # The sed script duplicates uniq functionality (thanks to 'info sed
-# uniq' for the recipe), in order to avoid a MacOS 10.5 bug where
+# uniq' for the recipe), in order to avoid a Mac OS 10.5 bug where
 # readdir can list a file multiple times in a rapidly changing
 # directory, while avoiding yet another fork.
 m4_defun([AC_STATE_SAVE],
index bd7951e705d3b197dd0eb59895ce5f96fde39a6c..a99149c437bd847ff88e85716aeef4d4cf4142c7 100644 (file)
@@ -29,16 +29,15 @@ trailer_m4='@abs_top_srcdir@/lib/autoconf/trailer.m4'
 export AUTOCONF AUTOHEADER AUTOM4TE AUTOM4TE_CFG
 export autom4te_buildauxdir autom4te_perllibdir trailer_m4
 
-case '@wrap_program@' in
-  ifnames)
-     # Does not have lib files.
-     exec '@abs_top_builddir@/bin/@wrap_program@' ${1+"$@"}
-     ;;
-  *)
-     # We might need files from the build tree (frozen files), in
-     # addition of src files.
-     exec '@abs_top_builddir@/bin/@wrap_program@' \
-         -B '@abs_top_builddir@'/lib \
-         -B '@abs_top_srcdir@'/lib ${1+"$@"}
+# Programs other than ifnames might need files from the build tree
+# (frozen files), in addition to src files.
+prog='@abs_top_builddir@/bin/@wrap_program@'
+buildlib='@abs_top_builddir@/lib'
+srclib='@abs_top_srcdir@/lib'
+case $#,'@wrap_program@' in
+  0,ifnames) exec "$prog" ;;
+  *,ifnames) exec "$prog" "$@" ;;
+  0,*)       exec "$prog" -B "$buildlib" -B "$srclib" ;;
+  *)         exec "$prog" -B "$buildlib" -B "$srclib" "$@" ;;
 esac
 exit 1