[PATCH 0/2] Modernize header checks

2013-05-30 Thread Zack Weinberg
This patch series accomplishes two things.

First, it switches AC_CHECK_HEADER[S] to do only a compile test by
default.  This completes the transition begun in Autoconf 2.56.  It
has been my experience that basically nobody bothered to disable the
mongrel mode, and that basically nobody actually needed the
preprocessor check.  Therefore, I do not anticipate problems from this
change.  Mongrel mode is completely removed.  Preprocessor-only checks
are still available by specifying [-] as the fourth argument to
AC_CHECK_HEADER, but this will issue a deprecation warning and the
manual tells people to switch to AC_PREPROC_IFELSE.

Second, it cleans up AC_INCLUDES_DEFAULT and all the other canned
tests so that they don't waste time checking for ISO C90 headers,
which are now ubiquitous (stddef.h, stdlib.h, string.h, wchar.h,
wctype.h, locale.h, time.h) and don't use pre-standard headers that
were replaced by C90 headers at all (memory.h and strings.h).  Certain
very old macros (AC_HEADER_STDC, AC_HEADER_TIME, AC_USG, AC_MEMORY_H)
are more aggressive about autoupdating themselves out of existence,
autoscan won't tell you you need to probe for C90 headers anymore, and
finally, the manual is revised so that it does not recommend checking
for obsolete or C90 headers.  (I may not have found every last
instance of such obsolete advice in the manual.)

I *should* have a past-and-future-changes copyright assignment on
file, but I'm not sure whether it explicitly covered Autoconf.

zw

 NEWS  |   24 +++
 doc/autoconf.texi |  396 +
 lib/autoconf/functions.m4 |   35 +
 lib/autoconf/headers.m4   |  281 ++---
 tests/c.at|   28 +++-
 tests/local.at|5 +-
 tests/semantics.at|   17 +-
 tests/tools.at|6 +-
 8 files changed, 297 insertions(+), 495 deletions(-)



[PATCH 2/2] Modernize AC_INCLUDES_DEFAULT and friends.

2013-05-30 Thread Zack Weinberg

 * lib/autoconf/headers.m4 (_AC_INCLUDES_DEFAULT_REQUIREMENTS):
   Include stddef.h, stdlib.h, and string.h unconditionally.
   Don't include strings.h or memory.h at all.
   Don't use AC_HEADER_STDC.
   Don't check for stddef.h, stdlib.h, string.h, strings.h, or memory.h.
   (AN_HEADER list): Remove C89 headers, strings.h, and memory.h from list.
   (AC_HEADER_STDC): AU_DEFUN as an unconditional AC_DEFINE of STDC_HEADERS.
   (AC_HEADER_TIME): AU_DEFUN, and define TIME_WITH_SYS_TIME unconditionally
   as long as sys/time.h is present.
   (AC_USG, AC_MEMORY_H): Assume existence of string.h.
 * lib/autoconf/functions.m4 (_AC_FUNC_MALLOC_IF, _AC_FUNC_REALLOC_IF):
   Don't use AC_HEADER_STDC. Assume stdlib.h exists.
   (AC_FUNC_MKTIME): Don't use AC_HEADER_TIME.
   (AC_FUNC_ALLOCA): Assume stdlib.h exists.
   (_AC_LIBOBJ_FNMATCH): Assume wchar.h and wctype.h exist.
   (_AC_LIBOBJ_GETLOADAVG): Assume locale.h exists.
   (AC_FUNC_MMAP): Assume stdlib.h exists.
 * tests/tools.at: Use AC_WORDS_BIGENDIAN instead of AC_STDC_HEADERS in
   autoupdate test.

 * NEWS, doc/autoconf.texi: Document changes. Remove obsolete advice.

Signed-off-by: Zack Weinberg za...@panix.com
---
 NEWS  |   14 ++
 doc/autoconf.texi |  290 +++--
 lib/autoconf/functions.m4 |   35 +-
 lib/autoconf/headers.m4   |  172 ++-
 tests/tools.at|6 +-
 5 files changed, 182 insertions(+), 335 deletions(-)

diff --git a/NEWS b/NEWS
index 1378388..2e7b36f 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,20 @@ GNU Autoconf NEWS - User visible changes.
 - AT_TESTED arguments can use variable or command substitutions, including
   in particular $EXEEXT
 
+- AC_INCLUDES_DEFAULT has been streamlined.  It now assumes that
+  ISO C90 headers are available unconditionally (stddef.h, stdio.h,
+  stdlib.h, string.h) and does not use pre-standard headers at all
+  (memory.h, strings.h).
+
+- AC_HEADER_STDC and AC_HEADER_TIME are now stubs which will be
+  removed from 'configure.ac' by 'autoupdate'.  For compatibility's
+  sake, the stubs (and their 'autoupdate' replacements) continue to
+  define the C preprocessor macros STDC_HEADERS and TIME_WITH_SYS_TIME,
+  respectively, but without actually checking for the ancient systems
+  where formerly those macros would not be defined.
+
+  These macros were already labeled obsolescent in the manual.
+
 * Noteworthy changes in release 2.69 (2012-04-24) [stable]
 
 ** Autoconf now requires perl 5.6 or better (but generated configure
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 7809859..de0596e 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -3881,15 +3881,9 @@ protected includes, such as:
 
 @example
 @group
-#ifdef TIME_WITH_SYS_TIME
+#include time.h
+#ifdef HAVE_SYS_TIME_H
 # include sys/time.h
-# include time.h
-#else
-# ifdef HAVE_SYS_TIME_H
-#  include sys/time.h
-# else
-#  include time.h
-# endif
 #endif
 @end group
 @end example
@@ -3908,26 +3902,16 @@ Expand to @var{include-directives} if defined, otherwise to:
 
 @example
 @group
+#include stddef.h
 #include stdio.h
+#include stdlib.h
+#include string.h
 #ifdef HAVE_SYS_TYPES_H
 # include sys/types.h
 #endif
 #ifdef HAVE_SYS_STAT_H
 # include sys/stat.h
 #endif
-#if defined STDC_HEADERS || defined HAVE_STDLIB_H
-# include stdlib.h
-#endif
-#include stddef.h
-#ifdef HAVE_STRING_H
-# if !defined STDC_HEADERS  defined HAVE_MEMORY_H
-#  include memory.h
-# endif
-# include string.h
-#endif
-#ifdef HAVE_STRINGS_H
-# include strings.h
-#endif
 #ifdef HAVE_INTTYPES_H
 # include inttypes.h
 #endif
@@ -3940,14 +3924,8 @@ Expand to @var{include-directives} if defined, otherwise to:
 @end group
 @end example
 
-If the default includes are used, then check for the presence of these
-headers and their compatibility, i.e., you don't need to run
-@code{AC_HEADER_STDC}, nor check for @file{stdlib.h} etc.
-
-These headers are checked for in the same order as they are included.
-For instance, on some systems @file{string.h} and @file{strings.h} both
-exist, but conflict.  Then @code{HAVE_STRING_H} is defined, not
-@code{HAVE_STRINGS_H}.
+If the default set of includes is used, the headers that are not part of
+ISO C90 are automatically checked for; you need not do this yourself.
 @end defmac
 
 @node Alternative Programs
@@ -4878,9 +4856,7 @@ like the following, to declare it properly.
 
 @example
 @group
-#if defined STDC_HEADERS || defined HAVE_STDLIB_H
-# include stdlib.h
-#endif
+#include stdlib.h
 #include stddef.h
 #ifdef HAVE_ALLOCA_H
 # include alloca.h
@@ -5735,6 +5711,29 @@ Posix Headers, gnulib, GNU gnulib} and @ref{Glibc Header File
 Substitutes, , Glibc Headers, gnulib, GNU gnulib}.  Please help us keep
 the gnulib list as complete as possible.
 
+When we say that a header ``may require'' some set of other headers, we
+mean that it may be necessary for you to manually include those other
+headers first, or the contents of the first header

[PATCH 1/2] AC_CHECK_HEADER/AC_CHECK_HEADERS: complete transition to compile tests.

2013-05-30 Thread Zack Weinberg

* lib/autoconf/headers.m4 (AC_CHECK_HEADER): Use _AC_CHECK_HEADER_COMPILE
  by default.  Continue to use _AC_CHECK_HEADER_PREPROC if fourth arg is '-'.
  (_AC_CHECK_HEADER_PREPROC): Issue a deprecation warning.
  (_AC_CHECK_HEADER_MONGREL, _AC_CHECK_HEADER_MONGREL_BODY): Remove.

* tests/local.at (AT_CHECK_M4): Support 'stderr' as fourth argument.
* tests/c.at, tests/semantics.at: Update uses of AC_CHECK_HEADER(S).
* doc/autoconf.texi, NEWS: Document change.

Signed-off-by: Zack Weinberg za...@panix.com
---
 NEWS|   10 
 doc/autoconf.texi   |  106 ++---
 lib/autoconf/headers.m4 |  109 +--
 tests/c.at  |   28 +---
 tests/local.at  |5 +-
 tests/semantics.at  |   17 ---
 6 files changed, 115 insertions(+), 160 deletions(-)

diff --git a/NEWS b/NEWS
index de9d915..1378388 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,16 @@ GNU Autoconf NEWS - User visible changes.
echo.  Macros AS_ECHO and AS_ECHO_N now expand unconditionally to
'printf %s\n' and 'printf %s'.
 
+** AC_CHECK_HEADER and AC_CHECK_HEADERS now default to doing only a
+   compilation test.  This completes the transition from preprocessor-
+   based header tests begun in Autoconf 2.56.
+
+   The double test that was the default since Autoconf 2.64 is no
+   longer available.  You can still request a preprocessor-only test
+   by specifying '-' as the fourth argument to either macro, but this
+   is now deprecated.  If you really need that behavior use
+   AC_PREPROC_IFELSE.
+
 ** Macros
 
 - New macro AC_C__GENERIC.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index faf6d97..7809859 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6255,26 +6255,21 @@ commands @var{action-if-found}, otherwise execute
 header file is available, consider using @code{AC_CHECK_HEADERS}
 instead.
 
-@var{includes} is decoded to determine the appropriate include
-directives.  If omitted or empty, @file{configure} will check for both header
-existence (with the preprocessor) and usability (with the compiler),
-using @code{AC_INCLUDES_DEFAULT} for the compile test.  If
-there is a discrepancy between the results, a warning is issued to the
-user, and the compiler results are favored (@pxref{Present But
-Cannot Be Compiled}).  In general, favoring the compiler results means
-that a header will be treated as not found even though the file exists,
-because you did not provide enough prerequisites.
+@var{includes} should be the appropriate @dfn{prerequisite} code, i.e.@:
+whatever might be required to appear above
+@samp{#include @var{header-file}} for it to compile without error.
+This can be anything, but will normally be additional @samp{#include}
+directives. If @var{includes} is omitted or empty, @file{configure} will
+use the contents of the macro @code{AC_INCLUDES_DEFAULT}.
+@xref{Default Includes}.
 
-Providing a non-empty @var{includes} argument allows the code to provide
-any prerequisites prior to including the header under test; it is common
-to use the argument @code{AC_INCLUDES_DEFAULT} (@pxref{Default
-Includes}).  With an explicit fourth argument, no preprocessor test is
-needed.  As a special case, an @var{includes} of exactly @samp{-}
-triggers the older preprocessor check, which merely determines existence
-of the file in the preprocessor search path; this should only be used as
-a last resort (it is safer to determine the actual prerequisites and
-perform a compiler check, or else use @code{AC_PREPROC_IFELSE} to make
-it obvious that only a preprocessor check is desired).
+This macro used to check only for the @emph{presence} of a header, not
+whether its contents were acceptable to the compiler.  Some older
+@command{configure} scripts rely on this behavior, so it is still
+available by specifying @samp{-} as @var{includes}.  This mechanism is
+deprecated as of Autoconf 2.70; situations where a preprocessor-only
+check is required should use @code{AC_PREPROC_IFELSE}.
+@xref{Running the Preprocessor}.
 
 This macro caches its result in the @code{ac_cv_header_@var{header-file}}
 variable, with characters not suitable for a variable name mapped to
@@ -6305,47 +6300,49 @@ variable, with characters not suitable for a variable name mapped to
 underscores.
 @end defmac
 
-Previous versions of Autoconf merely checked whether the header was
-accepted by the preprocessor.  This was changed because the old test was
-inappropriate for typical uses.  Headers are typically used to compile,
-not merely to preprocess, and the old behavior sometimes accepted
-headers that clashed at compile-time (@pxref{Present But Cannot Be
-Compiled}).  If you need to check whether a header is preprocessable,
-you can use @code{AC_PREPROC_IFELSE} (@pxref{Running the Preprocessor}).
+@defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})
+@acindex{CHECK_HEADERS_ONCE}
+@cvindex HAVE_@var{header}
+For each given system

Re: [PATCH 0/2] Modernize header checks

2013-05-31 Thread Zack Weinberg
On Fri, May 31, 2013 at 12:39 PM, Russ Allbery r...@stanford.edu wrote:
 Zack Weinberg za...@panix.com writes:

 I *think* your patch would remove strings.h from the list of headers that
 are probed by default by Autoconf, and hence remove HAVE_STRINGS_H from
 the preprocessor directives set by Autoconf.

That's right.

 If so, note that removing strings.h from the list of headers that are
 probed by default will cause backwards compatibility issues.  One still
 must include strings.h (not string.h) according to POSIX in order to get
 strcasecmp and friends, and some operating systems (specifically at least
 some versions of FreeBSD) do actually enforce that and do not prototype
 those functions in string.h.  I'm quite sure there is code out there that
 assumes that Autoconf will probe for strings.h as a side effect of other
 probes and set HAVE_STRINGS_H, and therefore doesn't probe for it
 explicitly.  (I maintain some of it, in fact.)

I had been under the impression that everything one still wanted out
of strings.h was also specified to be in string.h (in particular both
strcasecmp and ffs).  I see now that this is wrong.

For the short term I'm good with putting a conditional #include of
strings.h and a probe for it back into AC_INCLUDES_DEFAULT (MSVC is
the only common platform that doesn't seem to have it, but that's true
even in the very latest version).  However, I'd like to come up with a
transition plan so we don't have to treat this as an
almost-always-wanted header forever.  We don't have any tooling for a
you need to start probing for this manually warning, do we?  An
unconditional AC_DIAGNOSE would be spurious for most people...

I'm also good with restoring compatibility AC_DEFINEs for the C90
headers (HAVE_STRING_H, HAVE_STDDEF_H, HAVE_STDLIB_H, I think that was
all) just to be safe.



[PATCH 3/3] Use AC_CHECK_HEADERS_ONCE for the tests done by AC_INCLUDES_DEFAULT.

2013-09-07 Thread Zack Weinberg

 * lib/autoconf/headers.m4 (AC_CHECK_HEADERS_ONCE): Divide into a public
   macro that AC_REQUIREs _AC_INCLUDES_DEFAULT_REQUIREMENTS, and ...
   (_AC_CHECK_HEADERS_ONCE): ... a private macro, that doesn't.
   (_AC_HEADERS_EXPANSION): Use $ac_includes_default, not AC_INCLUDES_DEFAULT.
   (_AC_INCLUDES_DEFAULT_REQUIREMENTS): Use AC_CHECK_HEADERS_ONCE.
   (all of the above): Sprinkle dnl's around.

Signed-off-by: Zack Weinberg za...@panix.com
---
 lib/autoconf/headers.m4 |   24 +++-
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 6fe1380..8f2272a 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -203,14 +203,20 @@ _AC_HEADERS_EXPANSION])AC_REQUIRE([_AC_Header_]m4_translit([[$1]],
 # -
 # Add each whitespace-separated name in HEADER-FILE to the list of
 # headers to check once.
+# Note: has intimate knowledge of how AC_INCLUDES_DEFAULT works,
+# and vice versa.
+
 AC_DEFUN([AC_CHECK_HEADERS_ONCE],
+[AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
+_AC_CHECK_HEADERS_ONCE([$1])])
+AC_DEFUN([_AC_CHECK_HEADERS_ONCE],
 [m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])
 
 m4_define([_AC_HEADERS_EXPANSION],
-[
-  m4_divert_text([DEFAULTS], [ac_header_list=])
-  AC_CHECK_HEADERS([$ac_header_list], [], [], [AC_INCLUDES_DEFAULT])
-  m4_define([_AC_HEADERS_EXPANSION], [])
+[dnl
+  m4_divert_text([DEFAULTS], [ac_header_list=])dnl
+  AC_CHECK_HEADERS([$ac_header_list], [], [], [$ac_includes_default])dnl
+  m4_define([_AC_HEADERS_EXPANSION], [])dnl
 ])
 
 
@@ -255,19 +261,19 @@ ac_includes_default=\
 # include unistd.h
 #endif
 ])dnl
-AC_CHECK_HEADERS([sys/types.h sys/stat.h strings.h inttypes.h stdint.h unistd.h],
- [], [], [$ac_includes_default])
+_AC_CHECK_HEADERS_ONCE([sys/types.h sys/stat.h strings.h inttypes.h stdint.h
+unistd.h])dnl
 dnl For backward compatibility, provide unconditional AC_DEFINEs of
 dnl HAVE_STDLIB_H, HAVE_STRING_H, and STDC_HEADERS.
 AC_DEFINE(HAVE_STDLIB_H, 1,
   [Always define to 1, for backward compatibility.
-   You can assume stdlib.h exists.])
+   You can assume stdlib.h exists.])dnl
 AC_DEFINE(HAVE_STRING_H, 1,
   [Always define to 1, for backward compatibility.
-   You can assume string.h exists.])
+   You can assume string.h exists.])dnl
 AC_DEFINE(STDC_HEADERS, 1,
   [Always define to 1, for backward compatibility.
-   You can assume the C90 standard headers exist.])
+   You can assume the C90 standard headers exist.])dnl
 ])# _AC_INCLUDES_DEFAULT_REQUIREMENTS
 
 


[PATCH 1/3] AC_CHECK_HEADER/AC_CHECK_HEADERS: complete transition to compile tests.

2013-09-07 Thread Zack Weinberg

* lib/autoconf/headers.m4 (AC_CHECK_HEADER): Use _AC_CHECK_HEADER_COMPILE
  by default.  Continue to use _AC_CHECK_HEADER_PREPROC if fourth arg is '-'.
  (_AC_CHECK_HEADER_PREPROC): Issue a deprecation warning.
  (_AC_CHECK_HEADER_MONGREL, _AC_CHECK_HEADER_MONGREL_BODY): Remove.

* tests/local.at (AT_CHECK_M4): Support 'stderr' as fourth argument.
* tests/c.at, tests/semantics.at: Update uses of AC_CHECK_HEADER(S).
* doc/autoconf.texi, NEWS: Document change.

Signed-off-by: Zack Weinberg za...@panix.com
---
 NEWS|   10 
 doc/autoconf.texi   |  106 ++---
 lib/autoconf/headers.m4 |  109 +--
 tests/c.at  |   28 +---
 tests/local.at  |5 +-
 tests/semantics.at  |   17 ---
 6 files changed, 115 insertions(+), 160 deletions(-)

diff --git a/NEWS b/NEWS
index de9d915..1378388 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,16 @@ GNU Autoconf NEWS - User visible changes.
echo.  Macros AS_ECHO and AS_ECHO_N now expand unconditionally to
'printf %s\n' and 'printf %s'.
 
+** AC_CHECK_HEADER and AC_CHECK_HEADERS now default to doing only a
+   compilation test.  This completes the transition from preprocessor-
+   based header tests begun in Autoconf 2.56.
+
+   The double test that was the default since Autoconf 2.64 is no
+   longer available.  You can still request a preprocessor-only test
+   by specifying '-' as the fourth argument to either macro, but this
+   is now deprecated.  If you really need that behavior use
+   AC_PREPROC_IFELSE.
+
 ** Macros
 
 - New macro AC_C__GENERIC.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 26e7b17..a68dc07 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6253,26 +6253,21 @@ commands @var{action-if-found}, otherwise execute
 header file is available, consider using @code{AC_CHECK_HEADERS}
 instead.
 
-@var{includes} is decoded to determine the appropriate include
-directives.  If omitted or empty, @file{configure} will check for both header
-existence (with the preprocessor) and usability (with the compiler),
-using @code{AC_INCLUDES_DEFAULT} for the compile test.  If
-there is a discrepancy between the results, a warning is issued to the
-user, and the compiler results are favored (@pxref{Present But
-Cannot Be Compiled}).  In general, favoring the compiler results means
-that a header will be treated as not found even though the file exists,
-because you did not provide enough prerequisites.
+@var{includes} should be the appropriate @dfn{prerequisite} code, i.e.@:
+whatever might be required to appear above
+@samp{#include @var{header-file}} for it to compile without error.
+This can be anything, but will normally be additional @samp{#include}
+directives. If @var{includes} is omitted or empty, @file{configure} will
+use the contents of the macro @code{AC_INCLUDES_DEFAULT}.
+@xref{Default Includes}.
 
-Providing a non-empty @var{includes} argument allows the code to provide
-any prerequisites prior to including the header under test; it is common
-to use the argument @code{AC_INCLUDES_DEFAULT} (@pxref{Default
-Includes}).  With an explicit fourth argument, no preprocessor test is
-needed.  As a special case, an @var{includes} of exactly @samp{-}
-triggers the older preprocessor check, which merely determines existence
-of the file in the preprocessor search path; this should only be used as
-a last resort (it is safer to determine the actual prerequisites and
-perform a compiler check, or else use @code{AC_PREPROC_IFELSE} to make
-it obvious that only a preprocessor check is desired).
+This macro used to check only for the @emph{presence} of a header, not
+whether its contents were acceptable to the compiler.  Some older
+@command{configure} scripts rely on this behavior, so it is still
+available by specifying @samp{-} as @var{includes}.  This mechanism is
+deprecated as of Autoconf 2.70; situations where a preprocessor-only
+check is required should use @code{AC_PREPROC_IFELSE}.
+@xref{Running the Preprocessor}.
 
 This macro caches its result in the @code{ac_cv_header_@var{header-file}}
 variable, with characters not suitable for a variable name mapped to
@@ -6303,47 +6298,49 @@ variable, with characters not suitable for a variable name mapped to
 underscores.
 @end defmac
 
-Previous versions of Autoconf merely checked whether the header was
-accepted by the preprocessor.  This was changed because the old test was
-inappropriate for typical uses.  Headers are typically used to compile,
-not merely to preprocess, and the old behavior sometimes accepted
-headers that clashed at compile-time (@pxref{Present But Cannot Be
-Compiled}).  If you need to check whether a header is preprocessable,
-you can use @code{AC_PREPROC_IFELSE} (@pxref{Running the Preprocessor}).
+@defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})
+@acindex{CHECK_HEADERS_ONCE}
+@cvindex HAVE_@var{header}
+For each given system

[PATCH 2/3] Modernize AC_INCLUDES_DEFAULT and friends.

2013-09-07 Thread Zack Weinberg

 * lib/autoconf/headers.m4 (_AC_INCLUDES_DEFAULT_REQUIREMENTS):
   Include stddef.h, stdlib.h, and string.h unconditionally.
   Don't include memory.h at all.
   Don't use AC_HEADER_STDC.
   Don't check for stddef.h, stdlib.h, string.h, or memory.h.
   For compatibility, unconditionally define STDC_HEADERS,
   HAVE_STDLIB_H, and HAVE_STRING_H.
   (AN_HEADER list): Remove C89 headers, and memory.h from list.
   (AC_HEADER_STDC): AU_DEFUN as an explicit invocation of
   _AC_INCLUDES_DEFAULT_REQUIREMENTS.
   (AC_HEADER_TIME): AU_DEFUN, and define TIME_WITH_SYS_TIME unconditionally
   as long as sys/time.h is present.
   (AC_USG, AC_MEMORY_H): Assume existence of string.h.
 * lib/autoconf/functions.m4 (_AC_FUNC_MALLOC_IF, _AC_FUNC_REALLOC_IF):
   Don't use AC_HEADER_STDC. Assume stdlib.h exists.
   (AC_FUNC_MKTIME): Don't use AC_HEADER_TIME.
   (AC_FUNC_ALLOCA): Assume stdlib.h exists.
   (_AC_LIBOBJ_FNMATCH): Assume wchar.h and wctype.h exist.
   (_AC_LIBOBJ_GETLOADAVG): Assume locale.h exists.
   (AC_FUNC_MMAP): Assume stdlib.h exists.
 * tests/tools.at: Use AC_WORDS_BIGENDIAN instead of AC_STDC_HEADERS in
   autoupdate test.

 * NEWS, doc/autoconf.texi: Document changes. Remove obsolete advice.

Signed-off-by: Zack Weinberg za...@panix.com
---
 NEWS  |   24 
 doc/autoconf.texi |  314 +
 lib/autoconf/functions.m4 |   35 +
 lib/autoconf/headers.m4   |  179 ++
 tests/tools.at|6 +-
 5 files changed, 218 insertions(+), 340 deletions(-)

diff --git a/NEWS b/NEWS
index 1378388..623b008 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,30 @@ GNU Autoconf NEWS - User visible changes.
 - AT_TESTED arguments can use variable or command substitutions, including
   in particular $EXEEXT
 
+- AC_INCLUDES_DEFAULT has been streamlined.  It now assumes that the
+  ISO C90 headers 'stdlib.h' and 'string.h' are unconditionally
+  available, and does not include the pre-standard header 'memory.h'
+  at all.  If the POSIX header 'strings.h' exists, it will be
+  included; it is assumed to be safe to include both 'string.h' and
+  'strings.h' in the same source file.  We are not aware of any
+  current system that violates any of the above assumptions.
+
+  For compatibility's sake, the C preprocessor macros STDC_HEADERS,
+  HAVE_STDLIB_H, and HAVE_STRING_H are defined unconditionally.
+  These preprocessor macros should be considered obsolescent.
+
+  Future releases of Autoconf may reduce the set of headers checked
+  for by AC_INCLUDES_DEFAULT.
+
+- AC_HEADER_STDC and AC_HEADER_TIME are now stubs which will be
+  removed from 'configure.ac' by 'autoupdate'.  For compatibility's
+  sake, the stubs (and their 'autoupdate' replacements) continue to
+  define the C preprocessor macros STDC_HEADERS and TIME_WITH_SYS_TIME,
+  respectively, but without actually checking for the ancient systems
+  where formerly those macros would not be defined.
+
+  These macros were already labeled obsolescent in the manual.
+
 * Noteworthy changes in release 2.69 (2012-04-24) [stable]
 
 ** Autoconf now requires perl 5.6 or better (but generated configure
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index a68dc07..01d714e 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -3881,15 +3881,9 @@ protected includes, such as:
 
 @example
 @group
-#ifdef TIME_WITH_SYS_TIME
+#include time.h
+#ifdef HAVE_SYS_TIME_H
 # include sys/time.h
-# include time.h
-#else
-# ifdef HAVE_SYS_TIME_H
-#  include sys/time.h
-# else
-#  include time.h
-# endif
 #endif
 @end group
 @end example
@@ -3904,27 +3898,20 @@ of includes:
 
 @defmac AC_INCLUDES_DEFAULT (@ovar{include-directives})
 @acindex{INCLUDES_DEFAULT}
-Expand to @var{include-directives} if defined, otherwise to:
+Expand to @var{include-directives} if present and nonempty, otherwise to:
 
 @example
 @group
+#include stddef.h
 #include stdio.h
+#include stdlib.h
+#include string.h
 #ifdef HAVE_SYS_TYPES_H
 # include sys/types.h
 #endif
 #ifdef HAVE_SYS_STAT_H
 # include sys/stat.h
 #endif
-#if defined STDC_HEADERS || defined HAVE_STDLIB_H
-# include stdlib.h
-#endif
-#include stddef.h
-#ifdef HAVE_STRING_H
-# if !defined STDC_HEADERS  defined HAVE_MEMORY_H
-#  include memory.h
-# endif
-# include string.h
-#endif
 #ifdef HAVE_STRINGS_H
 # include strings.h
 #endif
@@ -3940,14 +3927,12 @@ Expand to @var{include-directives} if defined, otherwise to:
 @end group
 @end example
 
-If the default includes are used, then check for the presence of these
-headers and their compatibility, i.e., you don't need to run
-@code{AC_HEADER_STDC}, nor check for @file{stdlib.h} etc.
-
-These headers are checked for in the same order as they are included.
-For instance, on some systems @file{string.h} and @file{strings.h} both
-exist, but conflict.  Then @code{HAVE_STRING_H} is defined, not
-@code{HAVE_STRINGS_H}.
+Using this macro without @var{include-directives} has the side effect of
+checking

Re: [PATCH 0/3] Modernize header checks, v2

2013-09-07 Thread Zack Weinberg

On 2013-09-07 10:06 AM, Paul Eggert wrote:

Zack Weinberg wrote:

One remaining wart is that autoupdate
replaces AC_HEADER_STDC with an overt invocation of
_AC_INCLUDES_DEFAULT_REQUIREMENTS.  I couldn't find an AU_DEFUN
construct that didn't expose this internal macro but would still DTRT
both before and after an autoupdate run.  Ideas?


Perhaps we should make that macro public, under the name
AC_INCLUDES_DEFAULT_REQUIREMENTS.  It does seem weird
to inject _AC_* stuff into user code.


I had a better idea this morning.  The problem I was having is 
fundamentally the same problem as Ross was having with conditional 
AC_CHECK_HEADERS, so:


AU_DEFUN([AC_HEADER_STDC],
[# Autoupdate added the following line to ensure that your configure
# script's behavior did not change.  It is probably safe to remove.
AS_IF([:], [], [ac_dummy=AC_INCLUDES_DEFAULT])
],
 [...])

The complete testsuite is still running, but the specific check of 
AC_HEADER_STDC passed with this construct.



The other changes you're making all sound reasonable,
though I haven't reviewed the code.  Unless someone
objects soon I think they should be installed.  Would
you like to do that?  I see two Zack Weinbergs zackw
and zwol at Savannah, but neither have checkin rights,
so I'm not sure what's going on there.


'zackw' is my current Savannah account.  If you give it checkin rights, 
I can land the patches.  I would appreciate a detailed review if you 
have time, though; this is the first time I've attempted to make serious 
changes to Autoconf itself.


'zwol' is also a handle I use often; it's likely that I created that 
account some time ago and then lost the password.


zw



Re: problem with ./configure

2013-09-12 Thread Zack Weinberg

On 2013-09-12 12:13 PM, Eric Blake wrote:


That could help if we had a 'break' statement to abort the loop once we
think a version had been scraped; but right now, the full loop is
executed to completion regardless of what option(s) the compiler
understands (and in the case of gcc, executing both --version AND -v is
useful, as they give different outputs, both of which are useful).


Oh.  OK.


I'm okay if someone writes a patch to propose such an early exit (the
fewer times we execute 'gcc', the faster a configure script will run -
provided we aren't adding more forks in our decision for an early exit
in the first place), but am not sure I will tackle it myself.


Coincidentally I have fairly sophisticated compiler-version-detection 
logic written for another project; I'm not promising to do this anytime 
soon, but I might see about porting it over.


zw




Re: problem with ./configure

2013-09-12 Thread Zack Weinberg

On 2013-09-12 11:25 AM, Eric Blake wrote:


-for ac_option in --version -v -V -qversion; do
+for ac_option in --version -v -V -qversion -version; do
_AC_DO_LIMIT([$ac_compiler $ac_option AS_MESSAGE_LOG_FD])


This isn't anything to do with your change, but -qversion should be 
moved to the second position in this list, because the AIX compiler's 
response to any unrecognized command-line option is to dump its _entire 
manpage_ to stdout, which is IIRC about 10,000 lines of text.  I see 
that _AC_DO_LIMIT clips to ten lines by default, so we're not gonna get 
a ridiculous amount of junk in config.log, but it would still be more 
efficient to have it closer to the beginning (I only suggest we put it 
second because it's far more likely that the user actually has a 
compiler that understands --version).


zw



[PATCH 4/6] Use AC_CHECK_HEADERS_ONCE for the tests done by AC_INCLUDES_DEFAULT.

2013-09-15 Thread Zack Weinberg

 * lib/autoconf/headers.m4 (AC_CHECK_HEADERS_ONCE): Divide into a public
   macro that AC_REQUIREs _AC_INCLUDES_DEFAULT_REQUIREMENTS, and ...
   (_AC_CHECK_HEADERS_ONCE): ... a private macro, that doesn't.
   (_AC_HEADERS_EXPANSION): Use $ac_includes_default, not
   AC_INCLUDES_DEFAULT.
   (_AC_INCLUDES_DEFAULT_REQUIREMENTS): Use AC_CHECK_HEADERS_ONCE.

Signed-off-by: Zack Weinberg za...@panix.com
---
 lib/autoconf/headers.m4 |   16 +++-
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 634cf45..eb3aec8 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -204,14 +204,20 @@ _AC_HEADERS_EXPANSION])AC_REQUIRE([_AC_Header_]m4_translit([[$1]],
 # -
 # Add each whitespace-separated name in HEADER-FILE to the list of
 # headers to check once.
+# Note: has intimate knowledge of how AC_INCLUDES_DEFAULT works,
+# and vice versa.
+
 AC_DEFUN([AC_CHECK_HEADERS_ONCE],
+[AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
+_AC_CHECK_HEADERS_ONCE([$1])])
+AC_DEFUN([_AC_CHECK_HEADERS_ONCE],
 [m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])
 
 m4_define([_AC_HEADERS_EXPANSION],
-[
-  m4_divert_text([DEFAULTS], [ac_header_list=])
-  AC_CHECK_HEADERS([$ac_header_list], [], [], [AC_INCLUDES_DEFAULT])
-  m4_define([_AC_HEADERS_EXPANSION], [])
+[dnl
+  m4_divert_text([DEFAULTS], [ac_header_list=])dnl
+  AC_CHECK_HEADERS([$ac_header_list], [], [], [$ac_includes_default])dnl
+  m4_define([_AC_HEADERS_EXPANSION], [])dnl
 ])
 
 
@@ -256,7 +262,7 @@ ac_includes_default=\
 # include unistd.h
 #endif
 ])]dnl
-[AC_CHECK_HEADERS(
+[_AC_CHECK_HEADERS_ONCE(
   [sys/types.h sys/stat.h strings.h inttypes.h stdint.h unistd.h],
   [], [], [$ac_includes_default])]dnl
 dnl For backward compatibility, provide unconditional AC_DEFINEs of


[PATCH 3/6] Modernize AC_INCLUDES_DEFAULT and friends.

2013-09-15 Thread Zack Weinberg

 * lib/autoconf/headers.m4 (_AC_INCLUDES_DEFAULT_REQUIREMENTS):
   Include stddef.h, stdlib.h, and string.h unconditionally.
   Don't include memory.h at all.
   Don't use AC_HEADER_STDC.
   Don't check for stddef.h, stdlib.h, string.h, or memory.h.
   For compatibility, unconditionally define STDC_HEADERS,
   HAVE_STDLIB_H, and HAVE_STRING_H.
   (AN_HEADER list): Remove C89 headers, and memory.h from list.
   (AC_HEADER_STDC, AC_UNISTD_H): AU_DEFUN to trigger
   _AC_INCLUDES_DEFAULT_REQUIREMENTS if it hasn't already happened,
   and do nothing else.
   (AC_HEADER_TIME): AU_DEFUN, and define TIME_WITH_SYS_TIME unconditionally
   as long as sys/time.h is present.
   (AC_USG, AC_MEMORY_H): Assume existence of string.h.
 * lib/autoconf/functions.m4 (_AC_FUNC_MALLOC_IF, _AC_FUNC_REALLOC_IF):
   Don't use AC_HEADER_STDC. Assume stdlib.h exists.
   (AC_FUNC_MKTIME): Don't use AC_HEADER_TIME.  Assume time.h exists.
   (AC_FUNC_ALLOCA): Assume stdlib.h exists.
   (_AC_LIBOBJ_FNMATCH): Assume wchar.h and wctype.h exist.
   (_AC_LIBOBJ_GETLOADAVG): Assume locale.h exists.
   (AC_FUNC_MMAP): Assume stdlib.h exists.
 * tests/tools.at: Use AC_WORDS_BIGENDIAN instead of AC_STDC_HEADERS in
   autoupdate test.

 * NEWS, doc/autoconf.texi: Document changes. Remove obsolete advice.

Signed-off-by: Zack Weinberg za...@panix.com
---
 NEWS  |   24 +++
 doc/autoconf.texi |  373 ++---
 lib/autoconf/functions.m4 |   47 ++-
 lib/autoconf/headers.m4   |  189 +--
 tests/tools.at|6 +-
 5 files changed, 257 insertions(+), 382 deletions(-)

diff --git a/NEWS b/NEWS
index 5d6c657..f2cd5c5 100644
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,30 @@ GNU Autoconf NEWS - User visible changes.
 - AT_TESTED arguments can use variable or command substitutions, including
   in particular $EXEEXT
 
+- AC_INCLUDES_DEFAULT has been streamlined.  It now assumes that the
+  ISO C90 headers 'stdlib.h' and 'string.h' are unconditionally
+  available, and does not include the pre-standard header 'memory.h'
+  at all.  If the POSIX header 'strings.h' exists, it will be
+  included; it is assumed to be safe to include both 'string.h' and
+  'strings.h' in the same source file.  We are not aware of any
+  current system that violates any of the above assumptions.
+
+  For compatibility's sake, the C preprocessor macros STDC_HEADERS,
+  HAVE_STDLIB_H, and HAVE_STRING_H are defined unconditionally.
+  These preprocessor macros should be considered obsolescent.
+
+  Future releases of Autoconf may reduce the set of headers checked
+  for by AC_INCLUDES_DEFAULT.
+
+- AC_HEADER_STDC and AC_HEADER_TIME are now stubs which will be
+  removed from 'configure.ac' by 'autoupdate'.  For compatibility's
+  sake, the stubs (and their 'autoupdate' replacements) continue to
+  define the C preprocessor macros STDC_HEADERS and TIME_WITH_SYS_TIME,
+  respectively, but without actually checking for the ancient systems
+  where formerly those macros would not be defined.
+
+  These macros were already labeled obsolescent in the manual.
+
 * Noteworthy changes in release 2.69 (2012-04-24) [stable]
 
 ** Autoconf now requires perl 5.6 or better (but generated configure
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 0c489a3..d097c23 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -3885,57 +3885,78 @@ succeeds.
 @subsection Default Includes
 @cindex Default includes
 @cindex Includes, default
+@hdrindex{assert.h}
+@hdrindex{ctype.h}
+@hdrindex{errno.h}
+@hdrindex{float.h}
+@hdrindex{iso646.h}
+@hdrindex{limits.h}
+@hdrindex{locale.h}
+@hdrindex{math.h}
+@hdrindex{setjmp.h}
+@hdrindex{signal.h}
+@hdrindex{stdarg.h}
+@hdrindex{stddef.h}
+@hdrindex{stdio.h}
+@hdrindex{stdlib.h}
+@hdrindex{string.h}
+@hdrindex{time.h}
+@hdrindex{wchar.h}
+@hdrindex{wctype.h}
 
-Several tests depend upon a set of header files.  Since these headers
-are not universally available, tests actually have to provide a set of
-protected includes, such as:
+Test programs frequently need to include headers that may or may not be
+available on the system whose features are being tested.  Each test can
+use all the preprocessor macros that have been @code{AC_DEFINE}d by
+previous tests, so for example one may write
 
 @example
 @group
-#ifdef TIME_WITH_SYS_TIME
+#include time.h
+#ifdef HAVE_SYS_TIME_H
 # include sys/time.h
-# include time.h
-#else
-# ifdef HAVE_SYS_TIME_H
-#  include sys/time.h
-# else
-#  include time.h
-# endif
 #endif
 @end group
 @end example
 
 @noindent
-Unless you know exactly what you are doing, you should avoid using
-unconditional includes, and check the existence of the headers you
-include beforehand (@pxref{Header Files}).
+if @file{sys/time.h} has already been tested for.
 
-Most generic macros use the following macro to provide the default set
+All hosted environments that are still of interest for portable code
+provide all of the headers specified in ISO C90

[PATCH 6/6] Expose the checks done by AC_INCLUDES_DEFAULT as a public macro.

2013-09-15 Thread Zack Weinberg

 * lib/autoconf/headers.m4 (_AC_INCLUDES_DEFAULT_REQUIREMENTS):
   Rename to AC_CHECK_INCLUDES_DEFAULT.  All callers changed.
   (AC_HEADER_STDC, AC_UNISTD_H): Use AC_CHECK_INCLUDES_DEFAULT instead
   of previous kludge.

 * doc/autoconf.texi: Document AC_CHECK_INCLUDES_DEFAULT.

Signed-off-by: Zack Weinberg za...@panix.com
---
 doc/autoconf.texi   |   13 +
 lib/autoconf/headers.m4 |   22 +-
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index d097c23..dad882f 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -3980,6 +3980,19 @@ unconditionally defines @code{HAVE_STRING_H}, @code{HAVE_STDLIB_H}, and
 @code{STDC_HEADERS}.
 @end defmac
 
+@defmac AC_CHECK_INCLUDES_DEFAULT
+@acindex{CHECK_INCLUDES_DEFAULT}
+Check for all the headers that @code{AC_INCLUDES_DEFAULT} would check
+for as a side-effect, if this has not already happened.
+
+This macro mainly exists so that @code{autoupdate} can replace certain
+obsolete constructs with it. You should not need to use it yourself; in
+fact, it is likely to be safe to delete it from any script in which it
+appears.  (@code{autoupdate} does not know whether preprocessor macros
+such as @code{HAVE_STDINT_H} are used in the program, nor whether they
+would get defined as a side-effect of other checks.)
+@end defmac
+
 @node Alternative Programs
 @section Alternative Programs
 @cindex Programs, checking
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 2fa06cf..e4fe347 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -208,7 +208,7 @@ _AC_HEADERS_EXPANSION])AC_REQUIRE([_AC_Header_]m4_translit([[$1]],
 # and vice versa.
 
 AC_DEFUN([AC_CHECK_HEADERS_ONCE],
-[AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
+[AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])dnl
 _AC_CHECK_HEADERS_ONCE([$1])])
 AC_DEFUN([_AC_CHECK_HEADERS_ONCE],
 [m4_map_args_w([$1], [_AC_CHECK_HEADER_ONCE(], [)])])
@@ -231,10 +231,10 @@ m4_define([_AC_HEADERS_EXPANSION],
 # macros.  It is easier to document, to extend, and to understand than
 # having specific defaults for each macro.
 
-# _AC_INCLUDES_DEFAULT_REQUIREMENTS
-# -
+# AC_CHECK_INCLUDES_DEFAULT
+# -
 # Required when AC_INCLUDES_DEFAULT uses its default branch.
-AC_DEFUN_ONCE([_AC_INCLUDES_DEFAULT_REQUIREMENTS],
+AC_DEFUN_ONCE([AC_CHECK_INCLUDES_DEFAULT],
 dnl If ever you change this variable, please keep autoconf.texi in sync.
 [m4_divert_text([DEFAULTS],
 [# Factoring default headers for most tests.
@@ -276,7 +276,7 @@ dnl HAVE_STDLIB_H, HAVE_STRING_H, and STDC_HEADERS.
 [AC_DEFINE([STDC_HEADERS], [1],
   [Always define to 1, for backward compatibility.
You can assume the C90 standard headers exist.])])
-# _AC_INCLUDES_DEFAULT_REQUIREMENTS
+# AC_CHECK_INCLUDES_DEFAULT
 
 
 # AC_INCLUDES_DEFAULT([INCLUDES])
@@ -291,11 +291,8 @@ dnl HAVE_STDLIB_H, HAVE_STRING_H, and STDC_HEADERS.
 AC_DEFUN([AC_INCLUDES_DEFAULT],
 [m4_ifval([$1], [$1
 ],
-	  [AC_REQUIRE([_AC_INCLUDES_DEFAULT_REQUIREMENTS])dnl
-$ac_includes_default])])
-
-
-
+[AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])]dnl
+[$ac_includes_default])])
 
 
 ## --- ##
@@ -607,8 +604,7 @@ fi
 AU_DEFUN([AC_HEADER_STDC],
 [# Autoupdate added the following line to ensure that your configure
 # script's behavior did not change.  It is probably safe to remove.
-AS_IF([:], [], [ac_dummy=AC_INCLUDES_DEFAULT])
-],
+AC_CHECK_INCLUDES_DEFAULT],
  [The preprocessor macro `STDC_HEADERS' is obsolete.
   Except in unusual embedded environments, you can safely include all
   ISO C90 headers unconditionally.])
@@ -715,7 +711,7 @@ fi
 AU_DEFUN([AC_UNISTD_H],
 [# Autoupdate added the following line to ensure that your configure
 # script's behavior did not change.  It is probably safe to remove.
-AS_IF([:], [], [ac_dummy=AC_INCLUDES_DEFAULT])])
+AC_CHECK_INCLUDES_DEFAULT])
 
 
 # AU::AC_USG


[PATCH 5/6] Use AC_CHECK_{DECLS, FUNCS, HEADERS}_ONCE more in specific-check macros.

2013-09-15 Thread Zack Weinberg

 * lib/autoconf/functions.m4 (AC_FUNC_CHOWN): No need to check for unistd.h.
   (_AC_LIBOBJ_FNMATCH): Use AC_CHECK_DECLS_ONCE and AC_CHECK_FUNCS_ONCE.
   (_AC_LIBOBJ_GETLOADAVG): Use AC_CHECK_FUNCS_ONCE for setlocale.
   (AC_FUNC_MMAP): Use AC_CHECK_FUNCS_ONCE for getpagesize.
   (AC_FUNC_SELECT_ARGTYPES): Use AC_CHECK_HEADERS_ONCE for sys/select.h and
   sys/socket.h.
   (AC_FUNC_STRERROR_R): Use AC_CHECK_DECLS_ONCE + AC_CHECK_FUNCS_ONCE for
   strerror_r.
   (AC_FUNC_UTIME_NULL): Use AC_CHECK_HEADERS_ONCE for utime.h.
   (AC_FUNC_FORK): Use AC_CHECK_HEADERS_ONCE and AC_CHECK_FUNCS_ONCE.
   (AC_FUNC_VPRINTF): Use AC_CHECK_FUNCS_ONCE for vprintf (but not _doprnt).

 * lib/autoconf/headers.m4 (AC_HEADER_TIME, AC_MEMORY_H): Use
   AC_CHECK_HEADERS_ONCE.

Signed-off-by: Zack Weinberg za...@panix.com
---
 lib/autoconf/functions.m4 |   32 +++-
 lib/autoconf/headers.m4   |4 ++--
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index 1a378f5..ab13779 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -422,7 +422,6 @@ AN_FUNCTION([chown], [AC_FUNC_CHOWN])
 AC_DEFUN([AC_FUNC_CHOWN],
 [AC_REQUIRE([AC_TYPE_UID_T])dnl
 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
-AC_CHECK_HEADERS(unistd.h)
 AC_CACHE_CHECK([for working chown], ac_cv_func_chown_works,
 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
 #include fcntl.h
@@ -562,8 +561,8 @@ AC_DEFUN([_AC_LIBOBJ_FNMATCH],
 [AC_REQUIRE([AC_C_CONST])dnl
 AC_REQUIRE([AC_FUNC_ALLOCA])dnl
 AC_REQUIRE([AC_TYPE_MBSTATE_T])dnl
-AC_CHECK_DECLS([getenv])
-AC_CHECK_FUNCS([btowc mbsrtowcs mempcpy wmempcpy])
+AC_CHECK_DECLS_ONCE([getenv])
+AC_CHECK_FUNCS_ONCE([btowc mbsrtowcs mempcpy wmempcpy])
 AC_LIBOBJ([fnmatch])
 AC_CONFIG_LINKS([$ac_config_libobj_dir/fnmatch.h:$ac_config_libobj_dir/fnmatch_.h])
 AC_DEFINE(fnmatch, rpl_fnmatch,
@@ -674,14 +673,13 @@ m4_define([_AC_LIBOBJ_GETLOADAVG],
 [AC_LIBOBJ(getloadavg)
 AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
 # Figure out what our getloadavg.c needs.
+AC_CHECK_FUNCS_ONCE([setlocale])
 ac_have_func=no
 AC_CHECK_HEADER(sys/dg_sys_info.h,
 [ac_have_func=yes
  AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with sys/dg_sys_info.h.])
  AC_CHECK_LIB(dgc, dg_sys_info)])
 
-AC_CHECK_FUNCS(setlocale)
-
 # We cannot check for dwarf.h, because Solaris 2 does not use dwarf (it
 # uses stabs), but it is still SVR4.  We cannot check for elf.h because
 # Irix 4.0.5F has the header but not the library.
@@ -1212,7 +1210,7 @@ AN_FUNCTION([mmap], [AC_FUNC_MMAP])
 AC_DEFUN([AC_FUNC_MMAP],
 [AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
 AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
-AC_CHECK_FUNCS([getpagesize])
+AC_CHECK_FUNCS_ONCE([getpagesize])
 AC_CACHE_CHECK([for working mmap], [ac_cv_func_mmap_fixed_mapped],
 [AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
 [[/* malloc might have been renamed as rpl_malloc. */
@@ -1447,7 +1445,7 @@ AC_DEFUN([AC_FUNC_REALLOC],
 # function's arguments, and define those types in `SELECT_TYPE_ARG1',
 # `SELECT_TYPE_ARG234', and `SELECT_TYPE_ARG5'.
 AC_DEFUN([AC_FUNC_SELECT_ARGTYPES],
-[AC_CHECK_HEADERS(sys/select.h sys/socket.h)
+[AC_CHECK_HEADERS_ONCE([sys/select.h sys/socket.h])
 AC_CACHE_CHECK([types of arguments for select],
 [ac_cv_func_select_args],
 [for ac_arg234 in 'fd_set *' 'int *' 'void *'; do
@@ -1636,8 +1634,8 @@ AU_ALIAS([AM_FUNC_STRTOD], [AC_FUNC_STRTOD])
 # --
 AN_FUNCTION([strerror_r], [AC_FUNC_STRERROR_R])
 AC_DEFUN([AC_FUNC_STRERROR_R],
-[AC_CHECK_DECLS([strerror_r])
-AC_CHECK_FUNCS([strerror_r])
+[AC_CHECK_DECLS_ONCE([strerror_r])
+AC_CHECK_FUNCS_ONCE([strerror_r])
 AC_CACHE_CHECK([whether strerror_r returns char *],
 	   ac_cv_func_strerror_r_char_p,
[
@@ -1766,7 +1764,7 @@ AU_ALIAS([AC_STRCOLL], [AC_FUNC_STRCOLL])
 # AC_FUNC_UTIME_NULL
 # --
 AC_DEFUN([AC_FUNC_UTIME_NULL],
-[AC_CHECK_HEADERS_ONCE(utime.h)
+[AC_CHECK_HEADERS_ONCE([utime.h])
 AC_CACHE_CHECK(whether utime accepts a null argument, ac_cv_func_utime_null,
 [rm -f conftest.data; conftest.data
 # Sequent interprets utime(file, 0) to mean use start of epoch.  Wrong.
@@ -1804,8 +1802,8 @@ AN_FUNCTION([fork],  [AC_FUNC_FORK])
 AN_FUNCTION([vfork], [AC_FUNC_FORK])
 AC_DEFUN([AC_FUNC_FORK],
 [AC_REQUIRE([AC_TYPE_PID_T])dnl
-AC_CHECK_HEADERS(vfork.h)
-AC_CHECK_FUNCS(fork vfork)
+AC_CHECK_HEADERS_ONCE([vfork.h])
+AC_CHECK_FUNCS_ONCE([fork vfork])
 if test x$ac_cv_func_fork = xyes; then
   _AC_FUNC_FORK
 else
@@ -1988,12 +1986,12 @@ AU_ALIAS([AC_VFORK], [AC_FUNC_FORK])
 # Why the heck is that _doprnt does not define HAVE__DOPRNT???
 # That the logical name!
 AC_DEFUN([AC_FUNC_VPRINTF],
-[AC_CHECK_FUNCS(vprintf, [],
-[AC_CHECK_FUNC(_doprnt,
-	   [AC_DEFINE(HAVE_DOPRNT, 1,
+[AC_CHECK_FUNCS_ONCE([vprintf])
+AS_IF([test $ac_cv_func_vprintf = no],
+[AC_CHECK_FUNC([_doprnt],
+	   [AC_DEFINE([HAVE_DOPRNT], [1],
 			  [Define to 1 if you don't

[PATCH 2/6] AC_CHECK_HEADER/AC_CHECK_HEADERS: complete transition to compile tests.

2013-09-15 Thread Zack Weinberg

* lib/autoconf/headers.m4 (AC_CHECK_HEADER): Use _AC_CHECK_HEADER_COMPILE
  by default.  Continue to use _AC_CHECK_HEADER_PREPROC if fourth arg is '-'.
  (_AC_CHECK_HEADER_PREPROC): Issue a deprecation warning.
  (_AC_CHECK_HEADER_MONGREL, _AC_CHECK_HEADER_MONGREL_BODY): Remove.

* tests/c.at, tests/semantics.at: Update uses of AC_CHECK_HEADER(S).
* doc/autoconf.texi, NEWS: Document change.

Signed-off-by: Zack Weinberg za...@panix.com
---
 NEWS|   10 
 doc/autoconf.texi   |  106 -
 lib/autoconf/headers.m4 |  122 +++
 tests/c.at  |   28 ---
 tests/semantics.at  |   19 ---
 5 files changed, 121 insertions(+), 164 deletions(-)

diff --git a/NEWS b/NEWS
index 7003c44..5d6c657 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,16 @@ GNU Autoconf NEWS - User visible changes.
echo.  Macros AS_ECHO and AS_ECHO_N now expand unconditionally to
'printf %s\n' and 'printf %s'.
 
+** AC_CHECK_HEADER and AC_CHECK_HEADERS now default to doing only a
+   compilation test.  This completes the transition from preprocessor-
+   based header tests begun in Autoconf 2.56.
+
+   The double test that was the default since Autoconf 2.64 is no
+   longer available.  You can still request a preprocessor-only test
+   by specifying '-' as the fourth argument to either macro, but this
+   is now deprecated.  If you really need that behavior use
+   AC_PREPROC_IFELSE.
+
 ** Macros
 
 - New macro AC_C__GENERIC.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 4932067..0c489a3 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6264,26 +6264,21 @@ commands @var{action-if-found}, otherwise execute
 header file is available, consider using @code{AC_CHECK_HEADERS}
 instead.
 
-@var{includes} is decoded to determine the appropriate include
-directives.  If omitted or empty, @file{configure} will check for both header
-existence (with the preprocessor) and usability (with the compiler),
-using @code{AC_INCLUDES_DEFAULT} for the compile test.  If
-there is a discrepancy between the results, a warning is issued to the
-user, and the compiler results are favored (@pxref{Present But
-Cannot Be Compiled}).  In general, favoring the compiler results means
-that a header will be treated as not found even though the file exists,
-because you did not provide enough prerequisites.
+@var{includes} should be the appropriate @dfn{prerequisite} code, i.e.@:
+whatever might be required to appear above
+@samp{#include @var{header-file}} for it to compile without error.
+This can be anything, but will normally be additional @samp{#include}
+directives. If @var{includes} is omitted or empty, @file{configure} will
+use the contents of the macro @code{AC_INCLUDES_DEFAULT}.
+@xref{Default Includes}.
 
-Providing a non-empty @var{includes} argument allows the code to provide
-any prerequisites prior to including the header under test; it is common
-to use the argument @code{AC_INCLUDES_DEFAULT} (@pxref{Default
-Includes}).  With an explicit fourth argument, no preprocessor test is
-needed.  As a special case, an @var{includes} of exactly @samp{-}
-triggers the older preprocessor check, which merely determines existence
-of the file in the preprocessor search path; this should only be used as
-a last resort (it is safer to determine the actual prerequisites and
-perform a compiler check, or else use @code{AC_PREPROC_IFELSE} to make
-it obvious that only a preprocessor check is desired).
+This macro used to check only for the @emph{presence} of a header, not
+whether its contents were acceptable to the compiler.  Some older
+@command{configure} scripts rely on this behavior, so it is still
+available by specifying @samp{-} as @var{includes}.  This mechanism is
+deprecated as of Autoconf 2.70; situations where a preprocessor-only
+check is required should use @code{AC_PREPROC_IFELSE}.
+@xref{Running the Preprocessor}.
 
 This macro caches its result in the @code{ac_cv_header_@var{header-file}}
 variable, with characters not suitable for a variable name mapped to
@@ -6314,47 +6309,49 @@ variable, with characters not suitable for a variable name mapped to
 underscores.
 @end defmac
 
-Previous versions of Autoconf merely checked whether the header was
-accepted by the preprocessor.  This was changed because the old test was
-inappropriate for typical uses.  Headers are typically used to compile,
-not merely to preprocess, and the old behavior sometimes accepted
-headers that clashed at compile-time (@pxref{Present But Cannot Be
-Compiled}).  If you need to check whether a header is preprocessable,
-you can use @code{AC_PREPROC_IFELSE} (@pxref{Running the Preprocessor}).
+@defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})
+@acindex{CHECK_HEADERS_ONCE}
+@cvindex HAVE_@var{header}
+For each given system header file @var{header-file} in the
+blank-separated argument list that exists, define
+@code{HAVE_@var

[PATCH 1/6] * tests/local.at (AT_CHECK_M4): Support 'stderr' as fourth argument.

2013-09-15 Thread Zack Weinberg

Signed-off-by: Zack Weinberg za...@panix.com
---
 tests/local.at |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/local.at b/tests/local.at
index 97a1e1d..47501bf 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -113,13 +113,14 @@ m4_define([AT_CHECK_M4],
 [AT_CHECK([$1], [$2], [$3],
   m4_case([$4], [], [], [ignore], [ignore], [stderr]))
 m4_case([$4], [], [], [ignore], [],
-[AT_CHECK([[sed 's/^[^:]*m4[-.ex0-9]*: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
+[AT_CHECK([[mv stderr stderr-raw 
+   sed 's/^[^:]*m4[-.ex0-9]*: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
 	s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4[-.ex0-9]*: /m4:\1\2 /
 	s/: C\(annot open \)\([^`:]*\):/: c\1`\2'\'':/
 	s/: include:\( cannot open\)/:\1/
 	s/^autom4te: [^ ]*m4[.ex]* /autom4te: m4 /
 	s/ (E[A-Z]*)$//
-' stderr 2]], [0], [], [$4])])
+' stderr-raw 2]], [0], [], [$4])])
 ])
 
 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)


Re: [PATCH 4/6] Use AC_CHECK_HEADERS_ONCE for the tests done by AC_INCLUDES_DEFAULT.

2013-09-16 Thread Zack Weinberg

On 2013-09-14 12:42 PM, Zack Weinberg wrote:


  * lib/autoconf/headers.m4 (AC_CHECK_HEADERS_ONCE): Divide into a public
macro that AC_REQUIREs _AC_INCLUDES_DEFAULT_REQUIREMENTS, and ...
(_AC_CHECK_HEADERS_ONCE): ... a private macro, that doesn't.
(_AC_HEADERS_EXPANSION): Use $ac_includes_default, not
AC_INCLUDES_DEFAULT.
(_AC_INCLUDES_DEFAULT_REQUIREMENTS): Use AC_CHECK_HEADERS_ONCE.


I just noticed that this patch still has the dnl's inside the quotes. 
That's fixed in my tree now.


zw




Re: [PATCH 3/6] Modernize AC_INCLUDES_DEFAULT and friends.

2013-09-21 Thread Zack Weinberg
On Sat, Sep 21, 2013 at 9:29 AM, Eric Blake ebl...@redhat.com wrote:
 On 09/14/2013 10:22 AM, Zack Weinberg wrote:
...
(AC_HEADER_STDC, AC_UNISTD_H): AU_DEFUN to trigger
_AC_INCLUDES_DEFAULT_REQUIREMENTS if it hasn't already happened,
and do nothing else.
...
 Ah, I see what you did - you expanded to ac_dummy=AC_INCLUDES_DEFAULT
 rather than actually spelling out the internal macro name - it triggers
 the internal macro via AC_REQUIRES magic.  Interesting :)

Right.  (In case you're wondering, the AS_IF is to ensure that the
AC_REQUIRE expansion happens before the beginning of the
ac_dummy=... statement.)

Given that, do you still want patch 6?

I have made all the changes you requested (throughout the patch
series), and will go ahead and push once you answer this question. :)

zw



Re: [PATCH 3/6] Modernize AC_INCLUDES_DEFAULT and friends.

2013-09-23 Thread Zack Weinberg
On Mon, Sep 23, 2013 at 9:44 AM, Eric Blake ebl...@redhat.com wrote:
 Given that, do you still want patch 6?

 Yes, patch 6 is still worthwhile.

OK.  I have pushed the entire series now.

zw



Re: Turn on compiler warnings by default for AC_PROG_CC, AC_PROG_CXX AC_PROG_FC

2014-01-14 Thread Zack Weinberg
For GCC I would be quite hesitant to turn anything on beyond -Wall without
explicit buy-in from the project, but I like the idea of enabling -Wall by
default.


Re: Turn on compiler warnings by default for AC_PROG_CC, AC_PROG_CXX AC_PROG_FC

2014-01-17 Thread Zack Weinberg

On 2014-01-17 4:02 PM, David A. Wheeler wrote:

Zack Weinberg said:

For GCC I would be quite hesitant to turn anything on beyond -Wall
without explicit buy-in from the project, but I like the idea of
enabling -Wall by default.


I pretty sure that's what Dale Visser's patch does.  It says: +
-pedantic  % -Wall   dnl GCC

Dale Visser's patch does include a comment that says: +#   For the
GNU compiler it will be -Wall (and -ansi -pedantic) The result +#
is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by
default.

But I think this comment is no longer true. It appears to me that the
code is just trying to see if -pedantic *WORKS*, and if it does,
then using that as evidence that -Wall would work.


Oh, is that what -pedantic % -Wall means?  I had the impression it was 
going to try each one in isolation and include the subset that worked.


Despite the dire things the GCC manual says about -pedantic, it is not 
hard to write *new* code that is -pedantic clean, or -Wextra clean, etc; 
I would support an opt-in mechanism for enabling a much more aggressive 
set of warnings, and recommending its use in the manual for new 
projects.  But any such thing has a high probability of breaking *old* 
code, hence my earlier comments.  Also, as long as stock Autoconf checks 
are sloppy (e.g. AC_CHECK_FUNCS and its habit of blindly declaring 
everything as char foo();) we will need to distinguish warnings 
enabled for the *project* from warnings enabled for the *configure script*.


-ansi, however, should not be in there at all; it doesn't just turn on 
strict conformance mode, it turns on strict *C89* conformance mode, 
which is often wrong for new code.  And even nowadays, strict 
conformance mode in general tends to break system headers.


zw



Re: [PATCH] docs: mention that not all values can be exported

2014-09-29 Thread Zack Weinberg
On Sat, Sep 27, 2014 at 8:26 PM, Eric Blake ebl...@redhat.com wrote:
 There has been a LOT of news about bash's Shell Shock bug lately.
 Document some of the ramifications it has on portable scripting.

I think this is a good idea in the abstract, but I think it's maybe a
little too specific to this particular incident.  Can I suggest
instead

+Posix requires @command{export} to work with any arbitrary value for the
+contents of the variable being exported.  However, some shells have extensions
+that involve interpreting some values specially.  We currently know of only one
+case: all versions of Bash released prior to 27 September 2014 interpret
+an environment variable whose value begins with @code{() @{} as a shell
+function definition.  (This is the ``Shellshock'' bug, CVE-2014-6271; it was
+possible to exploit the parser and cause code to execute immediately upon
+shell startup.  Newer versions of Bash use special environment variable
+@emph{names} to implement the same feature.)



Re: [PATCH] AC_HEADER_MAJOR: port to glibc 2.25

2016-09-14 Thread Zack Weinberg
On Wed, Sep 14, 2016 at 9:26 AM, Eric Blake  wrote:
> glibc 2.25 is deprecating the namespace pollution of sys/types.h
> injecting major(), minor(), and makedev() into the compilation
> environment, with a warning that insists that users include
>  instead.  However, because the expansion of
> AC_HEADER_MAJOR didn't bother checking sys/sysmacros.h until
> after probing whether sys/types.h pollutes the namespace, it was
> not defining MAJOR_IN_SYSMACROS, with the result that code
> compiled with -Werror chokes on the deprecation warnings because
> it was not including sysmacros.h.
>
> In addition to fixing autoconf (which only benefits projects
> that rebuild configure after this fix is released), we can also
> give a hint to distros on how they can populate config.site with
> a cache variable to force pre-existing configure scripts without
> the updated macro to behave sanely in the presence of glibc 2.25.

Thanks for writing this patch.

> For this patch, I kept the status quo of assuming that if
> sys/sysmacros.h exists, then it probably defines major/minor/makedev;
> if you want me to rework the patch to explicitly check that this
> is the case, I can do that as well (probably best as a followup
> patch, in case downstreams want to backport one idea without the
> other).

glibc's sys/sysmacros.h _only_ defines major/minor/makedev.  What I'd
worry about is whether any other C library has a different header with
the same name; "sysmacros" is pretty generic.  I don't have any
evidence either way on that question.

> @@ -5977,6 +5977,27 @@ Particular Headers
>  @code{makedev}, but @file{sys/mkdev.h} does, define
>  @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
>  @code{MAJOR_IN_SYSMACROS}.

This part of the description should probably be adjusted to match what
the code does now.

> +To properly use any of these three functions, your code should contain
> +something like:

Also, I think "three functions" here is meant to refer to
major/minor/makedev, but it tripped me up the first time I read it.  I
suggest instead

   Detect the headers required to use @code{makedev}, @code{major}, and
   @code{minor}.  These functions may be defined by @file{sys/mkdev.h},
   @code{sys/sysmacros.h}, or @file{sys/types.h}.

   @code{AC_HEADER_MAJOR} defines @code{MAJOR_IN_MKDEV} if they are in
   @file{sys/mkdev.h}, or @code{MAJOR_IN_SYSMACROS} if they are in
   @file{sys/sysmacros.h.}.  If neither macro is defined, they are either
   in @file{sys/types.h} or they are unavailable.

   To portably use these functions, your code should contain something
   like

and then your @verbatim block.

(Should AC_HEADER_MAJOR maybe throw an error if none of the possible
headers we know about defines major/minor/makedev?  I believe this is
the case on MinGW, for instance.)

> +Note that glibc 2.25 issues a deprecation warning if these functions are
> +used from @file{sys/types.h} without also using @file{sys/sysmacros.h},
> +but that configure scripts built with versions of autoconf prior to 2.70
> +did not correctly define @code{MAJOR_IN_SYSMACROS} in that scenario; on
> +systems where that is a problem, you can use the workaround of priming
> +the configure cache by setting @code{ac_cv_header_sys_types_h_makedev}
> +to 'no', perhaps as part of a @file{config.site} site default file
> +(@pxref{Site Defaults}).

This is a really long sentence.  Also, "used from @file{sys/types.h}
without also using @file{sys/types.h}" is confusing, and since this is
the Autoconf manual, probably the paragraph should highlight the
affected Autoconf versions first.  Suggested:

   Note: Configure scripts built with Autoconf 2.69 or earlier will
   not detect a problem if @file{sys/types.h} contains definitions of
   @code{major}, @code{minor}, and/or @code{makedev} that trigger
   compiler warnings upon use.  This is known to occur with GNU libc
   2.25, where those definitions are being deprecated, to reduce
   namespace pollution.  If it is not practical to regenerate affected
   software's configure scripts with Autoconf 2.70, you can work around
   the problem by setting @samp{ac_cv_header_sys_types_h_makedev=no} in
   a @file{config.site} site default file (@pxref{Site Defaults}).


> +# Thanks to glibc 2.25, we need the following logic:
> +# If  compiles, assume it provides the macros.
> +# Otherwise, if  provides them, nothing further to do.
> +# Otherwise, if  exists, assume it provides the macros.

I think we should check sys/types.h last.  That will future-proof
against C libraries where these functions are in both sys/mkdev.h and
sys/types.h deciding to do the same deprecation that glibc has done.

zw



Re: [PATCH v2] AC_HEADER_MAJOR: port to glibc 2.25

2016-09-14 Thread Zack Weinberg
On Wed, Sep 14, 2016 at 3:00 PM, Eric Blake  wrote:
>
> Thanks for the wordsmithing help, and forcing me to think about
> mingw. This version updates some wording, and changes the macro
> to leave the relative order of mkdev.h vs. sysmacros.h checking
> unchanged (by merely weakining the sys/types.h check to no longer
> care whether the macros are present).

This version looks good to me.

zw



Re: [PATCH v2] AC_HEADER_MAJOR: port to glibc 2.25

2016-09-14 Thread Zack Weinberg
Doh, one small correction:

> +@verbatim
> +#include 
> +#ifdef MAJOR_IN_MKDEV
> +# include 
> +#elif MAJOR_IN_SYSMACROS
> +# include 
> +#endif
> +@end verbatim

That should be `#elif defined MAJOR_IN_SYSMACROS`.  This was
originally my mistake and I just realized it _was_ a mistake, sorry.

(also applies to a couple of places in your gnulib patches)

zw



[PATCH] _AS_REEXEC_WITH_SHELL: don’t use AS_EXIT.

2020-03-13 Thread Zack Weinberg
If _AS_REEXEC_WITH_SHELL fails to exec the selected “better” shell
interpreter, and that failure somehow doesn’t terminate the process,
it calls AS_EXIT([255]).  This expands to an invocation of as_fn_exit.
However, the definition of as_fn_exit goes into the M4SH-INIT-FN
diversion, whereas _AS_REEXEC_WITH_SHELL goes into the M4SH-SANITIZE
diversion, so as_fn_exit won’t be defined at the point of this use.
We can’t move the definition of as_fn_exit earlier, because we don’t
know that the shell supports shell functions until after we get to the
end of the M4SH-SANITIZE diversion.

This is only a theoretical bug because, as the comments say, “all the
known shells bail out after a failed exec.”  However, a shell that
doesn’t bail out will instead give the user a flood of nonsensical
error messages (starting with “as_fn_exit: not found” and then going
on to choke on the rest of the script) so I think we should fix it
anyway.  There shouldn’t be any problem with using a plain ‘exit’ at
this point; no traps are active yet, and we are exiting with an
explicit error code.

OK to commit?

zw

---
 lib/m4sugar/m4sh.m4 | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 92999f58..4af31517 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -294,7 +294,10 @@ exec $1 $as_opts "$as_myself" ${1+"$[@]"}
 # 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
-AS_EXIT([255])])# _AS_REEXEC_WITH_SHELL
+dnl AS_EXIT cannot be used here because as_fn_exit is not yet defined;
+dnl code inserted by AS_REQUIRE_SHELL_FN will appear _after_ this point.
+dnl We shouldn't have to worry about any traps being active at this point.
+exit 255])# _AS_REEXEC_WITH_SHELL
 
 
 # _AS_PREPARE
-- 
2.25.1




Re: [PATCH] Define $as_echo and $as_echo_n for backward compatibility.

2020-03-13 Thread Zack Weinberg
On Fri, Mar 13, 2020 at 3:13 PM Eric Blake  wrote:
>
> Unpatched bash 5.0 has a bug where calling $as_echo that contains \ can
> result in unintended globbing, where the behavior of the expansion is
> dependent on the contents of the current directory.  Nasty!

Yikes!  And not just unpatched 5.0.0, either...

$ bash --version
GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
$ touch %sn; bash -c 'cmd='\''printf %s\n'\''; $cmd test'
testn$

I don't see any practical workaround and I surely hope this gets fixed
*properly* soon in bash (that discussion you linked to doesn't seem
terribly promising, though).

> But I don't
> see a problem in providing the variable definition for back-compat
> reasons (that is, bash's bug doesn't affect this patch)

Makes sense.  Pushed.  Thanks for reviewing.

zw



[PATCH] Define $as_echo and $as_echo_n for backward compatibility.

2020-03-13 Thread Zack Weinberg
Commit 2b59b6f8a79b8bf77e178ff4e5aa0ede433d39cf removed the internal
shell variables $as_echo and $as_echo_n.  It turns out that these are
used by several widely-used third-party m4 files (notably both
gnulib-common.m4 from gnulib, and ax_pthread.m4 from the Autoconf
macro archive) as well as any number of existing configure.ac’s.

Restore these shell variables, unconditionally defining them to use
printf.  Issue -Wobsolete warnings if they are used, recommending the
use of AS_ECHO and AS_ECHO_N respectively.  Add a test which checks
both that they do work and that they trigger warnings.

OK for trunk?

zw

---
 NEWS|  6 +++-
 lib/m4sugar/m4sh.m4 | 28 ++---
 tests/m4sh.at   | 74 +
 3 files changed, 103 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 24aec0f6..3cb2876d 100644
--- a/NEWS
+++ b/NEWS
@@ -17,9 +17,13 @@ GNU Autoconf NEWS - User visible changes.
by autoreconf.
 
 ** Use of printf is now recommended instead of working around bugs in
-   echo.  Macros AS_ECHO and AS_ECHO_N now expand unconditionally to
+   echo.  The macros AS_ECHO and AS_ECHO_N now expand unconditionally to
'printf "%s\n"' and 'printf %s'.
 
+** Use of the undocumented internal shell variables $as_echo and
+   $as_echo_n now elicits a warning in the 'obsolete' category.
+   The macros AS_ECHO and AS_ECHO_N should be used instead.
+
 ** AC_CHECK_HEADER and AC_CHECK_HEADERS now default to doing only a
compilation test.  This completes the transition from preprocessor-
based header tests begun in Autoconf 2.56.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 4af31517..af286857 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -813,8 +813,11 @@ m4_defun_init([_AS_ECHO_LOG],
 # in a command substitution prints only the first character of the output
 # with ksh version M-11/16/88f on AIX 6.1; it needs to be reset by another
 # backquoted echo.
-m4_defun([_AS_ECHO_N_PREPARE],
-[ECHO_C= ECHO_N= ECHO_T=
+m4_defun([_AS_ECHO_N_PREPARE], [
+# Determine whether it's possible to make 'echo' print without a newline.
+# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
+# for compatibility with existing Makefiles.
+ECHO_C= ECHO_N= ECHO_T=
 case `echo -n x` in @%:@(
 -n*)
   case `echo 'xy\c'` in
@@ -826,6 +829,13 @@ case `echo -n x` in @%:@(
 *)
   ECHO_N='-n';;
 esac
+
+# For backward compatibility with old third-party macros, we provide
+# the shell variables $as_echo and $as_echo_n.  New code should use
+# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
+dnl The @@ prevents a spurious deprecation diagnostic.
+as_@@echo='printf %s\n'
+as_@@echo_n='printf %s'
 ])# _AS_ECHO_N_PREPARE
 
 
@@ -1032,16 +1042,26 @@ fi
 # Output WORD followed by a newline.  WORD must be a single shell word
 # (typically a quoted string).  The bytes of WORD are output as-is, even
 # if it starts with "-" or contains "\".
-m4_defun([AS_ECHO],
+m4_define([AS_ECHO],
 [printf "%s\n" $1])
 
+# Deprecation warning for the former internal shell variable $as_echo.
+m4_define([as_echo],
+[m4_warn([obsolete],
+   [$as_echo is obsolete; use AS_ECHO(["message"]) instead])as_@@echo])
+
 
 # AS_ECHO_N(WORD)
 # ---
 # Like AS_ECHO(WORD), except do not output the trailing newline.
-m4_defun([AS_ECHO_N],
+m4_define([AS_ECHO_N],
 [printf %s $1])
 
+# Deprecation warning for the former internal shell variable $as_echo_n.
+m4_define([as_echo_n],
+[m4_warn([obsolete],
+   [$as_echo_n is obsolete; use AS_ECHO_N(["message"]) instead])as_@@echo_n])
+
 
 # AS_TEST_X
 # -
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 16a0f168..9fd84558 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -557,6 +557,80 @@ AT_CHECK([$CONFIG_SHELL ./script])
 
 AT_CLEANUP
 
+# Obsolete shell variables with the same functionality as above.
+AT_SETUP([obsolete $as@@_echo and $as@@_echo_n])
+AT_KEYWORDS([m4sh])
+
+AT_DATA_M4SH([script.as],
+[[AS_INIT
+AS_REQUIRE([_AS_ECHO_N_PREPARE])
+
+m4_define([ECHO_TEST],
+[echo=`$as_echo '$1'`
+test "X$echo" = 'X$1' ||
+  echo "\$as@@_echo '$1' outputs '$echo'" >&2
+
+echo=`$as_echo_n '$1'`
+test "X$echo" = 'X$1' ||
+  echo "\$as@@_echo_n '$1' outputs '$echo'" >&2])
+
+ECHO_TEST([-])
+ECHO_TEST([--])
+ECHO_TEST([---...---])
+ECHO_TEST([ ])
+ECHO_TEST([-e])
+ECHO_TEST([-E])
+ECHO_TEST([-n])
+ECHO_TEST([-n -n])
+ECHO_TEST([-e -n])
+ECHO_TEST([ab\ncd])
+ECHO_TEST([abcd\c])
+ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
+ECHO_TEST([ab
+cd
+e])
+ECHO_TEST([
+ ])
+ECHO_TEST([
+\c])
+AS_EXIT(0)
+]])
+
+AT_CHECK_M4SH([-Wobsolete], 0, [],
+[[script.as:13: warning: $as@@_echo is obsolete; use 
AS@@_ECHO(["message"]) instead
+script.as:13: warning: $as@@_echo_n is obsolete; use 
AS@@_ECHO_N(["message"]) instead
+script.as:14: warning: $as@@_echo is obsolete; use AS@@_ECHO(["message"]) 
instead
+script.as:14: warning: $as@@_echo_n is obsolete; use 
AS@@_ECHO_N(["message"]) instead
+script.as:15: 

[PATCH 1/3] Look harder for a shell whose -n is known to work.

2020-03-25 Thread Zack Weinberg
The test suite was insisting on using /bin/sh -n for syntax checking,
which meant that if /bin/sh wasn’t one of the short list of shells
whose -n is known to work, we would skip all of the syntax-check
tests, even if some other shell was available that would work.

Instead do like _AS_DETECT_BETTER_SHELL, and loop over possible
shells, starting with $SHELL and going on to a hardwired list of
known-good possibilities.  The result is written to the substitution
variable @SHELL_N@ and the testsuite uses that.

(Should we invoke AC_PATH_PROG on the result of the search if it’s not
already absolute?)

* configure.ac: Search for a shell whose -n mode is known to
work, instead of just checking /bin/sh.  Set @SHELL_N@ to
what we find.
* tests/atlocal.in: Propagate @SHELL_N@ to testsuite.
* tests/local.at (AT_CHECK_SHELL_SYNTAX): Use $SHELL_N instead
of hardcoding /bin/sh.  Update test for usable shell -n.
(AT_CHECK_AUTOCONF): Update test for usable shell -n.
* tests/tools.at: Update test for usable shell -n.
---
 configure.ac | 39 +--
 tests/atlocal.in |  2 +-
 tests/local.at   |  6 +++---
 tests/tools.at   |  2 +-
 4 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8ff9f729..e9f0da92 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,9 +35,9 @@ AC_SUBST([RELEASE_YEAR])
 
 AB_INIT
 
-# We use '/bin/sh -n script' to check that there are no syntax errors
-# in the scripts.  Although incredible, there are /bin/sh that go into
-# endless loops with '-n', e.g., SunOS's:
+# We use 'sh -n script' to check that there are no syntax errors
+# in the scripts.  Although incredible, there are sh implementations
+# that go into endless loops with '-n', e.g., SunOS's:
 #
 #   $ uname -a
 #   SunOS ondine 4.1.3 2 sun4m unknown
@@ -52,27 +52,38 @@ AB_INIT
 #   $ time sh -nx endless.sh
 #   ^Csh -nx endless.sh  3,67s user 0,03s system 63% cpu 5,868 total
 #
-# Also, some implementations of /bin/sh (e.g., Solaris 8) are s slow
+# Also, some implementations (e.g., Solaris 8) are s slow
 # that they are unusable on large scripts like our testsuite.
+#
+# So we must identify a shell whose -n can safely be used.
 
-# So before using '/bin/sh -n' to check our scripts, we first check
-# that '/bin/sh -n' is known to not have these problems.
-
-AC_CACHE_CHECK([whether /bin/sh -n is known to work], [ac_cv_sh_n_works],
-[if (
+AC_CACHE_CHECK([for a shell whose -n mode is known to work],
+   [ac_cv_sh_working_n],
+[ac_cv_sh_working_n=none
+# Start by trying the shell that autoconf decided to use for this script,
+# follow with a hardwired list of shells that are known to work and can
+# be identified as such, starting with the ones with the fewest
+# syntactic extensions.  Unfortunately, several shells that are also
+# known to work can't be easily identified (e.g. BSD sh, dash).
+# Try ksh93, which is often buggy, and plain ksh and sh last.
+for cand_sh in "$SHELL" pdksh bash zsh ksh93 ksh sh
+do
+  if (
 unset BASH_VERSION ZSH_VERSION
-/bin/sh -c '
+"$cand_sh" -c '
   test ${BASH_VERSION+y} || # Bash
   test ${KSH_VERSION+y} || # pdksh
   test ${ZSH_VERSION+y} || # zsh
   test -n "${.sh.version}" # ksh93; put this last since its syntax is dodgy
 '
   ) 2>/dev/null
-then ac_cv_sh_n_works=yes
-else ac_cv_sh_n_works=no
-fi
+  then
+ac_cv_sh_working_n="$cand_sh"
+break
+  fi
+done
 ])
-AC_SUBST([ac_cv_sh_n_works])
+AC_SUBST([SHELL_N], [$ac_cv_sh_working_n])
 
 AC_MSG_CHECKING([for characters that cannot appear in file names])
 AC_CACHE_VAL([ac_cv_unsupported_fs_chars],
diff --git a/tests/atlocal.in b/tests/atlocal.in
index ec2a4167..079e35c6 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -24,7 +24,7 @@ EGREP='@EGREP@'
 SED='@SED@'
 
 # We need to know if sh -n is ok.
-ac_cv_sh_n_works='@ac_cv_sh_n_works@'
+SHELL_N='@SHELL_N@'
 
 # Check whether the underlying system can manage some unusual
 # symbols in file names.
diff --git a/tests/local.at b/tests/local.at
index 88a24e77..8496f55c 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -50,8 +50,8 @@ AT_CHECK([$at_diff "$1" "$2"])
 # otherwise, do nothing.  ksh93 -n also spits outs loads of warnings
 # about older constructs, but we don't care about the warnings.
 m4_define([AT_CHECK_SHELL_SYNTAX],
-[AT_SKIP_IF([test "$ac_cv_sh_n_works" != yes])
-AT_CHECK([/bin/sh -n $1], [], [], [ignore])])
+[AT_SKIP_IF([test "$SHELL_N" = none])
+AT_CHECK(["$SHELL_N" -n $1], [], [], [ignore])])
 
 m4_define([AT_CHECK_PERL_SYNTAX],
 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c 
"$abs_top_builddir"/bin/$1],
@@ -216,7 +216,7 @@ cp "$abs_top_srcdir/tests/statesave.m4" aclocal.m4
 # were running too fast.
 m4_define([AT_CHECK_AUTOCONF],
 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
-if test -s configure && test "$ac_cv_sh_n_works" = yes; then
+if test -s configure && test 

[PATCH 2/3] AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally.

2020-03-25 Thread Zack Weinberg
While investigating something else, I noticed that AC_REPLACE_FUNCS
calls _AH_CHECK_FUNC and AC_LIBSOURCE in the success branch of an
AC_CHECK_FUNC.  This doesn’t work; both of those are marker macros
that need to be expanded unconditionally at m4 time so that traces
(placed by autoheader and automake, respectively) will fire.  In order
to fix this while keeping the code readable, I would up doing a major
refactor.  There are now four internal macros implementing AC_REPLACE_FUNCS.

_AC_REPLACE_FUNC_U is called unconditionally for every shell word in
the list passed to AC_REPLACE_FUNCS, and does _AH_CHECK_FUNC +
AC_LIBSOURCE if it can, or issues a warning if it can’t.  (It could
make sense to make this a public function, if we think shell variables
in the AC_REPLACE_FUNCS list need to be supported long-term.  I dunno
if there’s a use case that can’t be handled by AC_REPLACE_FUNCS inside
a shell conditional just as well.)

_AC_REPLACE_FUNC_L and _AC_REPLACE_FUNC_NL implement the actual test
performed for each function to be replaced; the difference is that _L
(for literal) can only be used on a function whose name is known at m4
expansion time, _NL (nonliteral) works regardless.  _AC_REPLACE_FUNCS,
which already existed, handles looping either at m4 time or shell time
as appropriate.  AC_REPLACE_FUNCS remains a thin wrapper that runs
_AC_REPLACE_FUNCS(m4_flatten([$1])).

The _bulk_ of the patch is changes to the testsuite so that it notices
the original bug.  Specifically, AT_CHECK_AUTOHEADER now takes an
argument which is a whitespace-separated list of preprocessor macro
names that ought to appear in the generated config.h.in.  This can be
set to ‘ignore’ to skip the test, and unfortunately that’s what the
“trivial” per-macro tests have to do (AT_CHECK_MACRO and friends), so
coverage is not ideal, but it’s better than what we had.  Also,
AT_CHECK_M4 now normalizes the backtrace lines that appear in the
output of an AC_DIAGNOSE, e.g.

configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete.
configure.ac:6: You should run autoupdate.
../../lib/autoconf/lang.m4:125: AC_LANG_SAVE is expanded from...
configure.ac:6: the top level

becomes

configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete.
configure.ac:6: You should run autoupdate.
lang.m4: AC_LANG_SAVE is expanded from...
configure.ac:6: the top level

This allows us to write tests for these diagnostics that don’t depend
on the relationship between the source and build directories, and
won’t break when unrelated patches change the line number of a macro
definition.

* lib/autoconf/functions.m4 (AC_REPLACE_FUNCS, _AC_REPLACE_FUNCS)
(_AC_REPLACE_FUNC): Refactor into AC_REPLACE_FUNCS,
_AC_REPLACE_FUNCS, _AC_REPLACE_FUNC_U, _AC_REPLACE_FUNC_L,
_AC_REPLACE_FUNC_NL.  Ensure that _AH_CHECK_FUNC and
AC_LIBSOURCE are invoked unconditionally at m4 expansion
time for each literal function name in the argument to
AC_CHECK_FUNCS.  Issue warnings about non-literal names.

* tests/local.at (AT_CHECK_M4): Normalize backtrace lines from
the output of AC_DIAGNOSE / m4_warn.
(AT_CHECK_AUTOHEADER): Add arg EXPECTED-TMPLS
giving a list of preprocessor macro names that should appear
in the generated config.h.in.  Use AT_CHECK_M4 to invoke autoheader.
(_AT_CHECK_AC_MACRO, AT_CHECK_MACRO, AT_CHECK_AU_MACRO):
Update uses of AT_CHECK_AUTOHEADER.
* tests/fortran.at, tests/semantics.at, tests/tools.at
* tests/torture.at: Update all uses of AT_CHECK_AUTOHEADER.

* tests/semantics.at (AC_REPLACE_FUNCS test): Make somewhat
more thorough, using new functionality of AT_CHECK_M4 and
AT_CHECK_AUTOHEADER.

Signed-off-by: Zack Weinberg 
---
 lib/autoconf/functions.m4 | 39 ++-
 tests/fortran.at  | 40 +---
 tests/local.at| 63 +++
 tests/semantics.at| 79 +++
 tests/tools.at| 10 ++---
 tests/torture.at  | 13 ---
 6 files changed, 196 insertions(+), 48 deletions(-)

diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index 608641b3..44730096 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -141,14 +141,35 @@ do
 done])])
 
 
-# _AC_REPLACE_FUNC(FUNCTION)
-# --
+# _AC_REPLACE_FUNC_U(FUNCTION)
+# 
+# Perform the actions that need to be performed unconditionally
+# for every FUNCTION that *could* be replaced by AC_REPLACE_FUNCS.
+m4_define([_AC_REPLACE_FUNC_U],
+[AS_LITERAL_WORD_IF([$1],
+  [_AH_CHECK_FUNC([$1])AC_LIBSOURCE([$1.c])],
+  [AC_DIAGNOSE([syntax], [AC_REPLACE_FUNCS($1): you should use literals])])])
+
+# _AC_REPLACE_FUNC_L(FUNCTION)
+# 
 # If FUNCTION exists, define HAVE_FUNCTION; else add FUNCTION.c
 # to the list of library

[PATCH 3/3] Consistently expand macros in whitespace-separated lists.

2020-03-25 Thread Zack Weinberg
Several of the most commonly used Autoconf macros (starting with
AC_CHECK_FUNCS and AC_CHECK_HEADERS) take a whitespace-separated list
of symbols as their primary argument.  It would abstractly be best if
this list were _not_ subject to M4 macro expansion, in case there’s a
collision between a M4 macro name and something to be looked for.
However, we have historically not been careful about this, and there’s
been reports of configure scripts using ‘dnl’ to write comments inside
the list.  The AS_LITERAL_IF optimizations added to AC_CHECK_FUNCS and
AC_CHECK_HEADERS since 2.69 broke some of those scripts with bizarre
shell syntax errors.

Also, the macro expansion behavior is not consistent among all of the
macros that take whitespace-separated lists, nor is it consistent
between autoconf and autoheader.

Address this by introducing a new m4sugar macro, currently called
‘m4_validate_w’ (I’m open to suggestions for better names).  Here’s
its documentation comment:

| m4_validate_w(STRING): Expands into m4_normalize(m4_expand([STRING])),
| but if that is not the same as just m4_normalize([STRING]),
| issue a warning.

The text of the warning is

| configure.ac:N: warning: whitespace-separated-list contains macros;
| configure.ac:N: in a future version of Autoconf they will not be expanded

If the unexpanded form of the string contains the token ‘dnl’ then
there’s an additional line:

| configure.ac:N: note: ‘dnl’ is a macro

All of the public macros that take a whitespace-separated list of
symbols are changed to pass that argument through m4_validate_w before
doing anything else with it, and the test suite is updated to verify
consistent behavior for every last one of them.

This addresses Savannah issues #110210 and #110211, and the harmless
but annoying autoheader behavior described at
https://lists.gnu.org/archive/html/bug-autoconf/2018-02/msg5.html .

In order to avoid expanding relatively expensive m4sugar macros
multiple times per top-level macro invocation, several of the affected
Autoconf macros are restructured along the same lines as I did for
AC_REPLACE_FUNCS in the previous patch.

* lib/m4sugar/m4sugar.m4 (m4_validate_w): New macro.
* lib/autoconf/functions.m4 (AC_CHECK_FUNCS, AC_CHECK_FUNCS_ONCE)
  (AC_REPLACE_FUNCS)
* lib/autoconf/general.m4 (AC_CONFIG_MACRO_DIRS, AC_CHECK_FILES)
* lib/autoconf/headers.m4 (AC_CHECK_HEADERS, AC_CHECK_HEADERS_ONCE)
* lib/autoconf/status.m4 (AC_CONFIG_SUBDIRS): Pass $1 through
  m4_validate_w before use.

* lib/autoconf/headers.m4 (AC_CHECK_HEADERS): Refactor with helpers
  _AC_CHECK_HEADERS_ONE_U, _AC_CHECK_HEADERS_ONE_S, _AC_CHECK_HEADERS_ONE_C.
  (AC_CHECK_HEADERS_ONCE): Eliminate _AC_CHECK_HEADERS_ONCE.
  (AC_CHECK_INCLUDES_DEFAULT): Don’t use _AC_CHECK_HEADERS_ONCE.

* lib/autoconf/functions.m4 (AC_CHECK_FUNCS): Refactor with helpers
  _AC_CHECK_FUNCS_ONE_U, _AC_CHECK_FUNCS_ONE_S, _AC_CHECK_FUNCS_ONE_C.

* lib/autoconf/status.m4 (_AC_CONFIG_SUBDIRS): No need to use m4_normalize.

* tests/semantics.at: Add tests for expansion of M4 macros in
  whitespace-separated list arguments to all of the above.
---
 NEWS  |  16 +++
 lib/autoconf/functions.m4 |  47 +--
 lib/autoconf/general.m4   |   6 +-
 lib/autoconf/headers.m4   |  55 +---
 lib/autoconf/status.m4|   9 +-
 lib/m4sugar/m4sugar.m4|  21 
 tests/semantics.at| 259 +-
 7 files changed, 378 insertions(+), 35 deletions(-)

diff --git a/NEWS b/NEWS
index 3cb2876d..fc0fef80 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,22 @@ GNU Autoconf NEWS - User visible changes.
account.  This makes it possible to use AC_DEFINE for secondary
headers without duplicating the template in the main config header.
 
+** Macros that take whitespace-separated lists as arguments
+   now always expand macros within those arguments.  (Formerly, these
+   macros would *usually* expand those arguments, but the behavior was
+   not reliable nor was it consistent between autoconf and autoheader.)
+
+   Macro expansion within these arguments is deprecated; if expansion
+   changes the list, a warning in the 'obsolete' category will be
+   emitted.  Note that 'dnl' is a macro.  Putting 'dnl' comments
+   inside any argument to an Autoconf macro is, in general, only
+   supported when that argument takes more Autoconf code (e.g. the
+   ACTION-IF-TRUE argument to AC_COMPILE_IFELSE).
+
+   The affected macros are AC_CHECK_FILES, AC_CHECK_FUNCS,
+   AC_CHECK_FUNCS_ONCE, AC_CHECK_HEADERS, AC_CHECK_HEADERS_ONCE,
+   AC_CONFIG_MACRO_DIRS, AC_CONFIG_SUBDIRS, and AC_REPLACE_FUNCS.
+
 ** Macros
 
 - New macro AC_C__GENERIC.
diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index 44730096..645a7c60 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -78,6 +78,34 @@ m4_define([_AH_CHECK_FUNC],
 [AH_TEMPLATE(AS_TR_CPP([HAVE_$1]),
   [Define to 1 if you have the `$1' function.])])
 
+# _AC_CHECK_FUNCS_ONE_U(FUNCTION)
+# 

Re: [PATCH] m4sh: prefer bash over sh

2020-03-23 Thread Zack Weinberg
On Mon, Mar 23, 2020 at 9:34 AM Ross Burton  wrote:
> _AS_DETECT_BETTER_SHELL looks for a good shell to use, and tries to look for
> 'sh' before 'bash'.  Whilst for many systems sh is a symlink to bash,
> there are many where sh is a symlink to a more minimal sh implementation.
>
> For example, Debian by default has /bin/sh -> /bin/dash: dash is a faster
> shell to start (which makes a notable difference to boot speed) but is not
> as fast as bash at executing long scripts (and configure scripts are not
> known for their conciseness).

Ignoring what I just said in the other thread, a patch like this would
be a lot more compelling if it came with some performance
measurements.  Do you have time to find out whether bash is, in fact,
faster at executing long configure scripts than dash?  I would suggest
measuring it like this: find a bunch of configure scripts of varying
lengths (the minimal configure script with autoconf 2.69 is 2800 lines
long, and the GCC source tree contains 35 different configure scripts
of lengths ranging from 4000 to 83,000 lines, so that might be a good
start, but it'd be nice to have at least one short and one long script
written by a different set of developers too).  Run each one under
'time', 11 times in a row, with both bash and dash.  Throw out the
numbers for the very first run with each shell, and send us a CSV file
containing the reported wall, user, and system times and the name *and
the line count* for all the other runs of each script with each shell.
If you feel like doing statistics on those numbers, go for it, but I
can do it if you'd rather not.  If you have access to more than one
CPU architecture (as physical hardware) that would also be an
interesting independent variable.

zw



Re: [PATCH] Swallow m4traces that have no file/line number

2020-09-04 Thread Zack Weinberg
I would like to get this bug fixed for autoconf 2.70, but the trouble
is I have no idea how to reproduce the problem on my computer.  The
various old reports you originally linked to, all seem to involve
filesystem-level bugs on MacOS, which I don't have convenient access
to, or with archaic versions of the Linux CIFS driver.

You wrote:

> The root cause is m4 traces without a file/line number shown.
> So instead of something like:
>
>   m4trace:configure.ac:48: -1- ...
>
> you have something like:
>
>  m4trace: -1- ...
>
> In the scenarios I ran into, this is due to some error that throws m4 out.

Are you aware of a way to reproduce this effect on an ordinary local
file system?  If so, can you send me a minimal configure.ac, plus any
other necessary files, and instructions for using them to make m4 do
this?

zw



Re: [PATCH] Fortran Cray pointer macro support

2020-10-06 Thread Zack Weinberg
On Tue, Oct 6, 2020 at 12:24 PM Marshall Ward  wrote:
> This patch adds a macro, AC_FC_CRAY_POINTER, which tests if the Fortran
> compiler supports Cray pointers.

This seems like a reasonable addition to me. Would anyone with Fortran
experience care to comment? I have never properly learned Fortran.

I think we would prefer the macro to be named AC_FC_CRAY_POINTERS, and
I wonder whether there should be a _F77_ variant -- Cray pointers have
been around since the 80s, haven't they?

We are in a feature freeze right now, because we're trying to get the
long-overdue 2.70 release finished; the earliest your patch could be
accepted is for the 2.71 release. Also, I don't recognize your name as
a prior contributor to Autoconf. This is more code than we can accept
without a copyright assignment. If you've already gone through that
process, or your contribution would be covered by your employer's
assignment, just let me know; otherwise you need to follow the
instructions on the form at
https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/Copyright/request-assign.future
. It is best to do this as soon as possible, because sometimes the FSF
takes a long time to process the paperwork.

(The need for a copyright assignment also means I haven't reviewed
your code in detail.)

zw



Re: AS_IF

2020-10-06 Thread Zack Weinberg
On Tue, Oct 6, 2020 at 5:57 PM Bruno Haible  wrote:
> Paul Eggert wrote in
> :
> > > AFAICS, this is relevant for code written directly into configure.ac. But
> > > inside an AC_DEFUN it is irrelevant, because required macros are hoisted
> > > before the body of the AC_DEFUN anyway.
...
> > But now that you mention it, AS_IF isn't needed here and I installed the
> > attached further patch. Also, to help prevent others from making a similar
> > mistake, I plan to reword the Autoconf NEWS item to start with something 
> > like
> > "Autoconf macros that use AC_REQUIRE are not safe to use in hand-written 
> > shell
> > control-flow constructs that appear outside of macros defined by AC_DEFUN."
>
> Thanks. But if you, Paul, make an incorrect assumption about what AS_IF really
> does, how many more users (who read only the documentation) will make the same
> mistake? I therefore think the documentation should be enhanced to avoid this
> misinterpretation.

I agree that this should be clarified; I just had the same
conversation in another thread. I'm not sure we should say AS_IF/CASE
are equivalent to plain shell if/case inside an AC_DEFUN; they do do
more than just make the m4 expansion stack not be empty.

Also, why is AS_FOR not documented? Maybe, instead of avoiding
mentioning it in NEWS, it should be documented?

zw



Re: [PATCH] general.m4: fix AC_INIT with unquoted bug-report field

2020-10-13 Thread Zack Weinberg
On Tue, Oct 13, 2020 at 3:55 PM Ross Burton  wrote:
>
> The bug report field is passed unquoted to m4_define which causes
> problems if it contains values such as ',' (as seen in gmp).
>
> Ensure that the value is correctly quoted to solve this.

Thanks for the patch.  FYI, before committing it I want to write some
tests for this problem and also double-check that there aren't any
other instances of this mistake in this rather complicated macro.  I
probably won't have time to do that until next week, because I've got
a deadline for the day job coming up.

zw



Re: AS_IF

2020-10-12 Thread Zack Weinberg
On Mon, Oct 12, 2020 at 3:01 AM Paul Eggert  wrote:
> On 10/6/20 5:52 PM, Zack Weinberg wrote:
> > I'm not sure we should say AS_IF/CASE
> > are equivalent to plain shell if/case inside an AC_DEFUN; they do do
> > more than just make the m4 expansion stack not be empty.
>
> Yes, that goes a bit too far. I installed the attached doc patch to Savannah
> Autoconf master to try to clarify things a bit. I developed this patch before
> seeing Bruno's, but it should address the same issues (plus a few more, like
> portability of Posix case syntax).

Looks good, thanks.

> AS_FOR is kind of a mess. I wouldn't document it the way it is. Perhaps it 
> could
> be cleaned up in some future Autoconf version.

Oh, yeah, I see what you mean now.  I didn't actually read the
definition of AS_FOR before writing that NEWS entry.

zw



[PATCH 1/2 COMMITTED] Fix regressions when using the C++ compiler to perform tests.

2020-10-10 Thread Zack Weinberg
The Debian project has done an archive rebuild using autoconf 2.69c,
which found several serious regressions from 2.69 where test programs
used to be accepted by a C++ compiler, but are now rejected.  Part of
the problem is that newer C++ compilers are more likely to reject
“traditional” sloppy C, but part of it is that bug fixes since 2.69
did not consider the possibility of test macros being used with
AC_LANG([C++]) in effect.

I’m still working on test suite improvements that will catch these
regressions in the future, but I don’t see any reason to delay the
actual bugfixes.  (I’ve gotten far enough on the test suite changes
that I know they _will_ catch the bugs.)

* NEWS: Document that AC_FUNC_STRERROR_R no longer tries to detect a
  strerror_r that exists in the C library but isn’t declared by string.h.

* lib/autoconf/c.m4
  (AC_LANG_CALL(C++)): New macro.  Use a more robust technique for
  avoiding a type conflict with any intrinsic prototype.
  (AC_LANG_CALL(C)): Remove #ifdef __cplusplus, this macro is no longer
  used to generate C++ code.

* lib/autoconf/functions.m4
  (AC_FUNC_CLOSEDIR_VOID): Rely on  to declare closedir.
  Simplify test program.  Use AC_COMPILE_IFELSE, not AC_RUN_IFELSE.
  (_AC_FUNC_MALLOC_IF, _AC_FUNC_REALLOC_IF): Use void *, not char *,
  for variable holding a value returned by malloc/realloc respectively.
  (AC_FUNC_STRERROR_R): Don’t AC_CHECK_FUNCS_ONCE strerror_r.
  AC_DEFINE HAVE_STRERROR_R if and only if we are also going to define
  HAVE_DECL_STRERROR_R.  Remove AC_RUN_IFELSE fallback when strerror_r
  is not declared.

* lib/autoconf/headers.m4 (AC_USG): Use "", not 0, for the first
  argument to rindex.
---
 NEWS  | 10 ++
 lib/autoconf/c.m4 | 18 --
 lib/autoconf/functions.m4 | 71 +--
 lib/autoconf/headers.m4   |  2 +-
 4 files changed, 56 insertions(+), 45 deletions(-)

diff --git a/NEWS b/NEWS
index 55e938b3..be82eab9 100644
--- a/NEWS
+++ b/NEWS
@@ -124,6 +124,16 @@ GNU Autoconf NEWS - User visible changes.
   support for Solaris 2.4.  Most programs will want to avoid ‘vfork’
   on this OS because of this bug.
 
+*** AC_FUNC_STRERROR_R assumes strerror_r is unavailable if it’s not declared.
+
+  The fallback technique it used to probe strerror_r’s return type
+  when the function was present in the C library, but not declared by
+  , was fragile and did not work at all when cross-compiling.
+  The systems where this fallback was necessary were all obsolete.
+
+  Programs that use AC_FUNC_STRERROR_R should make sure to test the
+  preprocessor macro HAVE_DECL_STRERROR_R before using strerror_r at all.
+
 ** New features
 
 *** Configure scripts now support a ‘--runstatedir’ option.
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index be5e4148..de40b8ca 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -127,9 +127,6 @@ m4_if([$2], [main], ,
 [/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
 char $2 ();])], [return $2 ();])])
 
 
@@ -240,6 +237,21 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 ])
 
 
+# AC_LANG_CALL(C++)(PROLOGUE, FUNCTION)
+# -
+m4_define([AC_LANG_CALL(C++)],
+[AC_LANG_PROGRAM([[$1
+// We do not know the function signature of the real $2.
+// Declare it in a namespace so the compiler doesn't recognize it
+// (with, most likely, a clashing prototype); the 'extern "C"' will
+// hide the namespace from the linker, so it will still look for the
+// real (global) $2.
+namespace conftest {
+  extern "C" void $2 ();
+}]],
+[[conftest::$2 (); return 0;]])])
+
+
 # AC_LANG_CPLUSPLUS
 # -
 AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])
diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index aa560a63..4598b408 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -509,25 +509,23 @@ fi
 # AC_FUNC_CLOSEDIR_VOID
 # -
 # Check whether closedir returns void, and #define CLOSEDIR_VOID in
-# that case.
+# that case.  Note: the test program *fails* to compile when closedir
+# returns void.
 AC_DEFUN([AC_FUNC_CLOSEDIR_VOID],
 [AC_REQUIRE([AC_HEADER_DIRENT])dnl
 AC_CACHE_CHECK([whether closedir returns void],
   [ac_cv_func_closedir_void],
-[AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <$ac_header_dirent>
-#ifndef __cplusplus
-int closedir ();
-#endif
-],
-   [[return closedir (opendir (".")) != 0;]])],
+]], [[
+  return closedir(0);
+]])],
   [ac_cv_func_closedir_void=no],
-  [ac_cv_func_closedir_void=yes],
   [ac_cv_func_closedir_void=yes])])
 if test $ac_cv_func_closedir_void = yes; then
   AC_DEFINE(CLOSEDIR_VOID, 1,
[Define to 1 if the `closedir' function 

[PATCH 2/2 RFC] Improve handling of missing aux scripts.

2020-10-10 Thread Zack Weinberg
Another regression identified by the Debian archive rebuild was that
more macros require the presence of config.sub and config.guess now.
‘autoreconf --install’ doesn’t install these itself, it relies on
‘automake --add-missing’ to do that; so, packages that don’t use
Automake will fail at the configure stage after configure is
regenerated.  To make matters worse, AC_CONFIG_AUX_DIRS assumes that
everyone who needs config.sub and config.guess also needs install-sh,
so in about half of the affected packages, the failure manifested as a
complaint about install-sh being missing -- technically true but
adding install-sh wouldn’t have resolved the problem by itself.

We *could* make ‘autoreconf --install’ add config.sub, config.guess,
and install-sh itself when necessary, but then we’d have to ship those
files and we’d have to worry about them being out of sync with
automake’s copies.  And people with hand-written Makefiles might not
realize they need to add them to ‘make dist’, so they would ship
broken tarballs.  I haven’t taken that step yet.

What this patch does do is overhaul the AC_CONFIG_AUX_DIR(S) mechanism
so that a configure script knows the complete set of aux scripts that
were AC_REQUIRE_AUX_FILE’d for it, and checks for the existence of all
of them.  Thus, this configure script

AC_INIT([test], [1.0])
AC_FUNC_MALLOC
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT

if run in a directory not containing config.guess or config.sub, now
prints an accurate error message

configure: error: cannot find required auxiliary files: config.guess 
config.sub

instead of the misleading

configure: error: cannot find install-sh, install.sh, or shtool in "." 
"./.." "./../.."

I also made autoreconf trace AC_REQUIRE_AUX_FILE and detect missing
aux files, so that one gets an error at autoreconf time, where it’s
more likely to be caught by maintainers.  (It is not currently
practical to make autoconf itself issue this error message, because of
how the autoconf wrapper script is different from all the other
wrapper scripts.  Also, autoreconf runs automake *after* autoconf, so
we’d get spurious errors from packages that do use automake.)  And I
documented the expanded need for config.sub and config.guess in NEWS
as well as the manual.

A side-effect: it doesn’t make sense for AC_CONFIG_SUBDIRS to demand
the presence of Cygnus configure in the aux dir, on the off-chance
that one of the subdirectories *might* be using it -- I have no idea
where someone would even get a copy of that nowadays -- so I dropped
that feature.  I rather suspect nobody has needed it in over a decade.

Unlike the previous patch, this one has not been pushed.  I would
appreciate comments on the general approach, and on whether we
_should_ teach autoreconf to install config.sub, config.guess, and/or
install-sh itself.  I would also appreciate someone carefully going
over the M4 quotation in the changed macros, I'm not sure it's right.

zw

* NEWS: Document expanded need for config.sub and config.guess.
  Document removed support for Cygnus configure in subdirectories.

* doc/autoconf.texi: Clarify exactly when install-sh, config.sub,
  and/or config.guess are required.  Document canonical online sources
  for these scripts.  Revise documentation of AC_CONFIG_AUX_DIR and
  AC_REQUIRE_AUX_FILE.  Minor improvements to documentation of
  AC_CONFIG_SRCDIR.  Remove mentions of Cygnus configure in
  subdirectories.

* bin/autoreconf.in (find_missing_aux_files): New sub.
  (autoreconf_current_directory): Trace AC_REQUIRE_AUX_FILE.
  After running all tools that might install aux files, report on
  any that are still missing.

* lib/autoconf/general.m4
  (_AC_INIT_PARSE_ARGS): Remove mention of Cygnus configure;
  clarify function of configure.gnu.
  (AC_CONFIG_AUX_DIR): Support multiple invocations.
  (AC_CONFIG_AUX_DIRS): Now an undocumented compatibility interface
  rather than an internal subroutine; just runs AC_CONFIG_AUX_DIR on
  each of its arguments.
  (AC_CONFIG_AUX_DIR_DEFAULT): Now a backward compatibility stub that
  requires _AC_INIT_AUX_DIR without adding anything to _AC_AUX_FILES.

  (AC_REQUIRE_AUX_FILE): Now adds the named aux file to _AC_AUX_FILES
  and requires _AC_INIT_AUX_DIR, as well as being a trace hook.

  (_AC_INIT_AUX_DIR): New home of the loop searching for necessary aux
  files (formerly in AC_CONFIG_AUX_DIRS).  Looks for all the necessary
  aux files, not just for install-sh.

  (ac_config_guess, ac_config_sub, ac_configure): Issue deprecation
  warnings if these undocumented shell variables are actually used.

  (AC_CANONICAL_BUILD, AC_CANONICAL_HOST, AC_CANONICAL_TARGET):
  No need to require AC_CONFIG_AUX_DIR_DEFAULT.
  Can rely on $ac_aux_dir ending with a slash.

  * lib/autoconf/programs.m4 (AC_PROG_INSTALL, AC_PROG_MKDIR_P):
  No need to require AC_CONFIG_AUX_DIR_DEFAULT.

  * lib/autoconf/status.m4 (_AC_CONFIG_SUBDIRS):
  No need to require AC_CONFIG_AUX_DIR_DEFAULT.
  Remove check for Cygnus 

Re: [RFC PATCH 0/2] Additional AC_INIT/AC_OUTPUT-related diagnostics

2020-08-17 Thread Zack Weinberg
On Fri, Aug 14, 2020 at 5:06 PM Paul Eggert  wrote:
> On 8/14/20 11:44 AM, Zack Weinberg wrote:
> > I found a kludge that works,
> > but I’d like to hear opinions on whether we should instead postpone
> > this patch till after 2.70 so we can coordinate with automake on the
> > addition of the missing autom4te feature.
>
> I would rather not postpone, since the patch sounds correct as-is (albeit
> kludgey) and we can clean it up at our leisure after Automake is updated.
>
> Waiting for Automake might mean a long wait

That's fair.  Do you have any comments on the patches themselves or
shall I go ahead and merge them?

zw



Re: RFC PATCH 1/2] AS_INIT: try to ensure fds 0, 1, 2 are open

2020-08-28 Thread Zack Weinberg
On Thu, Aug 27, 2020 at 6:49 PM Paul Eggert  wrote:
>
> On 8/27/20 3:20 PM, Zack Weinberg wrote:
> > On Thu, Aug 27, 2020 at 2:09 PM Paul Eggert  wrote:
> >>
> >>> +  if (exec 3>&0) 2>/dev/null; then :; else exec 0 >>> +  if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
> >>> +  if (exec 3>&2); then :; else exec 2>/dev/null; fi
> >>
> >> This is all _AS_ENSURE_STANDARD_FDS needs to do; none of the other stuff is
> >> needed and I suggest omitting it as a maintenance time-sink.
> >
> > I can definitely see how the rest of it could turn into a maintenance
> > time sink, but are you sure we don't need a workaround of any kind for
> > this construct succeeding even though the target fd is closed, in very
> > old shells?
>
> Buggy old shells likely won't benefit from the other stuff anyway, as they'll 
> be
> running in older environments where the other stuff likely doesn't work 
> anyway.
> So the other stuff has little benefit to counterbalance the maintenance 
> timesink.

Fair enough.  Also I checked and _AS_DETECT_BETTER_SHELL works fine with
the standard fds closed and will reject all shells this old anyway
(they don't have
support for shell functions).

I pushed the revised patch below.



A patch was recently proposed for GNU libc to make *all* processes
start up with file descriptors 0, 1, and 2 guaranteed to be open.
Part of the rationale for this patch was that configure scripts fail
catastrophically if these fds are closed, even if you just want to run
--help or --version, e.g.

   $ ./configure --version <&-; echo $?
   ./configure: line 555: 0: Bad file descriptor
   1

configure scripts cannot rely on behavior specific to GNU libc, so
whether or not that patch gets committed, it makes sense for us to
make configure scripts robust against being started up with closed
stdin/stdout/stderr.

This patch adds code to ensure fds 0, 1, and 2 are open, early in
_AS_SHELL_SANITIZE.  It uses a construct, ‘(exec 3>)’, that’s known
not to work in very old shells, but that’s OK because those shells
will be rejected by _AS_DETECT_BETTER_SHELL anyway.  The worst-case
scenario is that the “This script requires a shell more modern than
all the shells I found on your system” error message won’t get printed.

When these fds are found not to be open, we open them on /dev/null, in
the normal I/O direction (0 for reading, 1 and 2 for writing).  There
is a case for opening them in the *opposite* direction so that, for
instance, writes to fd 1 will fail when fd 1 started out closed.
However, that would expose latent bugs that I think should be dealt
with *after* 2.70.  (See Savannah bug #110300 for more detail.)

I also took the opportunity to rationalize the order of operations in
_AS_SHELL_SANITIZE a little.  All the special shell and environment
variables that we care about are dealt with immediately after
AS_BOURNE_COMPATIBLE, and _AS_PATH_SEPARATOR_PREPARE happens
immediately before the first use of _AS_PATH_WALK.

* lib/m4sugar/m4sh.m4 (_AS_ENSURE_STANDARD_FDS): New macro.
  (_AS_SHELL_SANITIZE): Move the “Unset variables that we do not need”
  and “NLS nuisances” blocks immediately after setting IFS; merge the
  unsetting of CDPATH into the main unsetting loop; move invocation of
  _AS_PATH_SEPARATOR_PREPARE to immediately above the “Find who we are”
  block; invoke _AS_ENSURE_STANDARD_FDS immediately before
  _AS_PATH_SEPARATOR_PREPARE.

* tests/base.at (configure with closed standard fds): New test.
* tests/torture.at (--help and --version in unwritable directory): New test.
---
 lib/m4sugar/m4sh.m4 | 78 ++---
 tests/base.at   | 73 ++
 tests/torture.at| 27 
 3 files changed, 152 insertions(+), 26 deletions(-)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index c9e86246..bd4d2b9e 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -300,6 +300,28 @@ dnl We shouldn't have to worry about any traps
being active at this point.
 exit 255])# _AS_REEXEC_WITH_SHELL


+# _AS_ENSURE_STANDARD_FDS
+# ---
+# Ensure that file descriptors 0, 1, and 2 are open, as a defensive
+# measure against weird environments that run configure scripts
+# with these descriptors closed.
+# `exec m>` fails in POSIX sh when fd N is closed, but succeeds
+# regardless of whether fd N is open in some old shells, e.g. Solaris
+# /bin/sh.  This is OK because those shells will be rejected by
+# _AS_DETECT_BETTER_SHELL anyway.
+# TODO post-2.70: use "backward" redirections when opening these fds,
+# so we preserve their unusable state.  Needs downstream logic to
+# stop on the first failed attempt to write to fd 1 or 2, so we don't
+# run through an entire configure script spewing "

[PATCH] Generate manpages directly from source code.

2020-08-21 Thread Zack Weinberg
-version .version
 
 edit = sed \
diff --git a/bin/autoconf.as b/bin/autoconf.as
index ab6e3c52..ddf8cced 100644
--- a/bin/autoconf.as
+++ b/bin/autoconf.as
@@ -22,7 +22,7 @@ m4_divert_push([HEADER-COPYRIGHT])dnl
 m4_divert_pop([HEADER-COPYRIGHT])dnl back to BODY
 AS_ME_PREPARE[]dnl
 
-usage=["\
+help=["\
 Usage: $0 [OPTION]... [TEMPLATE-FILE]
 
 Generate a configuration script from a TEMPLATE-FILE if given, or
@@ -75,11 +75,11 @@ There is NO WARRANTY, to the extent permitted by law.
 
 Written by David J. MacKenzie and Akim Demaille."]
 
-help="\
+usage_err="\
 Try '$as_me --help' for more information."
 
 exit_missing_arg='
-  m4_bpatsubst([AS_ERROR([option '$[1]' requires an argument$as_nl$help])],
+  m4_bpatsubst([AS_ERROR([option '$[1]' requires an 
argument$as_nl$usage_err])],
 ['], ['\\''])'
 # restore font-lock: '
 
@@ -100,7 +100,7 @@ while test $# -gt 0 ; do
 --version | -V )
echo "$version" ; exit ;;
 --help | -h )
-   AS_ECHO(["$usage"]); exit ;;
+   AS_ECHO(["$usage_err"]); exit ;;
 
 --verbose | -v )
verbose=:
@@ -154,7 +154,7 @@ while test $# -gt 0 ; do
break ;;
 -* )
exec >&2
-   AS_ERROR([invalid option '$[1]'$as_nl$help]) ;;
+   AS_ERROR([invalid option '$[1]'$as_nl$usage_err]) ;;
 * )
break ;;
   esac
@@ -178,7 +178,7 @@ case $# in
   1)
 infile=$1 ;;
   *) exec >&2
- AS_ERROR([invalid number of arguments$as_nl$help]) ;;
+ AS_ERROR([invalid number of arguments$as_nl$usage_err]) ;;
 esac
 
 # Unless specified, the output is stdout.
diff --git a/bin/autoheader.in b/bin/autoheader.in
index b8ed9d3f..2a9a2e07 100644
--- a/bin/autoheader.in
+++ b/bin/autoheader.in
@@ -72,7 +72,7 @@ or else 'configure.in'.
   -f, --force  consider all files obsolete
   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY
 
-" . Autom4te::ChannelDefs::usage () . "
+" . Autom4te::ChannelDefs::usage . "
 
 Library directories:
   -B, --prepend-include=DIR  prepend directory DIR to search path
diff --git a/bin/autom4te.in b/bin/autom4te.in
index 3a80d4b7..d98998de 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -204,8 +204,7 @@ General help using GNU software: 
<https://www.gnu.org/gethelp/>.
 
 # $VERSION
 # 
-$version =  <<"EOF";
-autom4te (@PACKAGE_NAME@) @VERSION@
+$version = "autom4te (@PACKAGE_NAME@) @VERSION@
 Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
 License GPLv3+/Autoconf: GNU GPL version 3 or later
 <https://gnu.org/licenses/gpl.html>, <https://gnu.org/licenses/exceptions.html>
@@ -213,7 +212,7 @@ This is free software: you are free to change and 
redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 
 Written by Akim Demaille.
-EOF
+";
 
 
 ## -- ##
diff --git a/bin/autoscan.in b/bin/autoscan.in
index 0eb35040..9780f7db 100644
--- a/bin/autoscan.in
+++ b/bin/autoscan.in
@@ -87,7 +87,6 @@ my %needed_macros =
'AC_PREREQ' => [$me],
   );
 
-my $configure_scan = 'configure.scan';
 my $log;
 
 # Autoconf and lib files.
@@ -103,7 +102,7 @@ $help = "Usage: $0 [OPTION]... [SRCDIR]
 Examine source files in the directory tree rooted at SRCDIR, or the
 current directory if none is given.  Search the source files for
 common portability problems, check for incompleteness of
-'configure.ac', and create a file '$configure_scan' which is a
+'configure.ac', and create a file 'configure.scan' which is a
 preliminary 'configure.ac' for that package.
 
   -h, --help  print this help, then exit
@@ -462,7 +461,7 @@ sub output_kind ($$)
 if exists $kind_comment{$kind};
   foreach my $word (sort keys %{$used{$kind}})
 {
-  # Output the needed macro invocations in $configure_scan if not
+  # Output the needed macro invocations in configure.scan if not
   # already printed, and remember these macros are needed.
   foreach my $macro (@{$macro{$kind}{$word}})
{
diff --git a/build-aux/help-extract.pl b/build-aux/help-extract.pl
new file mode 100644
index ..0edc793a
--- /dev/null
+++ b/build-aux/help-extract.pl
@@ -0,0 +1,275 @@
+# help-extract -- extract --help and --version output from a script.
+# Copyright (C) 2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www

[PATCH] tests: New helper macro AT_CHECK_MAKE.

2020-08-20 Thread Zack Weinberg
This macro factors out some repeated code surrounding tests that run
make, such as honoring $MAKE, *not* honoring $MAKEFLAGS, and
normalizing the exit status.  Partially addresses bug #110267
(problems with Sun’s make barfing on GNU make options from
$MAKEFLAGS).

Also addresses some unrelated problems I noticed while changing all
the tests that run make to use this macro:

The shtool test is now properly skipped if shtool is not available on
the host system.

Some of the Fortran tests would create an executable and then run it,
others would create an executable and then the AT_CHECK operation that
would run it was commented out.  There’s no evidence in the changelog
or the git history for why this was done.  I uncommented all of the
commented-out cases; this can be undone easily if it causes
problems.  (It can’t be an issue with cross-compilation because some
of the tests do run the executable.)

It seems like it ought to be possible to put the three lines

  : "${MAKE=make}"
  export MAKE
  unset MAKEFLAGS

somewhere near the top of the testsuite script and not have to repeat
them for every invocation of AT_CHECK_MAKE, but I couldn’t figure out
the right way to do that in an autotest suite.  Suggestions would be
welcome.

OK for trunk?

zw


* tests/local.at (AT_CHECK_MAKE): New macro wrapping an AT_CHECK
  invocation of make.  All tests that run make updated to use this macro.
* tests/fortran.at: Uncomment all AT_CHECKs that run the just-compiled
  program.
* tests/foreign.at (shtool): Skip the test if shtool is not available
  from the host system.  Simplify shell logic.
---
 tests/autotest.at | 21 ---
 tests/c.at| 24 ++--
 tests/foreign.at  | 16 
 tests/fortran.at  | 93 ---
 tests/local.at| 26 +
 tests/torture.at  | 15 
 6 files changed, 99 insertions(+), 96 deletions(-)

diff --git a/tests/autotest.at b/tests/autotest.at
index 5519e9c7..2892b1dd 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -1599,20 +1599,13 @@ for signal in 2 15; do
   # AT_CHECK([[grep '[iI]nterrupt[  ]' stderr]], [1])
 
   # Ditto with `make' in the loop.
-  : "${MAKE=make}"
-  unset MAKEFLAGS
-  # Need to eliminate outer TESTSUITEFLAGS here.
-  # Need to normalize exit status here: some make implementations
-  # exit 1 (BSD make), some exit 2 (GNU make).
-  AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
-  [case $? in 1|2) exit 1;; *) exit $?;; esac],
-  [1], [ignore], [stderr])
+  # Explicitly setting TESTSUITEFLAGS to empty...
+  AT_CHECK_MAKE([TESTSUITEFLAGS=], [], [1], [ignore], [stderr])
   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
-  # Ditto, parallel case.
-  AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
-  [case $? in 1|2) exit 1;; *) exit $?;; esac],
-  [1], [ignore], [stderr])
+
+  # ... and explicitly requesting 3-fold parallelism.
+  AT_CHECK_MAKE([TESTSUITEFLAGS=--jobs=3], [], [1], [ignore], [stderr])
   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
 done
@@ -1926,7 +1919,7 @@ rm t/atconfig
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
-AT_CHECK([${MAKE-make}], [], [ignore])
+AT_CHECK_MAKE
 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
 AT_CLEANUP
@@ -1978,7 +1971,7 @@ rm t/atconfig
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
-AT_CHECK([${MAKE-make}], [], [ignore])
+AT_CHECK_MAKE
 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
 AT_CLEANUP
diff --git a/tests/c.at b/tests/c.at
index b1dabd14..d13b321e 100644
--- a/tests/c.at
+++ b/tests/c.at
@@ -326,11 +326,11 @@ class foo { int x; };
 class foo foobar;
 ]])
 
-AT_CHECK([autoconf])
-AT_CHECK([autoheader])
-AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
-AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
-AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_AUTOHEADER([], [restrict])
+AT_CHECK_CONFIGURE
+AT_CHECK_MAKE([cpp-works || exit 77])
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -381,10 +381,9 @@ int main (void)
 }
 ]])
 
-: "${MAKE=make}"
-AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
-AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -424,9 +423,8 @@ AT_DATA([foo.cpp],
 }
 ]])
 
-: "${MAKE=make}"
-AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
-AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE

[RFC PATCH 1/2] AS_INIT: try to ensure fds 0, 1, 2 are open

2020-08-27 Thread Zack Weinberg
A patch was recently proposed for GNU libc to make *all* processes
start up with file descriptors 0, 1, and 2 guaranteed to be open.
Part of the rationale for this patch was that configure scripts fail
catastrophically if these fds are closed, even if you just want to run
--help or --version, e.g.

   $ ./configure --version <&-; echo $?
   ./configure: line 555: 0: Bad file descriptor
   1

Obviously configure scripts cannot rely on behavior specific to GNU
libc, so even if that patch gets committed, it might make sense for
us to try to make configure scripts robust against being started up
with closed stdin/stdout/stderr.  This patch is a first attempt at
adding this robustness.

Detecting whether an fd is closed, readable, writable, or both, is
trivial in C.  In shell, on the other hand, I have not been able to
find a technique that works to my satisfaction on a broad variety of
Unixes. This patch uses /proc//fdinfo when available (only on
Linux, AFAIK).  Otherwise, it relies on ‘exec 3>’, which can only
detect whether an fd is *open*, not whether it is readable or
writable.  Worse, in some old shells (e.g. Solaris 10 /bin/sh) this
construct will succeed regardless of whether fd ‘n’ is closed.
(A questionably reliable old beard on Stack Overflow told me that this
is a known bug in “the” Bourne shell, by which he presumably means the
original implementation.)  The second patch in this set adds logic to
try using the ‘lsof’ and/or ‘fstat’ commands when available, which
helps, but brings other problems and is possibly not worth the hassle.

I’m asking for feedback on the code, suggestions for additional
techniques to try, and opinions whether this is worth trying to
do at all.  The patchset is available as the ‘zack/ensure-standard-fds’
branch in git, if anyone would like to experiment with it.  I’ve gotten
clean testsuite runs on Debian unstable, Solaris 10, NetBSD 9, and
FreeBSD 11 (the latter two are somewhat unusual installations)
except as noted in the second patch.

zw

* lib/m4sugar/m4sh.m4 (_AS_ENSURE_STANDARD_FDS): New macro.
  (_AS_SHELL_SANITIZE): Move the “Unset variables that we do not need”
  and “NLS nuisances” blocks immediately after setting IFS; merge the
  unsetting of CDPATH into the main unsetting loop; move invocation of
  _AS_PATH_SEPARATOR_PREPARE to immediately above the “Find who we are”
  block; invoke _AS_ENSURE_STANDARD_FDS immediately before
  _AS_PATH_SEPARATOR_PREPARE.

* tests/base.at (configure with closed standard fds): New test.
* tests/torture.at (--help and --version in unwritable directory): New test.
---
 lib/m4sugar/m4sh.m4 | 115 
 tests/base.at   |  73 
 tests/torture.at|  27 +++
 3 files changed, 194 insertions(+), 21 deletions(-)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index c9e86246..3b1e9015 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -299,6 +299,79 @@ dnl code inserted by AS_REQUIRE_SHELL_FN will appear 
_after_ this point.
 dnl We shouldn't have to worry about any traps being active at this point.
 exit 255])# _AS_REEXEC_WITH_SHELL
 
+# _AS_ENSURE_STANDARD_FDS
+# ---
+# Ensure that file descriptor 0 is open and readable, and file
+# descriptors 1 and 2 are open and writable.  This is a defensive
+# measure against weird environments that run configure scripts
+# with these descriptors closed.
+#
+# There is no universally portable way to test the readability
+# or writability of a file descriptor from a shell script, but there
+# are several semi-portable techniques which we try in descending order
+# of how likely we are to be on a system where they will work, how efficient
+# they are, and whether they can tell whether an fd is open for *reading*.
+#
+# This code runs before _AS_DETECT_BETTER_SHELL and must therefore be
+# extra careful about using only portable shell constructs.  Also, the
+# tests must not actually read or write any data on the fds being
+# tested, and must take care not to do anything that could temporarily
+# open fds 0, 1, or 2 in the parent shell.  For instance, command
+# substitutions `...` may be implemented with a pipe to the parent
+# shell; if fd 0 was closed to begin with, the read end of this pipe
+# could temporarily occupy fd 0 and invalidate the test.
+m4_defun([_AS_ENSURE_STANDARD_FDS], [dnl
+# If possible ensure that fds 0, 1, and 2 are open in an appropriate way.
+# If Linux's /proc//fdinfo directory is available, we can use it
+# to do an accurate test without any forks.
+if test -d /proc/$$/fdinfo; then
+  for as_fd in 0 1 2; do
+as_fd_ok=false
+if test -f /proc/$$/fdinfo/$as_fd; then
+  # `while read ...; do ...; done < file` might execute the loop
+  # in a subshell, preventing it from setting as_fd_ok.
+  exec 3/fdinfo is
+  # already Linux-specific, we can assume that O_ACCMODE == 3,
+  # O_RDONLY == 0, O_WRONLY == 1, O_RDWR == 2. Rather 

[RFC PATCH 2/2] _AS_ENSURE_STANDARD_FDS: use lsof and fstat when possible

2020-08-27 Thread Zack Weinberg
This follow-up patch adds additional ways of detecting whether fds 0,
1, 2 are closed, using the ‘lsof’ and ‘fstat’ utilities.  The former
is not a standard component of any OS, but is very widely installed
and can produce machine-parseable output; the latter ships with many
BSD variants but its output is in a fixed format not designed for
machine parsing.  Both of them may fail due to privilege restrictions.

The biggest problem with using these is that we have to run a program
and inspect its output.  I tried capturing the output using command
substitution, but that is often implemented using a pipe from the
child process to the parent shell; if fd 0 (for instance) started out
closed in the parent, the pipe is likely to occupy that fd number
right when lsof/fstat is inspecting the parent’s file table, causing a
false report that fd 0 is open.  The only alternatives I am aware of
are temporary files or named pipes, both of which involve creating
directory entries somewhere...and we can’t assume we have mktemp(1).
This patch uses a file in the current working directory, but that
breaks all of the tests that assume ‘configure --help’ will not write
to the current working directory (which seems like a reasonable
promise for us to make, tbh).

Better ideas solicited.

* lib/m4sugar/m4sh.m4 (_AS_ENSURE_STANDARD_FDS): If /proc//fdinfo
  is not available, try to use lsof or fstat.
---
 lib/m4sugar/m4sh.m4 | 66 ++---
 1 file changed, 57 insertions(+), 9 deletions(-)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 3b1e9015..6e145956 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -359,16 +359,64 @@ if test -d /proc/$$/fdinfo; then
   done
 
 else
-  # Shell redirection operations can only tell whether an fd is open,
-  # not whether it is readable or writable, so this is a last resort.
-  # `exec >` fails in POSIX sh when fd N is closed, but succeeds
-  # regardless of whether fd N is open in some old shells, e.g. Solaris
-  # /bin/sh.  We can live with that; at least it never fails when fd N
-  # is *open*.
-  if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
-  if (exec 3>&2); then :; else exec 2>/dev/null; fi
+  # If lsof is available, we can ask it to print just the information
+  # we want, in a format that's easy to parse.
+  # We can't run this command inside backquotes; with some shells that
+  # may cause the parent shell to have a pipe active on fd 0 right when
+  # lsof scans its file table.
+  # lsof may exist but not actually work, e.g. if it's restricted to root.
+  : > as_fd_status.$$
+  if command -v lsof > /dev/null 2>&1; then
+lsof -a -p $$ -d 0,1,2 -F fa > as_fd_status.$$ 2> /dev/null || :
+  fi
+  as_fd_status=`cat as_fd_status.$$`
 
+  if test -n "$as_fd_status"; then
+case "$as_fd_status" in *f0?a[ru]*) ;; *) exec 0/dev/null;; esac
+case "$as_fd_status" in *f2?a[wu]*) ;; *) exec 2>/dev/null;; esac
+
+  else
+# BSD fstat can also print the information we want.  The same concerns
+# re backquotes and privilege restrictions as above apply.
+if command -v fstat > /dev/null 2>&1; then
+  fstat -p $$ -n > as_fd_status.$$ 2> /dev/null || :
+fi
+
+# fstat's output is a fixed space-separated set of columns, not
+# designed for machine parsing:
+#   USER CMD PID FD DEV INUM MODE SZ|DV R/W.
+# Pipes and sockets are formatted differently from regular files
+# and device nodes, with an unpredictable number of columns in
+# between FD and R/W.  We just ignore everything after the fd
+# and before the last few characters on the line.
+# If there are unexpected spaces in the USER or CMD columns, the
+# sed program will output nothing and we will go on to the next
+# case.
+# The first sed 's' command has hard tabs in its arguments.
+as_fd_status="`sed -ne '[
+  s/[  ][  ]*/ /g
+  s/ $//
+  s/^[^ ]* [^ ]* [0-9]* \([012]\)\**.* \([rw][rw]*\)$/f\1,\2,/p
+]' as_fd_status.$$`"
+if test -n "$as_fd_status"; then
+  case "$as_fd_status" in *f0,r,*|*f0,rw,*) ;; *) exec 0/dev/null;; esac
+  case "$as_fd_status" in *f2,w,*|*f2,rw,*) ;; *) exec 2>/dev/null;; esac
+
+else
+  # Shell redirection operations can only tell whether an fd is open,
+  # not whether it is readable or writable, so this is a last resort.
+  # `exec >` fails in POSIX sh when fd N is closed, but succeeds
+  # regardless of whether fd N is open in some old shells, e.g. Solaris
+  # /bin/sh.  We can live with that; at least it never fails when fd N
+  # is *open*.
+  if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
+  if (exec 3>&2); then :; else exec 2>/dev/null; fi
+fi
+  fi
+  rm -f as_fd_status.$$
 fi
 ])
 
-- 
2.28.0




Re: RFC PATCH 1/2] AS_INIT: try to ensure fds 0, 1, 2 are open

2020-08-27 Thread Zack Weinberg
On Thu, Aug 27, 2020 at 2:09 PM Paul Eggert  wrote:
>
> > +  if (exec 3>&0) 2>/dev/null; then :; else exec 0 > +  if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
> > +  if (exec 3>&2); then :; else exec 2>/dev/null; fi
>
> This is all _AS_ENSURE_STANDARD_FDS needs to do; none of the other stuff is
> needed and I suggest omitting it as a maintenance time-sink.

I can definitely see how the rest of it could turn into a maintenance
time sink, but are you sure we don't need a workaround of any kind for
this construct succeeding even though the target fd is closed, in very
old shells?  I wouldn't be concerned for almost anything else, but
this is the _generated configure scripts_ we're talking about here.
Coping with very old shells is a big part of why they exist still, and
are still shell scripts.

> not that 'read' from 0 or 'write' to 1 or 2 must succeed (there's never any 
> guarantee of that).

I'm not 100% convinced by this argument but I don't have a real
counterargument either and in any case it's more on-topic for the
glibc thread, not here.

zw



[PATCH 1/2] Trim whitespace from arguments of AC_INIT (#107986)

2020-08-14 Thread Zack Weinberg
Specifically, all five arguments, if present, are passed through
m4_normalize before doing anything else with them.  For instance,
AC_INIT([  GNU  Hello  ], [1.0]) is now equivalent to
AC_INIT([GNU Hello], [1.0]).

As a consequence, newlines in the arguments to AC_INIT are now
converted to spaces and no longer trigger warnings.

Also, diagnose inappropriate contents of the fourth and fifth
arguments as well as the first three.  The fifth argument should be
“usable as-is in single- and double-quoted strings and quoted and
unquoted here-docs,” like the first three.  (This is the check
performed by _AC_INIT_LITERAL.)  The fourth argument (TARNAME) is used
to construct filenames, so apply an even more stringent test, namely
AS_LITERAL_WORD_IF.

Suggested by David A. Wheeler, who submitted a patch, but I didn’t
wind up using any of his code.

* lib/autoconf/general.m4 (_AC_INIT_LITERAL): Not necessary to check
  for newlines anymore.
  (_AC_INIT_PACKAGE): Pass all five arguments through m4_normalize
  before doing anything else with them.  New warning: apply
  _AC_INIT_LITERAL to fifth argument (URL).  New warning: complain
  if fourth argument (TARNAME) is not a literal word according to
  AS_LITERAL_WORD_IF.  Simplify a conditional by using m4_default.

* tests/base.at (AC_INIT with unusual version strings): Adjust to
  match above changes, add more subtests.
---
 NEWS| 11 +++
 doc/autoconf.texi   |  7 +++-
 lib/autoconf/general.m4 | 70 ++-
 tests/base.at   | 73 -
 4 files changed, 130 insertions(+), 31 deletions(-)

diff --git a/NEWS b/NEWS
index 000570e0..e0cdd069 100644
--- a/NEWS
+++ b/NEWS
@@ -194,6 +194,17 @@ GNU Autoconf NEWS - User visible changes.
 - AC_FC_LINE_LENGTH now documents the maximum portable length of
   "unlimited" Fortran source code lines to be 250 columns, not 254.
 
+- AC_INIT now trims extra white space from its arguments.  For instance,
+
+AC_INIT([  GNU  Hello  ], [1.0])
+
+  will set PACKAGE_NAME to “GNU Hello”.
+
+- AC_INIT will now issue warnings (in the “syntax” category) for a
+  non-literal URL argument, and for a TARNAME argument which is either
+  non-literal or contains characters that should not be used in file
+  names (e.g. ‘*’).
+
 * Noteworthy changes in release 2.69 (2012-04-24) [stable]
 
 ** Autoconf now requires perl 5.6 or better (but generated configure
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8e563bf8..4b90debb 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -1890,7 +1890,7 @@ Initializing configure
 other than alphanumerics and underscores are changed to @samp{-}.  If
 provided, @var{url} should be the home page for the package.
 
-The arguments of @code{AC_INIT} must be static, i.e., there should not
+All the arguments of @code{AC_INIT} must be static, i.e., there should not
 be any shell computation, quotes, or newlines, but they can be computed
 by M4.  This is because the package information strings are expanded at
 M4 time into several contexts, and must give the same text at shell time
@@ -1901,6 +1901,11 @@ Initializing configure
 Autoconf does just that, for all builds of the development tree made
 between releases).
 
+The @var{tarname} argument is used to construct filenames.
+In addition to being static, it should not contain wildcard
+characters, white space, or anything else that could be troublesome
+as part of a file or directory name.
+
 The following M4 macros (e.g., @code{AC_PACKAGE_NAME}), output variables
 (e.g., @code{PACKAGE_NAME}), and preprocessor symbols (e.g.,
 @code{PACKAGE_NAME}), are defined by @code{AC_INIT}:
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 8436d8c3..4d5f021d 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -224,40 +224,66 @@ AU_ALIAS([AC_HELP_STRING], [AS_HELP_STRING])
 
 # _AC_INIT_LITERAL(STRING)
 # 
-# Reject STRING if it contains newline, or if it cannot be used as-is
-# in single-quoted strings, double-quoted strings, and quoted and
-# unquoted here-docs.
+# Reject STRING if it cannot be used as-is in single-quoted strings,
+# double-quoted strings, and quoted and unquoted here-docs.
 m4_define([_AC_INIT_LITERAL],
-[m4_if(m4_index(m4_translit([[$1]], [
-""], ['']), ['])AS_LITERAL_HEREDOC_IF([$1], [-]), [-1-], [],
-  [m4_warn([syntax], [AC_INIT: not a literal: $1])])])
+[m4_if(m4_index(m4_translit([[$1]], [""], ['']),
+['])AS_LITERAL_HEREDOC_IF([$1], [-]),
+   [-1-], [],
+  [m4_warn([syntax], [AC_INIT: not a literal: "$1"])])])
 
 # _AC_INIT_PACKAGE(PACKAGE-NAME, VERSION, BUG-REPORT, [TARNAME], [URL])
 # -
 m4_define([_AC_INIT_PACKAGE],
-[_AC_INIT_LITERAL([$1])
-_AC_INIT_LITERAL([$2])
-_AC_INIT_LITERAL([$3])
+[m4_pushdef([_ac_init_NAME], m4_normalize([$1]))
+m4_pushdef([_ac_init_VERSION],   m4_normalize([$2]))

[PATCH 2/2] Warn if AC_INIT or AC_OUTPUT are missing from configure.ac (#107986)

2020-08-14 Thread Zack Weinberg
It is almost always incorrect for a configure script to omit either
AC_INIT or AC_OUTPUT.  Issue warnings in the ‘syntax’ category for
this.

The implementation is, unfortunately, a bit of a kludge.  To check for
the _absence_ of a macro invocation, we can use m4_provide_if inside a
m4_wrap hook.  However, if we activate the m4_wrap hook directly from
general.m4, we get spurious warnings at freeze time.  We also get
warnings whenever a script that’s missing AC_INIT and/or AC_OUTPUT
is *traced*, which means we get double warnings from autoconf, and
autoheader and aclocal complain about it too, which seems unnecessary.

A clean way to deal with this would be to make the hook look for a
special macro that’s defined only when autoconf (the program) is
invoked without any --trace arguments.  Unfortunately, autom4te
doesn’t pass --define down to M4, and changing that would involve
coordinating with Automake (the project), so instead I’ve gone for the
kludge: a new file lib/autoconf/trailer.m4 that calls m4_wrap.  This
file is *not* included in autoconf.m4f, but it’s installed, and it’s
added to the m4 invocation by autoconf (the program) only when not
tracing.  (It still uses m4_wrap, because we pass it to m4 *before*
configure.ac, because otherwise we get nonsense locations for any
*other* diagnostics coming out of this autoconf invocation.  I don’t
know why.)

The additional checks in autoreconf are intended to make sure that if
autoreconf skips a directory entirely, you get told why.

Lots of tests in the testsuite didn’t bother with AC_OUTPUT, and
somewhat fewer didn’t bother with AC_INIT; where possible I just added
them.

Suggested by David A. Wheeler, who submitted a patch, but I didn’t
wind up using any of his code.  (His implementation used an extra
tracing pass, only checked for a missing AC_INIT, and invented a new
command-line option to turn off this specific warning.  I thought this
was tidier overall, despite the kludge.)

* lib/autoconf/general.m4 (_AC_FINALIZE): New macro: code to be run
  when generating configure, after the entire configure.ac is
  processed. Currently only checks that AC_INIT and AC_OUTPUT were
  called at some point, issuing syntax-category warnings if not.
  (AC_INIT, AC_OUTPUT): m4_provide self.
* lib/autoconf/trailer.m4: New file that just calls m4_wrap([_AC_FINALIZE]).
* lib/local.mk: Install new file.

* bin/autoconf.as: Add trailer.m4 to the final invocation of autom4te,
  but only when not tracing.
* bin/autoreconf.in (autoreconf_current_directory): Distinguish in
  diagnostics between “directory skipped because it doesn’t have a
  configure.ac or configure.in” (e.g. Cygnus configure) and “directory
  has a configure.ac but it doesn’t appear to be autoconf input.”

* tests/*.at: Fix all tests affected by the new warnings.
---
 NEWS|  3 +++
 bin/autoconf.as | 14 +-
 bin/autoreconf.in   | 14 ++
 lib/autoconf/general.m4 | 23 +++
 lib/autoconf/status.m4  |  6 ++
 lib/autoconf/trailer.m4 |  4 
 lib/local.mk|  3 ++-
 tests/base.at   | 33 ++---
 tests/c.at  |  1 +
 tests/compile.at| 26 +++---
 tests/m4sh.at   |  5 -
 tests/semantics.at  | 12 ++--
 tests/tools.at  | 28 +++-
 tests/torture.at| 13 -
 tests/wrapper.as|  3 ++-
 15 files changed, 154 insertions(+), 34 deletions(-)
 create mode 100644 lib/autoconf/trailer.m4

diff --git a/NEWS b/NEWS
index e0cdd069..ccf0f40a 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ GNU Autoconf NEWS - User visible changes.
 ** The use of the long-deprecated name 'configure.in' for the autoconf
input file now elicits a warning in the 'obsolete' category.
 
+** autoconf will now issue warnings (in the ‘syntax’ category) if the
+   input file is missing a call to AC_INIT and/or AC_OUTPUT.
+
 ** Older version of automake and aclocal (< 1.8) are no longer supported
by autoreconf.
 
diff --git a/bin/autoconf.as b/bin/autoconf.as
index 581eb81e..ab6e3c52 100644
--- a/bin/autoconf.as
+++ b/bin/autoconf.as
@@ -85,6 +85,7 @@ exit_missing_arg='
 
 # Variables.
 : ${AUTOM4TE='@bindir@/@autom4te-name@'}
+: ${trailer_m4='@pkgdatadir@/autoconf/trailer.m4'}
 autom4te_options=
 outfile=
 verbose=false
@@ -183,9 +184,20 @@ esac
 # Unless specified, the output is stdout.
 test -z "$outfile" && outfile=-
 
+# Don't read trailer.m4 if we are tracing.
+if test -n "$traces"; then
+trailer_m4=""
+else
+# The extra quotes will be stripped by eval.
+trailer_m4=\""$trailer_m4"\"
+fi
+
 # Run autom4te with expansion.
+# trailer.m4 is read _before_ $infile, despite the name,
+# because putting it afterward screws up autom4te's location tracing.
 eval set x "$autom4te_options" \
-  --language=autoconf --output=\"\$outfile\" "$traces" \"\$infile\"
+  --language=autoconf --output=\"\$outfile\" "$traces" 

[RFC PATCH 0/2] Additional AC_INIT/AC_OUTPUT-related diagnostics

2020-08-14 Thread Zack Weinberg
In Savannah bug #107986, David Wheeler contributed some additional
diagnostics for misuse of AC_INIT.  I sat down to review them late
last week and wound up making so many changes and enhancements that
this is effectively a rewrite from scratch.  (I would like to
apologize to David for making him go through the copyright assignment
process and then not actually using any of his code.)

The first patch, which I hope is uncontroversial, makes AC_INIT trim
whitespace (via m4_normalize) from all its arguments, and extends the
existing checks for inappropriate contents of the first three
arguments to cover the fourth and fifth as well.

The second patch adds warnings when a configure.ac is missing calls to
AC_INIT and/or AC_OUTPUT.  The concept here should also be
unproblematic, but I’m not entirely happy with the implementation.
David’s original implementation used an extra trace pass and custom
logic in bin/autoconf.as.  I decided it would be better to make these
normal syntax warnings, but this involves an m4_wrap hook that’s *not*
run when tracing or when freezing, and the clean way to do that would
involve adding a feature to autom4te.  I found a kludge that works,
but I’d like to hear opinions on whether we should instead postpone
this patch till after 2.70 so we can coordinate with automake on the
addition of the missing autom4te feature.

zw

Zack Weinberg (2):
  Trim whitespace from arguments of AC_INIT (#107986)
  Warn if AC_INIT or AC_OUTPUT are missing from configure.ac (#107986)

 NEWS|  14 ++
 bin/autoconf.as |  14 +-
 bin/autoreconf.in   |  14 --
 doc/autoconf.texi   |   7 ++-
 lib/autoconf/general.m4 |  93 ++-
 lib/autoconf/status.m4  |   6 +++
 lib/autoconf/trailer.m4 |   4 ++
 lib/local.mk|   3 +-
 tests/base.at   | 106 ++--
 tests/c.at  |   1 +
 tests/compile.at|  26 --
 tests/m4sh.at   |   5 +-
 tests/semantics.at  |  12 ++---
 tests/tools.at  |  28 +--
 tests/torture.at|  13 +++--
 tests/wrapper.as|   3 +-
 16 files changed, 284 insertions(+), 65 deletions(-)
 create mode 100644 lib/autoconf/trailer.m4

-- 
2.28.0




[RFC PATCH 3/3] Update documentation of warnings options and strictness levels.

2020-09-22 Thread Zack Weinberg
The warning categories ‘cross’ and ‘portability-recursive’ were not mentioned
in the manual.

Also clarify the relationship between warnings categories and strictness
levels, and streamline the description of strictness levels by merging the
“Gnits” section into the “Strictness” section.

* doc/automake.texi (Gnits, Strictness): Combine these sections.
  Minor revisions to explanation of strictness levels.
  (automake Invocation): Add documentation of all the warnings
  categories that have been added since the last time this section
  was updated.  Minor clarifications.
---
 doc/automake.texi | 250 --
 1 file changed, 129 insertions(+), 121 deletions(-)

diff --git a/doc/automake.texi b/doc/automake.texi
index 3a6c1815d..738eb84cb 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -118,7 +118,6 @@ Top
 * Include:: Including extra files in an Automake template
 * Conditionals::Conditionals
 * Silencing Make::  Obtain less verbose output from @command{make}
-* Gnits::   The effect of @option{--gnu} and 
@option{--gnits}
 * Not Enough::  When Automake is not Enough
 * Distributing::Distributing the Makefile.in
 * API Versioning::  About compatibility between Automake versions
@@ -1913,7 +1912,9 @@ General Operation
 
 @node Strictness
 @section Strictness
-
+@c "Gnits" used to be a separate section.
+@c This @anchor allows old links to still work.
+@anchor{Gnits}
 @cindex Non-GNU packages
 
 While Automake is intended to be used by maintainers of GNU packages, it
@@ -1921,44 +1922,107 @@ Strictness
 not want to use all the GNU conventions.
 
 @cindex Strictness, defined
-@cindex Strictness, @option{foreign}
-@cindex @option{foreign} strictness
-@cindex Strictness, @option{gnu}
-@cindex @option{gnu} strictness
-@cindex Strictness, @option{gnits}
-@cindex @option{gnits} strictness
+To this end, Automake supports three levels of @dfn{strictness}---how
+stringently Automake should enforce conformance with GNU conventions.
+Each strictness level can be selected using an option of the same name;
+see @ref{Options}.
 
-To this end, Automake supports three levels of @dfn{strictness}---the
-strictness indicating how stringently Automake should check standards
-conformance.
-
-The valid strictness levels are:
+The strictness levels are:
 
 @table @option
+@item gnu
+@cindex Strictness, @option{gnu}
+@cindex @option{gnu} strictness
+@opindex --gnu
+This is the default level of strictness.  Automake will check for
+basic compliance with the GNU standards for software packaging.
+@xref{Top,,, standards, The GNU Coding Standards} for full details
+of these standards.  Currently the following checks are made:
+
+@itemize @bullet
+@item
+The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
+and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
+or @file{COPYING}, are required at the topmost directory of the package.
+
+If the @option{--add-missing} option is given, @command{automake} will
+add a generic version of the @file{INSTALL} file as well as the
+@file{COPYING} file containing the text of the current version of the
+GNU General Public License existing at the time of this Automake release
+(version 3 as this is written,
+@uref{https://www.gnu.org/@/copyleft/@/gpl.html}).
+However, an existing @file{COPYING} file will never be overwritten by
+@command{automake}.
+
+@item
+The options @option{no-installman} and @option{no-installinfo} are
+prohibited.
+@end itemize
+
+Future versions of Automake will add more checks at this level of
+strictness; it is advisable to be familiar with the precise requirements
+of the GNU standards.
+
+Future versions of Automake may, at this level of strictness, require
+certain non-standard GNU tools to be available to maintainer-only
+Makefile rules.  For instance, in the future @command{pathchk}
+(@pxref{pathchk invocation,,, coreutils, GNU Coreutils})
+may be required to run @samp{make dist}.
+
 @item foreign
+@cindex Strictness, @option{foreign}
+@cindex @option{foreign} strictness
+@opindex --foreign
 Automake will check for only those things that are absolutely
 required for proper operation.  For instance, whereas GNU standards
 dictate the existence of a @file{NEWS} file, it will not be required in
 this mode.  This strictness will also turn off some warnings by default
 (among them, portability warnings).
-The name comes from the fact that Automake is intended to be
-used for GNU programs; these relaxed rules are not the standard mode of
-operation.
-
-@item gnu
-Automake will check---as much as possible---for compliance to the GNU
-standards for packages.  This is the default.
 
 @item gnits
+@cindex Strictness, @option{gnits}
+@cindex @option{gnits} strictness
+@opindex --gnits
 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
 standards}.  These are based on 

[RFC PATCH 0/3] Work around autoconf/automake warnings skew (automake side)

2020-09-22 Thread Zack Weinberg
This patch set completes the work necessary on automake’s side to bring
ChannelDefs.pm back into sync between automake and autoconf.  It also
updates the documentation of warnings options and arranges to suppress
warnings from autom4te --trace in a cleaner fashion.

See <https://lists.gnu.org/archive/html/autoconf-patches/2020-09/msg8.html>
for the rationale for merge_WARNINGS, which is not used in automake, but will
be in autoconf.

Zack Weinberg (3):
  New utility function Automake::ChannelDefs::merge_WARNINGS.
  Use WARNINGS=none to suppress warnings from autom4te runs.
  Update documentation of warnings options and strictness levels.

 bin/aclocal.in  |  19 ++-
 bin/automake.in |   7 +-
 doc/automake.texi   | 250 +++-
 lib/Automake/ChannelDefs.pm |  67 +-
 4 files changed, 208 insertions(+), 135 deletions(-)

-- 
2.28.0




[RFC PATCH 1/3] New utility function Automake::ChannelDefs::merge_WARNINGS.

2020-09-22 Thread Zack Weinberg
This function merges a list of warnings categories into the environment
variable WARNINGS, returning a new value to set it to.  The intended use
is in code of the form

{
  local $ENV{WARNINGS} = merge_WARNINGS ("this", "that");

  # run a command here with WARNINGS=this,that,etc
}

This is not actually used in automake, but will be in autoconf.

* lib/Automake/ChannelDefs.pm (merge_WARNINGS): New function.
---
 lib/Automake/ChannelDefs.pm | 67 +++--
 1 file changed, 65 insertions(+), 2 deletions(-)

diff --git a/lib/Automake/ChannelDefs.pm b/lib/Automake/ChannelDefs.pm
index b98191b4c..e9aaf2f80 100644
--- a/lib/Automake/ChannelDefs.pm
+++ b/lib/Automake/ChannelDefs.pm
@@ -63,7 +63,8 @@ BEGIN
 
 our @ISA = qw (Exporter);
 our @EXPORT = qw (_error   
- _warning _WARNINGS _warnings);
+ _warning _WARNINGS _warnings
+ _WARNINGS);
 
 =head2 CHANNELS
 
@@ -107,7 +108,7 @@ Warnings related to GNU Coding Standards.
 
 =item C
 
-Warnings about obsolete features (silent by default).
+Warnings about obsolete features.
 
 =item C
 
@@ -409,6 +410,68 @@ sub parse_warnings (@)
   switch_warning ($_werror ? 'error' : 'no-error');
 }
 
+=item C
+
+Merge the warnings categories in the environment variable C
+with the warnings categories in C<@CATEGORIES>, and return a new
+value for C.  Values in C<@CATEGORIES> take precedence.
+Use like this:
+
+local $ENV{WARNINGS} = merge_WARNINGS @additional_warnings;
+
+=cut
+
+sub merge_WARNINGS (@)
+{
+  my $werror = '';
+  my $all_or_none = '';
+  my %warnings;
+
+  my @categories = split /,/, $ENV{WARNINGS} || '';
+  push @categories, @_;
+
+  foreach (@categories)
+{
+  if (/^(?:no-)?error$/)
+{
+  $werror = $_;
+}
+  elsif (/^(?:all|none)$/)
+{
+  $all_or_none = $_;
+}
+  else
+{
+  # The character class in the second match group is ASCII \S minus
+  # comma.  We are generous with this because category values may come
+  # from WARNINGS and we don't want to assume what other programs'
+  # syntaxes for warnings categories are.
+  /^(no-|)([\w\[\]\/\\!"#$%&'()*+-.:;<=>?@^`{|}~]+)$/
+or die "Invalid warnings category: $_";
+  $warnings{$2} = $1;
+}
+}
+
+  my @final_warnings;
+  if ($all_or_none)
+{
+  push @final_warnings, $all_or_none;
+}
+  else
+{
+  foreach (sort keys %warnings)
+{
+  push @final_warnings, $warnings{$_} . $_;
+}
+}
+  if ($werror)
+{
+  push @final_warnings, $werror;
+}
+
+  return join (',', @final_warnings);
+}
+
 =item C
 
 Configure channels for strictness C<$STRICTNESS_NAME>.
-- 
2.28.0




[RFC PATCH 5/6] Update documentation related to warnings.

2020-09-22 Thread Zack Weinberg
This makes the Texinfo documentation consistent with the previous
changes.  --help output regarding warnings is already drawn directly
from ChannelDefs.pm and thus does not need to be updated.

* doc/autoconf.texi: Update all ‘invocation’ sections to describe
  -W/--warnings consistently, and to refer to m4_warn for the list
  of categories.
  (m4_warn): Document the complete current list of categories.
  (Reporting Messages): Delete section.
  (AC_DIAGNOSE, AC_WARNING, AC_FATAL): Move to Obsolete Macros.
---
 doc/autoconf.texi | 287 +-
 1 file changed, 128 insertions(+), 159 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 60407fc2..dea85e4a 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -495,7 +495,6 @@ Top
 
 * Macro Definitions::   Basic format of an Autoconf macro
 * Macro Names:: What to call your new macros
-* Reporting Messages::  Notifying @command{autoconf} users
 * Dependencies Between Macros::  What to do when macros depend on other macros
 * Obsoleting Macros::   Warning about old ways of doing things
 * Coding Style::Writing Autoconf macros @`a la Autoconf
@@ -1555,42 +1554,37 @@ autoconf Invocation
 Save output (script or trace) to @var{file}.  The file @option{-} stands
 for the standard output.
 
-@item --warnings=@var{category}
-@itemx -W @var{category}
+@item --warnings=@var{category}[,@var{category}...]
+@itemx -W@var{category}[,@var{category}...]
 @evindex WARNINGS
-Report the warnings related to @var{category} (which can actually be a
-comma separated list).  @xref{Reporting Messages}, macro
-@code{AC_DIAGNOSE}, for a comprehensive list of categories.  Special
-values include:
+Enable or disable warnings related to each @var{category}.
+@xref{m4_warn}, for a comprehensive list of categories.
+Special values include:
 
 @table @samp
 @item all
-report all the warnings
+Enable all categories of warnings.
 
 @item none
-report none
+Disable all categories of warnings.
 
 @item error
-treats warnings as errors
+Treat all warnings as errors.
 
 @item no-@var{category}
-disable warnings falling into @var{category}
+Disable warnings falling into @var{category}.
 @end table
 
-Warnings about @samp{syntax} are enabled by default, and the environment
-variable @env{WARNINGS}, a comma separated list of categories, is
-honored as well.  Passing @option{-W @var{category}} actually behaves as if
-you had passed @option{--warnings syntax,$WARNINGS,@var{category}}.  To
-disable the defaults and @env{WARNINGS}, and then
-enable warnings about obsolete constructs, use @option{-W
-none,obsolete}.
+The enviroment variable @env{WARNINGS} may also be set to a
+comma-separated list of warning categories to enable or disable.
+It is interpreted exactly the same way as the argument of
+@option{--warnings}, but unknown categories are silently ignored.
+The command line takes precedence; for instance, if @env{WARNINGS}
+is set to @code{obsolete}, but @option{-Wnone} is given on the
+command line, no warnings will be issued.
 
-@cindex Back trace
-@cindex Macro invocation stack
-Because @command{autoconf} uses @command{autom4te} behind the scenes, it
-displays a back trace for errors, but not for warnings; if you want
-them, just pass @option{-W error}.  @xref{autom4te Invocation}, for some
-examples.
+Some categories of warnings are on by default.
+Again, for details see @ref{m4_warn}.
 
 @item --trace=@var{macro}[:@var{format}]
 @itemx -t @var{macro}[:@var{format}]
@@ -1787,45 +1781,37 @@ autoreconf Invocation
 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
 Passed on to @command{autoconf} and @command{autoheader} internally.
 
-@item --warnings=@var{category}
-@itemx -W @var{category}
+@item --warnings=@var{category}[,@var{category}...]
+@itemx -W@var{category}[,@var{category}...]
 @evindex WARNINGS
-Report the warnings related to @var{category} (which can actually be a
-comma separated list).
+Enable or disable warnings related to each @var{category}.
+@xref{m4_warn}, for a comprehensive list of categories.
+Special values include:
 
 @table @samp
-@item cross
-related to cross compilation issues.
-
-@item obsolete
-report the uses of obsolete constructs.
-
-@item portability
-portability issues
-
-@item syntax
-dubious syntactic constructs.
-
 @item all
-report all the warnings
+Enable all categories of warnings.
 
 @item none
-report none
+Disable all categories of warnings.
 
 @item error
-treats warnings as errors
+Treat all warnings as errors.
 
 @item no-@var{category}
-disable warnings falling into @var{category}
+Disable warnings falling into @var{category}.
 @end table
 
-Warnings about @samp{syntax} are enabled by default, and the environment
-variable @env{WARNINGS}, a comma separated list of categories, is
-honored as well.  Passing @option{-W @var{category}} actually behaves as if
-you had passed @option{--warnings 

[RFC PATCH 2/6] New utility function Autom4te::ChannelDefs::merge_WARNINGS.

2020-09-22 Thread Zack Weinberg
This function merges a list of warnings categories into the environment
variable WARNINGS, returning a new value to set it to.  The intended use
is in code of the form

{
  local $ENV{WARNINGS} = merge_WARNINGS ("this", "that");

  # run a command here with WARNINGS=this,that,etc
}

This is not used yet, but will be in the next patch.

* lib/Autom4te/ChannelDefs.pm (merge_WARNINGS): New function.
---
 lib/Autom4te/ChannelDefs.pm | 65 -
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/lib/Autom4te/ChannelDefs.pm b/lib/Autom4te/ChannelDefs.pm
index 21f444b9..62e69323 100644
--- a/lib/Autom4te/ChannelDefs.pm
+++ b/lib/Autom4te/ChannelDefs.pm
@@ -63,7 +63,8 @@ BEGIN
 
 our @ISA = qw (Exporter);
 our @EXPORT = qw (_error   
- _warning _WARNINGS _warnings);
+ _warning _WARNINGS _warnings
+ _WARNINGS);
 
 =head2 CHANNELS
 
@@ -409,6 +410,68 @@ sub parse_warnings (@)
   switch_warning ($_werror ? 'error' : 'no-error');
 }
 
+=item C
+
+Merge the warnings categories in the environment variable C
+with the warnings categories in C<@CATEGORIES>, and return a new
+value for C.  Values in C<@CATEGORIES> take precedence.
+Use like this:
+
+local $ENV{WARNINGS} = merge_WARNINGS @additional_warnings;
+
+=cut
+
+sub merge_WARNINGS (@)
+{
+  my $werror = '';
+  my $all_or_none = '';
+  my %warnings;
+
+  my @categories = split /,/, $ENV{WARNINGS} || '';
+  push @categories, @_;
+
+  foreach (@categories)
+{
+  if (/^(?:no-)?error$/)
+{
+  $werror = $_;
+}
+  elsif (/^(?:all|none)$/)
+{
+  $all_or_none = $_;
+}
+  else
+{
+  # The character class in the second match group is ASCII \S minus
+  # comma.  We are generous with this because category values may come
+  # from WARNINGS and we don't want to assume what other programs'
+  # syntaxes for warnings categories are.
+  /^(no-|)([\w\[\]\/\\!"#$%&'()*+-.:;<=>?@^`{|}~]+)$/
+or die "Invalid warnings category: $_";
+  $warnings{$2} = $1;
+}
+}
+
+  my @final_warnings;
+  if ($all_or_none)
+{
+  push @final_warnings, $all_or_none;
+}
+  else
+{
+  foreach (sort keys %warnings)
+{
+  push @final_warnings, $warnings{$_} . $_;
+}
+}
+  if ($werror)
+{
+  push @final_warnings, $werror;
+}
+
+  return join (',', @final_warnings);
+}
+
 =item C
 
 Configure channels for strictness C<$STRICTNESS_NAME>.
-- 
2.28.0




[RFC PATCH 1/6] Manually sync ChannelDefs.pm from automake.

2020-09-22 Thread Zack Weinberg
ChannelDefs.pm *ought* to be kept in sync between automake and autoconf,
because it defines the set of valid -W options, and autoreconf assumes
that it can pass arbitrary -W options to all of the tools it invokes.
However, it isn’t covered by either project’s ‘make fetch’ and it hasn’t
actually *been* in sync for more than 17 years.

This patch manually brings over all of the changes made on the
automake side.  Once the complementary patch is applied by the
automake team, both versions of the file will be the same, and then we
can add it to the list in fetch.pl and not have this problem any more
in the future.

There are some user-visible consequences to bringing this file back
into sync.  The only one worth mentioning in NEWS is that the ‘obsolete’
category of warnings is now on by default.  This had quite a bit of
fallout throughout the testsuite.  There are also some new warning
categories that get mentioned in --help output, but we don’t actually
generate any warnings in those categories, so people using ‘-Wall’
won’t see any change.  More diagnostics are automatically tagged with
‘warning:’ or ‘error:’, which also had some fallout in the testsuite.
Finally, ‘-Werror’ no longer causes complaints about unknown warning
categories to be treated as hard errors.

Internally, there are some small API changes: ‘parse_warnings’ is no
longer usable as a ‘getopt’ callback function, and we now have a stub
Autom4te/Config.pm to match the automake code’s expectations.  (This
file *should* also be synced from automake by ‘make fetch’, but we
can’t quite do that yet because it’s a generated file and our build
system is not prepared to handle adding *two* directories to @INC when
running a not-yet-installed Perl script.  I plan to fix that after 2.70.)

As a side-effect of adding a Config.pm, ‘prog_error’ now says to
report the bug to bug-autoconf, not bug-automake.  If this is why we
mostly haven’t been using prog_error for internal errors, we can stop
avoiding it.  (I did not change anything to use prog_error in this
patch.)

* lib/Autom4te/ChannelDefs.pm: Merge from automake.
* lib/Autom4te/Config.pm: New file.
* lib/local.mk (dist_perllib_DATA): Add Autom4te/Config.pm.

* bin/autoconf.as: Update list of warning categories to match
  Autom4te::ChannelDefs::usage.
* bin/autoheader.in (@warnings): New global.
  (parse_args): Don’t use parse_warnings as a getopt callback.
  (main): Add warnings options from our command line to $autoconf.
  No need to turn on 'obsolete' warnings explicitly.
  No need to include "warning: " in warning messages.
* bin/autom4te.in (parse_args): Don’t use parse_warnings as a getopt callback.
  (main): No need to include "warning: " in warning messages.
* bin/autoreconf.in (parse_args): parse_warnings now takes only one argument.
* bin/autoupdate.in: Set WARNINGS=none in environment for all child processes.

* tests/local.at
  (AT_CHECK_M4): Handle `autom4te: error: /usr/bin/m4 ...` like
  `autom4te: /usr/bin/m4 ...`.
  (_AT_CHECK_AC_MACRO): Add AUTOCONF-FLAGS argument, passed to both
  autoconf and autoheader.
  (AT_CHECK_MACRO): Default AUTOCONF-FLAGS argument to empty.
  Pass that argument to autoheader as well as autoconf.
  (AT_CHECK_AU_MACRO): Expect a “macro ‘NAME’ is obsolete’ diagnostic
  on the first run of autoconf.  Pass -Wno-obsolete to autoconf on the
  second run, and to autoheader on both runs.

* tests/base.at
* tests/c.at
* tests/compile.at
* tests/m4sh.at
* tests/m4sugar.at
* tests/semantics.at
* tests/tools.at
* tests/torture.at:
  No need to pass -Wobsolete to autoconf.
  Pass -Wno-obsolete to autoheader where needed to avoid handling
  the same warning twice.
  Update various expectations for diagnostics to match behavior
  changes.

* tests/tools.at (autoupdating AU_ALIAS): Add an AC_CONFIG_HEADERS
  line to the test configure.ac to eliminate an unrelated diagnostic.
---
 NEWS|   3 +
 bin/autoconf.as |  21 +++--
 bin/autoheader.in   |  14 +--
 bin/autom4te.in |  10 ++-
 bin/autoreconf.in   |   2 +-
 bin/autoupdate.in   |   5 ++
 lib/Autom4te/ChannelDefs.pm | 172 
 lib/Autom4te/Config.pm  |  43 +
 lib/local.mk|   1 +
 tests/base.at   |   2 +-
 tests/c.at  |   2 +-
 tests/compile.at|   7 +-
 tests/local.at  |  48 +-
 tests/m4sh.at   |   2 +-
 tests/m4sugar.at|  25 +++---
 tests/semantics.at  |  34 +++
 tests/tools.at  |  54 +--
 tests/torture.at|   5 +-
 18 files changed, 332 insertions(+), 118 deletions(-)
 create mode 100644 lib/Autom4te/Config.pm

diff --git a/NEWS b/NEWS
index 72761730..9ee7dbec 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,9 @@ GNU Autoconf NEWS - User visible changes.
per-process temporary runtime files (such as pid files) into '/run'
instead of '/var/run'.
 
+** Warnings about 

[RFC PATCH 6/6] Autoupdate AC_{DIAGNOSE, FATAL, OBSOLETE, WARNING} and _AC_COMPUTE_INT.

2020-09-22 Thread Zack Weinberg
While working on the previous patches I noticed that all of these
macros are officially obsolete, but autoupdate doesn’t replace them.

_AC_COMPUTE_INT is easy to autoupdate.  AC_{DIAGNOSE,FATAL,WARNING}
require a little special handling because their replacements are
m4sugar macros, and autoupdate normally expands m4sugar macros as it
goes.  Fortunately, the same workaround as is used for AC_FOREACH can
be applied.  AC_OBSOLETE also needs that workaround, and cannot be
fully replaced automatically.

The bulk of the patch is removing internal uses of AC_DIAGNOSE.

* lib/autoconf/autoupdate.m4
* lib/autoconf/c.m4
* lib/autoconf/functions.m4
* lib/autoconf/general.m4
* lib/autoconf/headers.m4
* lib/autoconf/lang.m4
* lib/autoconf/status.m4
* lib/autoconf/types.m4
* tests/local.at
* tests/tools.at:
  Use, and/or refer to, m4_warn instead of AC_DIAGNOSE.

* lib/autoconf/general.m4 (_AC_COMPUTE_INT): Define using AU_DEFUN.
  (AC_DIAGNOSE, AC_FATAL, AC_WARNING): Autoupdate to m4_warn,
  m4_fatal, and m4_warn([syntax], [$1]) respectively, using the same
  paired AU_DEFUN/AC_DEFUN trick that is used for AC_FOREACH.
  (AC_OBSOLETE): Autoupdate to m4_warn([obsolete], [$1]) and advise
  hand-conversion to AU_DEFUN.

* lib/autoconf/autoupdate.m4 (AU_DEFUN): Tweak quoting so m4_warn([$3])
  is emitted into the edited configure.ac instead of being expanded at
  autoupdate time.

* tests/tools.at (autoupdating AC_FOREACH): Adjust grep expressions.
  (autoupdating AC_DIAGNOSE and AC_WARNING): New test.
  (autoupdating AC_FATAL): New test.
  (autoupdating AC_OBSOLETE): New test.
* tests/mktests.sh (ac_exclude_list, au_exclude_list):
  Exclude AC_DIAGNOSE, AC_FATAL, AC_FOREACH, AC_OBSOLETE, and AC_WARNING
  if not already excluded.
---
 NEWS   |  10 +++
 lib/autoconf/autoupdate.m4 |  14 ++--
 lib/autoconf/c.m4  |   2 +-
 lib/autoconf/functions.m4  |   8 +--
 lib/autoconf/general.m4|  78 +++---
 lib/autoconf/headers.m4|   8 +--
 lib/autoconf/lang.m4   |   2 +-
 lib/autoconf/specific.m4   |   2 +-
 lib/autoconf/status.m4 |   6 +-
 lib/autoconf/types.m4  |   4 +-
 tests/local.at |   2 +-
 tests/mktests.sh   |  10 +--
 tests/tools.at | 129 -
 13 files changed, 205 insertions(+), 70 deletions(-)

diff --git a/NEWS b/NEWS
index 9ee7dbec..8a8ac9f1 100644
--- a/NEWS
+++ b/NEWS
@@ -199,6 +199,16 @@ GNU Autoconf NEWS - User visible changes.
   diagnosed as obsolete, and replaced with AC_CONFIG_HEADERS by
   autoupdate.
 
+- The obsolete macros AC_DIAGNOSE, AC_FATAL, AC_WARNING, and
+  _AC_COMPUTE_INT are now replaced with modern equivalents by
+  autoupdate.
+
+- The macro AC_OBSOLETE is obsolete.  Autoupdate will replace it with
+  m4_warn([obsolete], [explanation]).  If possible, macros using
+  AC_OBSOLETE should be converted to use AU_DEFUN or AU_ALIAS instead,
+  which enables autoupdate to replace them, but this has to be done by
+  hand and is not always possible.
+
 - AC_FC_LINE_LENGTH now documents the maximum portable length of
   "unlimited" Fortran source code lines to be 250 columns, not 254.
 
diff --git a/lib/autoconf/autoupdate.m4 b/lib/autoconf/autoupdate.m4
index 056ef08f..109d8949 100644
--- a/lib/autoconf/autoupdate.m4
+++ b/lib/autoconf/autoupdate.m4
@@ -55,12 +55,14 @@ m4_define([AU_DEFINE], [])
 # and to update a configure.ac.
 # See the end of `autoupdate.in' for a longer description.
 m4_define([AU_DEFUN],
-[# This is what autoupdate's m4 run will expand.  It fires
-# the warning (with _au_warn_XXX), outputs it into the
-# updated configure.ac (with AC_DIAGNOSE), and then outputs
-# the replacement expansion.
+[# This is what autoupdate's m4 run will expand.  It fires the warning
+# (with _au_warn_XXX), outputs it into the updated configure.ac (with
+# m4_warn), and then outputs the replacement expansion.  We need extra
+# quotation around the m4_warn and dnl so they will be written
+# unexpanded into the updated configure.ac.
 AU_DEFINE([$1],
-[m4_ifval([$3], [_au_warn_$1([$3])AC_DIAGNOSE([obsolete], [$3])d[]nl
+[m4_ifval([$3], [_au_warn_$1([$3])[m4_warn([obsolete],
+[$3])dnl]
 ])dnl
 $2])
 
@@ -79,7 +81,7 @@ m4_define([_au_warn_$1], [])])
 # about autoupdate's warning because that contains
 # information on what to do *after* running autoupdate.
 AC_DEFUN([$1],
-[AC_DIAGNOSE([obsolete], [The macro `$1' is obsolete.
+[m4_warn([obsolete], [The macro `$1' is obsolete.
 You should run autoupdate.])dnl
 $2])])
 
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index fe6aa2b6..be5e4148 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1690,7 +1690,7 @@ dnl the user did not specify a config header but is 
relying on the
 dnl default behavior for universal builds.
  m4_default([$4],
[AC_CONFIG_COMMANDS_PRE([m4_ifset([AH_HEADER], [],
-[AC_DIAGNOSE([obsolete],
+[m4_warn([obsolete],
   [AC_C_BIGENDIAN should be used with 

[RFC PATCH 0/6] Work around autoconf/automake warnings skew

2020-09-22 Thread Zack Weinberg
autoreconf runs a bunch of subsidiary tools, and is expected to pass
along various command-line settings, such as those controlling
warnings.  It has historically done this via the command line.
However, not all of the tools recognize the same set of command-line
warnings options.  There’s an existing check for whether aclocal and
automake understand ‘--warnings’ at all, but it currently assumes that
automake will accept the same set of warnings *categories* that
autoconf does.  This hasn’t actually been true for many years
and is known to cause problems; see the discussion starting at
<https://lists.gnu.org/archive/html/autoconf/2020-09/msg0.html>.

This patch set makes the changes on autoconf’s side required to bring
ChannelDefs.pm back into sync between autoconf and automake, which
makes the set of categories consistent for future releases.  It also
implements a workaround in autoreconf, to avoid problems with
inconsistent *installed* versions of autoconf and automake: we pass
warnings options to subsidiary tools using the WARNINGS environment
variable instead of on the command line.  Unsupported categories in
WARNINGS have always been ignored, so the problem is eliminated.

I manually verified that, with the combination of trunk autoconf and
released automake 1.16, one can run autoreconf -Werror,cross without
any problems.  With autoreconf from 2.69, by contrast, aclocal will
bomb out.

The main thing I want to discuss before merging these patches is the
location of the new Perl function merge_WARNINGS.  I put it in
ChannelDefs.pm because that is where all the other code relating to
WARNINGS is, but it’s only used in autoreconf, so there’s an argument
for putting it in autoreconf instead, if only so we can modify it in
the future without having to go through automake.

Side effects include:

 - The ‘obsolete’ category of warnings is now on by default
   (automake has already made this change).
 - More of autoreconf’s subsidiary tools may generate warnings now.
   Specifically, we were not passing -W options to autopoint,
   libtoolize, intltool, or gtkdocize, but they will all see the
   WARNINGS environment variable.  I don’t know if any of them
   pay attention to it.
 - All of the commands that run autoconf or autom4te in --trace mode
   also set WARNINGS=none in the environment.  This means, most
   visibly, that autoheader no longer repeats autoconf’s warnings.
 - We are now autoupdating a bunch of obsolete diagnostics-related
   macros.  This is just something I happened to notice because I was
   messing with code near them.

N.B. I have not yet added ChannelDefs.pm to the list of files to sync
from automake.  I will do that in a separate commit after all the dust
settles from this patchset.

zw
-- 

Zack Weinberg (6):
  Manually sync ChannelDefs.pm from automake.
  New utility function Autom4te::ChannelDefs::merge_WARNINGS.
  Disable all warnings when running autoconf as a subprocess.
  Use WARNINGS to pass down warnings options from autoreconf.
  Update documentation related to warnings.
  Autoupdate AC_{DIAGNOSE,FATAL,OBSOLETE,WARNING} and _AC_COMPUTE_INT.

 NEWS|  13 ++
 bin/autoconf.as |  21 ++-
 bin/autoheader.in   |  31 ++--
 bin/autom4te.in |  10 +-
 bin/autoreconf.in   |  87 ++-
 bin/autoscan.in |   5 +-
 bin/autoupdate.in   |   5 +
 doc/autoconf.texi   | 287 
 lib/Autom4te/ChannelDefs.pm | 237 -
 lib/Autom4te/Config.pm  |  43 ++
 lib/autoconf/autoupdate.m4  |  14 +-
 lib/autoconf/c.m4   |   2 +-
 lib/autoconf/functions.m4   |   8 +-
 lib/autoconf/general.m4 |  78 +-
 lib/autoconf/headers.m4 |   8 +-
 lib/autoconf/lang.m4|   2 +-
 lib/autoconf/specific.m4|   2 +-
 lib/autoconf/status.m4  |   6 +-
 lib/autoconf/types.m4   |   4 +-
 lib/autom4te.in |   1 -
 lib/local.mk|   1 +
 tests/base.at   |   2 +-
 tests/c.at  |   2 +-
 tests/compile.at|   7 +-
 tests/local.at  |  48 +++---
 tests/m4sh.at   |   2 +-
 tests/m4sugar.at|  25 ++--
 tests/mktests.sh|  10 +-
 tests/semantics.at  |  48 +++---
 tests/tools.at  | 179 +-
 tests/torture.at|  64 ++--
 31 files changed, 831 insertions(+), 421 deletions(-)
 create mode 100644 lib/Autom4te/Config.pm

-- 
2.28.0




[RFC PATCH 3/6] Disable all warnings when running autoconf as a subprocess.

2020-09-22 Thread Zack Weinberg
autoheader and autoscan both run autoconf in trace mode, and
autoheader makes a point of passing down the warnings options.
This means autoheader prints warnings that a regular invocation
of autoconf would also print, so in the common case where both
are being run by autoreconf, the warnings are duplicated.
autoscan doesn’t pass down warnings options but it _does_ leave
the WARNINGS environment variable alone, which means it may issue
completely spurious warnings because the configure script is still
under construction.

Change this so that both programs disable all warnings for the
subsidiary invocation of autoconf, by not passing any warnings
options themselves, and by setting the WARNINGS environment variable
to “none” for the subprocess.  For this to work correctly, the
‘args: --warnings syntax’ line has to be removed from autom4te.cfg
(m4sugar section).  Since syntax warnings are on by default anyway,
the sole effect of this is to allow WARNINGS=none to turn off syntax
warnings.

The test suite changes are all to remove expectations of duplicate
diagnostics from autoheader.

* bin/autoheader.in: Do not pass warnings options down to subsidiary
  autoconf, and set WARNINGS=none in the environment for that process.
* bin/autoscan.in: Set WARNINGS=none in the environment for subsidiary
  autoconf.
* lib/autom4te.in (M4sugar): Remove ‘--warnings syntax’.
* tests/semantics.at, tests/torture.at: No longer expect various
  diagnostics from autoheader as well as autoconf.
---
 bin/autoheader.in  | 19 +++
 bin/autoscan.in|  5 -
 lib/autom4te.in|  1 -
 tests/semantics.at | 14 +-
 tests/torture.at   | 12 ++--
 5 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/bin/autoheader.in b/bin/autoheader.in
index 6b02cbb8..1f3af9f1 100644
--- a/bin/autoheader.in
+++ b/bin/autoheader.in
@@ -166,7 +166,6 @@ END
 my $autoconf = "'$autom4te' --language=autoconf ";
 $autoconf .= join (' --include=', '', map { shell_quote ($_) } @include);
 $autoconf .= join (' --prepend-include=', '', map { shell_quote ($_) } 
@prepend_include);
-$autoconf .= join (' --warnings=', '', map { shell_quote ($_) } @warnings);
 $autoconf .= ' --debug' if $debug;
 $autoconf .= ' --force' if $force;
 $autoconf .= ' --verbose' if $verbose;
@@ -178,13 +177,17 @@ $autoconf .= ' --verbose' if $verbose;
 # Source what the traces are trying to tell us.
 verb "$me: running $autoconf to trace from $ARGV[0]";
 my $quoted_tmp = shell_quote ($tmp);
-xsystem ("$autoconf"
-# If you change this list, update the
-# 'Autoheader-preselections' section of autom4te.in.
-. ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= \'"\'"\'$1\'"\'"\';\''
-. ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = 
\'"\'"\'$2\'"\'"\';\''
-. ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} = 
1;\''
-. " " . shell_quote ($ARGV[0]) . " >$quoted_tmp/traces.pl");
+{
+  # Suppress all warnings from the subsidiary autoconf invocation.
+  local $ENV{WARNINGS} = 'none';
+  xsystem ("$autoconf"
+   # If you change this list, update the
+   # 'Autoheader-preselections' section of autom4te.in.
+   . ' --trace AC_CONFIG_HEADERS:\'$$config_h ||= 
\'"\'"\'$1\'"\'"\';\''
+   . ' --trace AH_OUTPUT:\'$$verbatim{\'"\'"\'$1\'"\'"\'} = 
\'"\'"\'$2\'"\'"\';\''
+   . ' --trace AC_DEFINE_TRACE_LITERAL:\'$$symbol{\'"\'"\'$1\'"\'"\'} 
= 1;\''
+   . " " . shell_quote ($ARGV[0]) . " >$quoted_tmp/traces.pl");
+}
 
 local (%verbatim, %symbol);
 debug "$me: 'do'ing $tmp/traces.pl:\n" . `sed 's/^/| /' $quoted_tmp/traces.pl`;
diff --git a/bin/autoscan.in b/bin/autoscan.in
index 99df4929..658a7980 100644
--- a/bin/autoscan.in
+++ b/bin/autoscan.in
@@ -591,7 +591,10 @@ sub check_configure_ac ($)
 join (' --trace=', '',
  uniq (sort (map { s/\(.*//; $_ } keys %needed_macros)));
 
-  verb "running: $autoconf $trace_option $configure_ac";
+  # Suppress all warnings from the subsidiary autoconf invocation.
+  local $ENV{WARNINGS} = 'none';
+
+  verb "running: WARNINGS=none $autoconf $trace_option $configure_ac";
   my $traces =
 new Autom4te::XFile "$autoconf $trace_option $configure_ac |";
 
diff --git a/lib/autom4te.in b/lib/autom4te.in
index 3c787972..4f1f4799 100644
--- a/lib/autom4te.in
+++ b/lib/autom4te.in
@@ -169,5 +169,4 @@ end-language: "M4sh"
 begin-language: "M4sugar"
 args: --prepend-include '@pkgdatadir@'
 args: m4sugar/m4sugar.m4f
-args: --warnings syntax
 end-language: "M4sugar"
diff --git a/tests/semantics.at b/tests/semantics.at
index e7dd7c5a..ab3cea7c 100644
--- a/tests/semantics.at
+++ b/tests/semantics.at
@@ -214,11 +214,7 @@ AT_CHECK_AUTOHEADER([], [
   HAVE_FOPEN
   HAVE_FPRINTF
   HAVE_PRINTF
-], [], [],
-[[configure.ac:9: warning: AC_REPLACE_FUNCS($funcs): you should use literals
-functions.m4: AC_REPLACE_FUNCS is expanded from...
-configure.ac:9: the top level
-]])
+])
 AT_CHECK_CONFIGURE
 AT_CHECK_ENV
 

[RFC PATCH 2/3] Use WARNINGS=none to suppress warnings from autom4te runs.

2020-09-22 Thread Zack Weinberg
aclocal uses autom4te in trace mode to scan configure.ac for macros whose
definition is not yet available.  It has a kludge to prevent this from
producing spurious warnings, but a cleaner, fully backward compatible, way to
get the same effect is to set WARNINGS=none in the environment and not pass
down any -W options.  (This is better than passing -Wnone on the command line
because it automatically inherits to any subprocesses started by autom4te.)

Perl’s ‘local’ feature can be used to make the enviironment variable setting
temporary, reverting to the previous value when we exit the function.

automake also runs autom4te (technically autoconf) in trace mode; warnings
from this invocation will not be *spurious*, but in the common case where
the person running automake is going to run autoconf next, they will be
duplicated.  Therefore, make the same change to automake.

* bin/aclocal.in (trace_used_macros)
* bin/automake.in (scan_autoconf_traces):
  Use “local $ENV{WARNINGS}='none'” to suppress warnings from autom4te.
---
 bin/aclocal.in  | 19 ---
 bin/automake.in |  7 ++-
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/bin/aclocal.in b/bin/aclocal.in
index 42e8d839a..ca2f96324 100644
--- a/bin/aclocal.in
+++ b/bin/aclocal.in
@@ -762,22 +762,19 @@ sub trace_used_macros ()
   my %files = map { $map{$_} => 1 } keys %macro_seen;
   %files = strip_redundant_includes %files;
 
-  # When AC_CONFIG_MACRO_DIRS is used, avoid possible spurious warnings
-  # from autom4te about macros being "m4_require'd but not m4_defun'd";
-  # for more background, see:
-  # https://lists.gnu.org/archive/html/autoconf-patches/2012-11/msg4.html
-  # as well as autoconf commit 'v2.69-44-g1ed0548', "warn: allow aclocal
-  # to silence m4_require warnings".
-  my $early_m4_code .= "m4_define([m4_require_silent_probe], [-])";
+  # Suppress all warnings from this invocation of autom4te.
+  # In particular we want to avoid spurious warnings about
+  # macros being "m4_require'd but not m4_defun'd" because
+  # aclocal.m4 is not yet available.
+  local $ENV{WARNINGS} = 'none';
 
   my $traces = ($ENV{AUTOM4TE} || '@am_AUTOM4TE@');
   $traces .= " --language Autoconf-without-aclocal-m4 ";
-  $traces = "echo '$early_m4_code' | $traces - ";
 
   # Support AC_CONFIG_MACRO_DIRS also with older autoconf.
   # Note that we can't use '$ac_config_macro_dirs_fallback' here, because
-  # a bug in option parsing code of autom4te 2.68 and earlier will cause
-  # it to read standard input last, even if the "-" argument is specified
+  # a bug in option parsing code of autom4te 2.68 and earlier would cause
+  # it to read standard input last, even if the "-" argument was specified
   # early.
   # FIXME: To be removed in Automake 2.0, once we can assume autoconf
   #2.70 or later.
@@ -807,7 +804,7 @@ sub trace_used_macros ()
   # characters (like newlines).
   (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen)));
 
-  verb "running $traces $configure_ac";
+  verb "running WARNINGS=$ENV{WARNINGS} $traces $configure_ac";
 
   my $tracefh = new Automake::XFile ("$traces $configure_ac |");
 
diff --git a/bin/automake.in b/bin/automake.in
index 67b729045..a88b835a5 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -5249,6 +5249,11 @@ sub scan_autoconf_traces
sinclude => 1,
  );
 
+  # Suppress all warnings from this invocation of autoconf.
+  # The user is presumably about to run autoconf themselves
+  # and will see its warnings then.
+  local $ENV{WARNINGS} = 'none';
+
   my $traces = ($ENV{AUTOCONF} || '@am_AUTOCONF@') . " ";
 
   # Use a separator unlikely to be used, not ':', the default, which
@@ -5257,8 +5262,8 @@ sub scan_autoconf_traces
   map { "--trace=$_" . ':\$f:\$l::\$d::\$n::\${::}%' }
   (keys %traced));
 
+  verb "running WARNINGS=$ENV{WARNINGS} $traces";
   my $tracefh = new Automake::XFile ("$traces $filename |");
-  verb "reading $traces";
 
   @cond_stack = ();
   my $where;
-- 
2.28.0




Re: doc: Mention two more shell portability problems

2020-09-18 Thread Zack Weinberg
I verified both of these behaviors and merged the patch, with two
slight changes to the text:

 - it is specifically Solaris 10 /bin/sh that executes redirected
compound commands in a subshell; ksh (aka /usr/xpg4/bin/sh) doesn't.
 - the latest version of dash also doesn't support file descriptors
larger than 9, so I took out the version number

zw



Re: [PATCH] AC_LANG_INT_SAVE: Modernize function declarators (C89 and above).

2020-08-05 Thread Zack Weinberg
On Wed, Aug 5, 2020 at 1:32 PM Vincent Lefevre  wrote:
>
> On 2020-08-05 07:24:38 -0700, Paul Eggert wrote:
> > On 8/5/20 3:59 AM, Vincent Lefevre wrote:
> > > This allows one to avoid a failure with AC_COMPUTE_INT when using
> > > the -Werror=old-style-definition GCC option.
> >
> > Why is this needed? Telling 'configure' to use -Werror has never worked, for
> > lots of other reasons.
>
> With MPFR, it works after applying this patch.

+1 from me regardless -- we should be phasing out the use of pre-ANSI
constructs in autoconf's generated C snippets, and this is as good a
place to start as any.

zw



Re: [PATCH] Use just-built utilities for help2man rule

2020-07-15 Thread Zack Weinberg
On Wed, Jul 15, 2020 at 7:57 AM Andreas Schwab  wrote:
> -   
> PATH="./tests$(PATH_SEPARATOR)$(top_srcdir)/build-aux$(PATH_SEPARATOR)$$PATH";
>  \
> +   
> PATH="bin$(PATH_SEPARATOR)./tests$(PATH_SEPARATOR)$(top_srcdir)/build-aux$(PATH_SEPARATOR)$$PATH";
>  \

This bypasses the wrappers installed in ./tests and therefore causes
each just-built executable to be run *without* the options pointing it
at the matching, not-yet-installed, .m4 and .m4f files.  This may be
harmless in this case since we're (I presume) only running the
executables in --help mode, but it's not correct in general and I
don't want to give future hackers reading the Makefiles the wrong
impression.

Under normal circumstances, there should always be a wrapper in
./tests for each executable in ./bin.  Exactly what did you do that
made you think this patch was necessary?  Please be excruciatingly
detailed.

zw



Re: [PATCH] Use just-built utilities for help2man rule

2020-07-15 Thread Zack Weinberg
On Wed, Jul 15, 2020 at 10:13 AM Andreas Schwab  wrote:
> On Jul 15 2020, Zack Weinberg wrote:
>
> > Under normal circumstances, there should always be a wrapper in
> > ./tests for each executable in ./bin.
>
> There are no dependencies.

OK, want to write a patch to fix *that*?

zw



Re: [PATCH] AS_INIT: don't encode full path

2020-07-04 Thread Zack Weinberg
On Fri, Jul 3, 2020 at 8:42 PM Luke Mewburn  wrote:
>
> Fix AS_INIT to use the basename of __file__ instead of the full path.
> Allows for reproducible builds.

I like the idea here, but I think the patch isn't quite ready yet.
Most importantly, please write a test for the testsuite to ensure that
this doesn't get broken accidentally in the future.  Second, there
should be a comment in m4sh.m4 explaining that we are taking the
basename of __file__ so that the path to the source directory is not
embedded in the output file.  Third, a small tweak for your regular
expression: it should be "^.*/\([^/]*\)$" instead of "^.*/\(.*)".  The
latter relies too much on the particular greediness behavior of M4's
regexp implementation.

zw



Re: [PATCH] Revert 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)'

2020-07-16 Thread Zack Weinberg
On Thu, Jul 16, 2020 at 7:21 AM Ross Burton  wrote:
>
> Commit 8173e5, 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)',
> causes AC_PROG_LEX to always fail when searching for a lex library.

Before we give up on this patch I'd like to understand the conditions
under which it fails.  I did test it extensively on my computer, with
several different permutations of libl.{a,so} and libfl.{a,so}
available.  It would help if you could tell me as much as possible of
the following:

- the config.log from a configure invocation where AC_PROG_LEX failed
- where I can find the configure.ac from which that configure script
was generated
- the operating system where you observed AC_PROG_LEX to fail
- the shell used to execute the configure script
- whether you have original lex or flex or both, and the versions of each
- the output of `find /usr \( -name libl\* -o -name libfl\* \) -ls`

Thanks,
zw



Re: [PATCH] Revert 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)'

2020-07-16 Thread Zack Weinberg
On Thu, Jul 16, 2020 at 9:46 AM Ross Burton  wrote:
>
> On Thu, 16 Jul 2020 at 14:08, Zack Weinberg  wrote:
> > > Commit 8173e5, 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)',
> > > causes AC_PROG_LEX to always fail when searching for a lex library.
> >
> > Before we give up on this patch I'd like to understand the conditions
> > under which it fails.
>
> Agreed.  I admit that the revert was a way of getting attention, I
> filed a bug at https://savannah.gnu.org/support/index.php?110269 with
> further details.

Bother.  This regression is actually the behavior *intended* by the
submitter of the original patch (see
https://savannah.gnu.org/support/index.php?109320).  Formerly, if
there was no libl.a nor libfl.a available at all, configure would say
"none needed" even though its test program (which uses yywrap without
providing a definition) failed to link.  They wanted it to fail
instead.

I presume that gdbm, flex, and gmp provide a definition of yywrap
themselves, so they don't actually *need* lib{,f}l.a.

> In Flex isn't libfl.so only needed if you want to turn a generated parser 
> into a stand-alone binary for testing?

It also provides a fallback definition of yywrap.

Clearly we need to preserve compatibility with these existing autoconf
scripts, and I would guess that programs that define yywrap themselves
are much more common than those that use the fallback, which is not
that useful (all it does is return 1, causing the scanner to stop).  I
propose to make the following additional changes, instead of reverting
the patch:

 - Change the conftest.l used by _AC_PROG_LEX_YYTEXT_DECL so that it
defines yywrap itself (it already defines main).  Thus, LEXLIB will
only be set to -ll or -lfl if there's something in there *besides*
yywrap and main that the generated scanner needs.  Document this.

 - Add a new macro, tentatively AC_FUNC_YYWRAP([action-if-not-found]),
that tries to find a definition of yywrap in libl and libfl, sets
LEXLIB accordingly, and failing that executes action-if-not-found,
which defaults to AC_LIBOBJ([yywrap]).

What do you think?

zw



Re: [PATCH] Revert 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)'

2020-07-16 Thread Zack Weinberg
On Thu, Jul 16, 2020 at 1:55 PM Ross Burton  wrote:
> On Thu, 16 Jul 2020 at 18:51, Paul Eggert  wrote:
>>
>> On 7/16/20 10:34 AM, Ross Burton wrote:
>> > Wouldn't that break cross-compilation where a host flex is present but
>> > target libfl isn't?  That case worked previously and should work fine,
>> > as libfl isn't actually that useful.
>>
>> That shouldn't be a problem when building from tarballs, as flex shouldn't be
>> needed then and the patch is a win because it prevents the build from failing
>> unnecessarily. However, it could be a problem when building from Git
>> repositories where you need flex but may well not need the library.
>>
>> So I installed the attached patch, which implements Zack's first suggestion. 
>> I'm
>> being somewhat bold in installing here; feel free to comment and suggest
>> improvements (or suggest I revert :-).
>
> I suggest you revert and take my patch. :)
>
> I can’t actually find any projects that need libfl.so so this will continue 
> to break all cross compilation where a target flex isn’t around.

Can we slow down a bit please?  I had written out a patch (basically
equivalent to what's now in trunk) and I am in the process of setting
up a cross-compilation environment to validate the fix for certain,
but this is going to take several hours.

I believe that what's in trunk now should work fine for
cross-compilation of programs that don't require yywrap, even if there
is no target libfl, even for source tarballs that don't ship lex.yy.c,
as long as the flex program is available in the build environment.  If
that's not the scenario you're talking about, Ross, please clarify,
but I don't see how a tarball that doesn't ship the generated scanner
could ever have worked with no flex at all.

zw



Re: [PATCH] Revert 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)'

2020-07-16 Thread Zack Weinberg
On Thu, Jul 16, 2020 at 2:47 PM Ross Burton  wrote:
> On Thu, 16 Jul 2020 at 19:41, Zack Weinberg  wrote:
> > Can we slow down a bit please?  I had written out a patch (basically
> > equivalent to what's now in trunk) and I am in the process of setting
> > up a cross-compilation environment to validate the fix for certain,
> > but this is going to take several hours.
> >
> > I believe that what's in trunk now should work fine for
> > cross-compilation of programs that don't require yywrap, even if there
> > is no target libfl, even for source tarballs that don't ship lex.yy.c,
> > as long as the flex program is available in the build environment.  If
> > that's not the scenario you're talking about, Ross, please clarify,
> > but I don't see how a tarball that doesn't ship the generated scanner
> > could ever have worked with no flex at all.
>
> Build-testing current master now. Will report back later: I love Yocto
> but it is annoying to work on something like autoconf as that causes a
> toolchain rebuild...

Thanks for testing.  I will proceed with my own tests in parallel.

I pushed another change but it just revises the manual section for
AC_PROG_LEX some more.

zw



Re: [PATCH] Revert 'Fix logic error in _AC_PROG_LEX_YYTEXT_DECL (#109320)'

2020-07-16 Thread Zack Weinberg
On Thu, Jul 16, 2020 at 8:50 PM Paul Eggert  wrote:
> On 7/16/20 11:40 AM, Zack Weinberg wrote:
> > I believe that what's in trunk now should work fine for
> > cross-compilation of programs that don't require yywrap
>
> I thought so too, but after eyeballing the trunk a bit I noticed a shell
> portability bug in the recently-added AC_PROG_LEX code. I then found a couple
> more instances of the same bug elsewhere in Autoconf (in rarely-executed 
> code, I
> think).
>
> The problem is that constructs like ${ac_lib:-none needed} don't conform to
> POSIX, as POSIX requires that the stuff after the :- be a single shell word.
> (The next time I meet Steve Bourne I want to give him an earfull)

Aaaargh.  I thought I knew all these traps by now, but this one I'd
never encountered before.

> and would like to also install the attached patch to fix the code bugs. I have
> held off installing this latter patch, though, as I don't want to get in the 
> way
> of whatever testing you're doing.

Go ahead and install, I can check out the older revision for testing.
(Still waiting for cross compilers to build. :-/ )

However:

+for ac_cv_lib_lex in 'none needed' -lfl -ll 'not found'; do
+  case $ac_cv_lib_lex in
+'none needed') ;;
+'not found') break;;
+*) LIBS="$ac_lib $ac_save_LIBS";;
+  esac

Shouldn't this be LIBS="$ac_cv_lib_lex $ac_save_LIBS" now?

zw



Re: [PATCH] AS_INIT: don't encode full path

2020-07-05 Thread Zack Weinberg
On Sun, Jul 5, 2020 at 12:13 AM Luke Mewburn  wrote:
>
> I've updated the patch to address your comments:
> 1) Added a testsuite.
> 2) Added the comment.
> 3) Improved the regex. (Thanks for the heads up about M4 greedy regex.)

Thanks for the quick reply!  I adjusted the wording of the comment a
little and pushed this change.  It doesn't need a copyright assignment
by itself, but we would need one to take any more changes from you, so
if you plan to do any more work on Autoconf, it would be a good idea
to start on the paperwork now.

Was this the only thing that needed changing in Autoconf to support
reproducibility?

zw



Re: [PATCH] general: support CONFIG_SITE being a list of entries

2020-11-11 Thread Zack Weinberg
On Wed, Nov 11, 2020 at 8:33 AM Ross Burton  wrote:
>
> Instead of treating CONFIG_SITE as a single path, treat it as a
> space-separated list of paths and load them in order.

Thanks.  This is simple enough that I don't see any reason not to
merge it for 2.70, but could you also update the documentation?
("Site Defaults" section of doc/autoconf.texi.)

zw



Re: [PATCH v2] general: support CONFIG_SITE being a list of entries

2020-11-11 Thread Zack Weinberg
On Wed, Nov 11, 2020 at 11:04 AM Ross Burton  wrote:
>
> Instead of treating CONFIG_SITE as a single path, treat it as a
> space-separated list of paths and load them in order.

Merged with minor adjustments as
996f608165814d578bdcb0ab2f3382edb8918690, thank you again.

zw



[PATCH 2/2] Improve handling of missing aux scripts (autoreconf)

2020-10-20 Thread Zack Weinberg
Make ‘autoreconf --install’ add config.sub, config.guess, and
install-sh to the source tree when necessary.  This is only relevant
for packages that don’t use Automake, because ‘automake --add-missing’
already adds these scripts to the source tree, but apparently there
are plenty of packages out there that don’t use Automake, didn’t need
config.{sub,guess} with autoconf 2.69, and do need them with 2.70.
Such packages will need to have their equivalent of ‘make dist’
manually updated to ship the new files, of course.

This patch also has ‘autoreconf’ issue an error if aux files are
missing and ‘--install’ *wasn’t* used, or if --install *was* used but
could not install all the missing files.  This error is more likely to
be caught by maintainers than the configure-time error added in the
previous patch.  It is not currently practical to make autoconf itself
issue this error message, because of how the autoconf wrapper script
is different from all the other wrapper scripts.  Also, autoreconf
runs automake *after* autoconf, so we’d get spurious errors from
packages that do use automake.

I will commit these patches tomorrow afternoon if I don't hear any
comments by then.

zw

* bin/autoreconf.in ($buildauxdir): New package global, initialized
  to $pkgdatadir/build-aux, or to $ENV{autom4te_buildauxdir} if that’s set.
  (find_missing_aux_files, can_install_aux_files, try_install_aux_files)
  (install_aux_file, make_executable): New subs.
  (autoreconf_current_directory): Trace AC_REQUIRE_AUX_FILE.
  After running all tools that might install aux files, try to
  install aux files ourself if --install was given.
  After that, report on any that are still missing.
* lib/autom4te.in (Autoreconf-preselections): Add AC_REQUIRE_AUX_FILE.
  Make list order consistent with list order in autoreconf.in.
* tests/wrapper.as: Set autom4te_buildauxdir to point to location of
  config.guess, config.sub, and install-sh within the source tree.

* lib/local.mk: Install config.guess, config.sub, and install-sh
  into $(pkgdatadir)/build-aux.

* doc/autoconf.texi: Document that autoreconf can now install
  config.guess, config.sub, and install-sh itself without help from
  automake, but packages not using automake will need to arrange for
  tarball distribution of these files by hand.

* tests/torture.at (Missing auxiliary files): Test autoreconf as well.
---
 NEWS  |  17 ++--
 bin/autoreconf.in | 192 --
 doc/autoconf.texi |  47 
 lib/autom4te.in   |   5 +-
 lib/local.mk  |  10 +++
 tests/torture.at  |  58 ++
 tests/wrapper.as  |   4 +-
 7 files changed, 303 insertions(+), 30 deletions(-)

diff --git a/NEWS b/NEWS
index 1883faab..42095344 100644
--- a/NEWS
+++ b/NEWS
@@ -55,11 +55,18 @@ GNU Autoconf NEWS - User visible changes.
   when your configure script is run, even if you have no intention of
   ever cross-compiling your program.
 
-  If you are using Automake, the auxiliary scripts your configure script
-  needs will be added to your source tree by ‘autoreconf --install’ or
-  ‘automake --add-missing’, and will be automatically included in your
-  distribution tarball.  If you are not using Automake, you will need
-  to add them yourself.  See the “Input” section of the manual for
+  autoreconf will issue an error if any auxiliary scripts are needed but
+  cannot be found.  (It is not currently possible to make autoconf
+  itself issue this error.)
+
+  ‘autoreconf --install’ will add ‘config.sub’, ‘config.guess’, and
+  ‘install-sh’ to your source tree if they are needed.  If you are
+  using Automake, scripts added to your tree by ‘autoreconf --install’
+  will automatically be included in the tarball produced by ‘make dist’;
+  otherwise, you will need to arrange for them to be distributed
+  yourself.
+
+  See the “Input” section of the manual for more detail, including
   where to get the auxiliary scripts that may be needed by autoconf macros.
 
 *** Older versions of automake and aclocal (< 1.8) are no longer supported.
diff --git a/bin/autoreconf.in b/bin/autoreconf.in
index ba08c6ac..2d427155 100644
--- a/bin/autoreconf.in
+++ b/bin/autoreconf.in
@@ -28,11 +28,14 @@ use 5.006;
 use strict;
 use warnings FATAL => 'all';
 
+my $buildauxdir;
 BEGIN
 {
   my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
   unshift @INC, $pkgdatadir;
 
+  $buildauxdir = $ENV{'autom4te_buildauxdir'} || $pkgdatadir . '/build-aux';
+
   # Override SHELL.  On DJGPP SHELL may not be set to a shell
   # that can handle redirection and quote arguments correctly,
   # e.g.: COMMAND.COM.  For DJGPP always use the shell that configure
@@ -42,6 +45,8 @@ BEGIN
 
 # Do not use Cwd::chdir, since it might hang.
 use Cwd qw (cwd);
+use File::Copy qw (copy);
+use File::Temp ();
 
 use Autom4te::ChannelDefs;
 use Autom4te::Channels;
@@ -244,6 +249,146 @@ sub parse_args ()
 }
 
 
+## --- ##
+## Handling of aux files.  ##
+## 

RFC: Autotest: add official way to execute code before all/each test.

2020-10-28 Thread Zack Weinberg
Currently, there isn’t any documented way for an Autotest testsuite to
add custom code to be run either right before the main driver loop, or
at the point of each AT_SETUP.  For instance, there’s no good place to
put environment variable sanitization that should apply to the entire
testsuite (but isn’t universally relevant), or shell function
definitions to be used by custom test macros.

Autoconf’s test suite is poking shell functions directly into the
PREPARE_TESTS diversion, and doing environment variable sanitization
in each individual test.  Both of these are obviously undesirable.

This patch adds three new AT_* macros that can be used to do these
things in an officially-supported way: AT_PREPARE_TESTS adds code to
be run right before the main driver loop, AT_PREPARE_EACH_TEST adds
code to be run at the beginning of each test, and AT_TEST_HELPER_FN
defines a shell function that will be available to each test.  In
Autoconf’s test suite, I use AT_PREPARE_TESTS to factor out
environment variable sanitization that *ought* to apply across the
board, and AT_TEST_HELPER_FN for the helper function used by
AT_CHECK_ENV.

(This fixes the testsuite bug reported by Jannick at
https://lists.gnu.org/archive/html/autoconf/2020-10/msg00052.html .)

Comments requested particularly on the names and implementations of
the new macros.  Also, it would be nice to have an example of when
AT_PREPARE_EACH_TEST is useful, but I didn’t find one in the autoconf
test suite.

This patch is available from the zack/autotest-new-hooks branch on savannah git.

zw
From ff49cfa697466da3bbce6b740c228fe84831c174 Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Wed, 28 Oct 2020 17:04:22 -0400
Subject: [PATCH] Autotest: add official way to execute code before all/each
 test.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently, there isn’t any documented way for an Autotest testsuite to
add custom code to be run either right before the main driver loop, or
at the point of each AT_SETUP.  For instance, there’s no good place to
put environment variable sanitization that should apply to the entire
testsuite (but isn’t universally relevant), or shell function
definitions to be used by custom test macros.

Autoconf’s test suite is poking shell functions directly into the
PREPARE_TESTS diversion, and doing environment variable sanitization
in each individual test.  Both of these are obviously undesirable.

This patch adds three new AT_* macros that can be used to do these
things in an officially-supported way: AT_PREPARE_TESTS adds code to
be run right before the main driver loop, AT_PREPARE_EACH_TEST adds
code to be run at the beginning of each test, and AT_TEST_HELPER_FN
defines a shell function that will be available to each test.  In
Autoconf’s test suite, I use AT_PREPARE_TESTS to factor out
environment variable sanitization that *ought* to apply across the
board, and AT_TEST_HELPER_FN for the helper function used by
AT_CHECK_ENV.

(This fixes the testsuite bug reported by Jannick at
https://lists.gnu.org/archive/html/autoconf/2020-10/msg00052.html .)

Comments requested particularly on the names and implementations of
the new macros.  Also, it would be nice to have an example of when
AT_PREPARE_EACH_TEST is useful, but I didn’t find one in the autoconf
test suite.

* lib/autotest/general.m4 (AT_PREPARE_TESTS, AT_PREPARE_EACH_TEST)
  (AT_TEST_HELPER_FN): New macros.
  (AT_INIT, AT_TESTED): Emit the code to report tested programs only
  if it’s needed, and make sure it’s after any code added by
  AT_PREPARE_TESTS.

* tests/local.at: Add AT_PREPARE_TESTS block that ensures
  $MAKE is set sensibly and $MAKEFLAGS and $CONFIG_SITE are unset.
  Use AT_TEST_HELPER_FN for the helper function needed by AT_CHECK_ENV.
  (AT_CHECK_MAKE): No need to sanitize $MAKE or $MAKEFLAGS here.
* tests/base.at, tests/compile.at, tests/m4sh.at, tests/torture.at:
  No need to unset or neutralize $CONFIG_SITE in individual tests.

* doc/autoconf.texi, NEWS: Document new macros.
---
 NEWS|   5 ++
 doc/autoconf.texi   |  35 +
 lib/autotest/general.m4 | 109 
 tests/base.at   |  13 ++---
 tests/compile.at|  10 
 tests/local.at  |  42 ++--
 tests/m4sh.at   |   4 +-
 tests/torture.at|   5 --
 8 files changed, 149 insertions(+), 74 deletions(-)

diff --git a/NEWS b/NEWS
index 42095344..a0258956 100644
--- a/NEWS
+++ b/NEWS
@@ -363,6 +363,11 @@ GNU Autoconf NEWS - User visible changes.
 *** AT_TESTED arguments can use variable or command substitutions, including
 in particular $EXEEXT
 
+*** New macros AT_PREPARE_TESTS, AT_PREPARE_EACH_TEST, and AT_TEST_HELPER_FN.
+
+   These provide an official way to define testsuite-specific
+   initialization code and shell functions.
+
 * Noteworthy changes in release 2.69 (2012-04-24) [stable]
 
 ** Autoconf now requires perl 5.6 or better

Re: [PATCH] doc: Document another portability problem of 'od'.

2020-12-30 Thread Zack Weinberg
On Mon, Dec 28, 2020 at 9:43 PM Bruno Haible  wrote:
> Here's a patch to mention a portability problems of 'od', that I noticed
> during Gnulib work.

Merged, thank you.



Re: [PATCH] lib/autoconf/c.m4: fix NULL pointer dereference in _AC_LANG_IO_PROGRAM

2021-06-28 Thread Zack Weinberg
On Mon, Jun 28, 2021 at 10:17 AM Nicolas Iooss  wrote:
> * lib/autoconf/c.m4: return an error when f is NULL.
> ---
>  lib/autoconf/c.m4 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
> index 9f881f0bc10c..0d9efa62d450 100644
> --- a/lib/autoconf/c.m4
> +++ b/lib/autoconf/c.m4
> @@ -114,7 +114,7 @@ $2
>  m4_define([_AC_LANG_IO_PROGRAM(C)],
>  [AC_LANG_PROGRAM([@%:@include ],
>  [FILE *f = fopen ("conftest.out", "w");
> - return ferror (f) || fclose (f) != 0;
> + return !f || ferror (f) || fclose (f) != 0;
>  ])])

Thank you for the bug report and the patch. The change looks correct
and is simple enough not to require a copyright assignment. I will
apply it to Autoconf trunk in the next few days.

Our test suite does not catch this bug, which probably means it never
tests AC_LANG_IO_PROGRAM inside AC_RUN_IFELSE. Would you be willing to
write a test case, perhaps based on the configure.ac that caused you
to discover the bug? If you don't have time to write a test yourself,
could you at least tell us about how you found the bug?

zw



[PATCH 3/3] Add a bootstrap script like Automake has.

2021-02-05 Thread Zack Weinberg
The bootstrap script generates the same files ‘autoreconf -vi’ would,
in a normal package, but it uses autoconf *from the git sources* to do
it.  This means people building from git do not need autoconf to be
installed already.  More importantly, it eliminates the extra steps
when building from git, of re-generating autoconf’s own configure
script with the just-built autoconf, then rebuilding the entire tree.

(This process still requires Automake to be installed already, and
Automake’s bootstrap script requires Autoconf to be installed already,
so there is still a dependency loop between Autoconf and Automake when
building from git—you need at least one of them installed from a
tarball to get started.)

The bootstrap script works by creating a partial installation tree in
a temporary directory, containing bin/autoconf, bin/autom4te, and just
enough of the usual contents of $(pkgdatadir) for autoconf and
autom4te to work.  It then runs a hardcoded list of commands,
corresponding to what ‘autoreconf -i -Wall,error’ would run, but
setting environment variables AUTOCONF and AUTOM4TE to ensure the
bootstrap versions of these tools are used.  (We have to create both,
because automake runs autoconf, not autom4te, to trace configure.ac.)

The ‘Autom4te’, ‘autoconf’, and ‘m4sugar’ subdirectories of the
partial installation tree are symlinked back to the source tree; this
is why version.m4 needed to be moved out of the m4sugar subdirectory,
so the bootstrap script can create it without scribbling on the source
tree.  autom4te is run in --melt mode, so we don’t need to create
freeze files in any subdirectories either.  All of the substitution
variables that are needed for autoconf and autom4te to both run, and
create the same output that they would have if fully configured, are
honored (unfortunately this does involve some messy digging around in
configure.ac with sed expressions).
---
 README-hacking |  22 +++--
 bootstrap  | 235 +
 2 files changed, 248 insertions(+), 9 deletions(-)
 create mode 100755 bootstrap

diff --git a/README-hacking b/README-hacking
index 1743dd37..6f766e70 100644
--- a/README-hacking
+++ b/README-hacking
@@ -14,7 +14,6 @@ requirements on anyone wishing to build from the 
just-checked-out sources.
 For example, you have to use recent stable versions of the maintainer
 tools we depend upon, including:
 
-- Autoconf 2.62+ 
 - Automake 1.11+ 
 - Help2man 1.29+ 
 - M4 1.4.6+ 
@@ -71,18 +70,17 @@ project, you should use this instead:
 The next step is to generate files like configure and Makefile.in:
 
   $ cd autoconf
-  $ autoreconf -vi
+  $ ./bootstrap
 
-Since we're building autoconf itself, and its tests are picky, the
-following procedure includes an extra step to ensure that some
-generated files are regenerated using the tools just built by "make"
-(if you use GNU make, the file GNUmakefile sets PATH for you):
+The bootstrap script generates the same files ‘autoreconf -vi’ would,
+in a normal package, but it uses autoconf *from the git sources* to do
+it.  This means you do not need autoconf installed already, and you do
+not need to re-generate ‘configure’ after building Autoconf.
+
+You can now build and test the package:
 
   $ ./configure
   $ make
-  $ ( PATH=`pwd`/tests:$PATH; autoreconf -vi )
-  $ make distclean
-  $ ./configure
   $ make check
 
 At this point, there should be no difference between your local copy,
@@ -103,6 +101,12 @@ setting the configure_options variable:
 
   $ make check TESTSUITEFLAGS='configure_options="CC=gcc-2.95"'
 
+The test suite is not automatically parallelized by ‘make -j’.  If you
+want to parallelize the testsuite, you need to use TESTSUITEFLAGS for
+that, too:
+
+  $ make check TESTSUITEFLAGS=-j8
+
 * Submitting patches
 
 All patches should be submitted to  for
diff --git a/bootstrap b/bootstrap
new file mode 100755
index ..8ea1b286
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,235 @@
+#! /bin/sh
+
+# This script helps bootstrap autoconf, when checked out from git.
+#
+# Copyright (C) 2021 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+# Autoconf's own configure script is generated using Autoconf.  This
+# script does what 

[PATCH 2/3] Rewrite bin/autoconf in Perl.

2021-02-05 Thread Zack Weinberg
Of all the installed programs (autoconf, autoheader, autom4te,
autoreconf, autoscan, autoupdate, ifnames) autoconf is the only one
that is a shell script instead of a Perl script.  This means it has to
do a lot of fiddly quoting and requoting to assemble an autom4te
command line, it doesn’t get to use the shared option handling code in
Autom4te/{General,Getopt}.pm, and it has to duplicate usage text that
properly should only be in Autom4te/ChannelDefs.pm.  It also means
there’s extra code in build-aux/help-extract.pl just for it, and a
special two-phase generation process in bin/local.mk.

This also paves the way for the bootstrap script mentioned in the
previous commit; it will only have to know how to deal with
substitution variables, not generation of m4sh scripts.

The new script winds up being slightly longer on disk but that’s
because our boilerplate for Perl scripts is quite long.  The code is
visibly simpler.

* bin/autoconf.as: Rename to bin/autoconf.in and rewrite in Perl.
* bin/local.mk (EXTRA_DIST): Change autoconf.as to autoconf.in.
  (MOSTLYCLEANFILES): Don’t delete autoconf.in.
  (bin/autoconf.in): Delete rule.
  (ETAGS_PERL): Add autoconf.in and sort list.
  (ETAGS_SH): Delete, no longer needed.
* tests/tools.at: Syntax-check autoconf as a Perl script.

* build-aux/help-extract.pl: Remove all code for extracting usage text
  from shell scripts.
* man/autoconf.w, man/local.mk: Refer to autoconf.in, not autoconf.as.
---
 .gitignore|   1 -
 bin/autoconf.as   | 208 -
 bin/autoconf.in   | 213 ++
 bin/local.mk  |  23 ++--
 build-aux/help-extract.pl |  49 +
 man/autoconf.w|   2 +-
 man/local.mk  |   2 +-
 tests/tools.at|   2 +-
 8 files changed, 225 insertions(+), 275 deletions(-)
 delete mode 100644 bin/autoconf.as
 create mode 100644 bin/autoconf.in

diff --git a/.gitignore b/.gitignore
index e4c8a752..21d51819 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,7 +43,6 @@ Makefile.in
 /autom4te.cache
 /bin/autoheader
 /bin/autoconf
-/bin/autoconf.in
 /bin/autom4te
 /bin/autoreconf
 /bin/autoscan
diff --git a/bin/autoconf.as b/bin/autoconf.as
deleted file mode 100644
index 1407739d..
--- a/bin/autoconf.as
+++ /dev/null
@@ -1,208 +0,0 @@
-AS_INIT[]dnl-*- shell-script -*-
-m4_divert_push([HEADER-COPYRIGHT])dnl
-# @configure_input@
-# autoconf -- create 'configure' using m4 macros.
-
-# Copyright (C) 1992-1994, 1996, 1999-2017, 2020-2021 Free Software
-# Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see .
-
-m4_divert_pop([HEADER-COPYRIGHT])dnl back to BODY
-AS_ME_PREPARE[]dnl
-
-help=["\
-Usage: $0 [OPTION]... [TEMPLATE-FILE]
-
-Generate a configuration script from a TEMPLATE-FILE if given, or
-'configure.ac' if present, or else 'configure.in'.  Output is sent
-to the standard output if TEMPLATE-FILE is given, else into
-'configure'.
-
-Operation modes:
-  -h, --helpprint this help, then exit
-  -V, --version print version number, then exit
-  -v, --verbose verbosely report processing
-  -d, --debug   don't remove temporary files
-  -f, --force   consider all files obsolete
-  -o, --output=FILE save output in FILE (stdout is the default)
-  -W, --warnings=CATEGORY   report the warnings falling in CATEGORY
-
-Warning categories include:
-  cross  cross compilation issues
-  gnuGNU coding standards (default in gnu and gnits modes)
-  obsolete   obsolete features or constructions (default)
-  override   user redefinitions of Automake rules or variables
-  portabilityportability issues (default in gnu and gnits modes)
-  portability-recursive  nested Make variables (default with -Wportability)
-  extra-portability  extra portability issues related to obscure tools
-  syntax dubious syntactic constructs (default)
-  unsupportedunsupported or incomplete features (default)
-  allall the warnings
-  no-CATEGORYturn off warnings in CATEGORY
-  none   turn off all the warnings
-
-The environment variables 'M4' and 'WARNINGS' are honored.
-
-Library directories:
-  -B, 

[PATCH 1/3] Generate version.m4 from config.status, in lib/ not lib/m4sugar/.

2021-02-05 Thread Zack Weinberg
This simplifies the Makefile a bit and also paves the way for a
bootstrap script (replacing the process of re-running autoreconf with
the just-built autoconf) which will be able to cope with generated
files that get installed in @pkgdatadir@ but not in @pkgdatadir@/m4sugar.

* lib/version.in: New file, contents extracted from lib/local.mk.
* lib/local.mk: Do not generate version.m4 here.
* configure.ac: Generate lib/version.m4 from lib/version.in via
  config.status.

* lib/freeze.mk, lib/local.mk, lib/m4sugar/m4sugar.m4:
  version.m4 now lives in @pkgdatadir@ rather than @pkgdatadir@/m4sugar.
---
 configure.ac   |  1 +
 lib/freeze.mk  |  2 +-
 lib/local.mk   | 25 +++--
 lib/m4sugar/m4sugar.m4 |  6 +++---
 lib/version.in | 12 
 5 files changed, 20 insertions(+), 26 deletions(-)
 create mode 100644 lib/version.in

diff --git a/configure.ac b/configure.ac
index e6750473..18f04447 100644
--- a/configure.ac
+++ b/configure.ac
@@ -227,6 +227,7 @@ dnl Allow maintainer rules under GNU make even in VPATH 
builds.
 AC_CONFIG_LINKS([GNUmakefile:GNUmakefile])
 
 AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([lib/version.m4:lib/version.in])
 
 AC_OUTPUT
 # Report the state of this version of Autoconf if this is a beta.
diff --git a/lib/freeze.mk b/lib/freeze.mk
index b7d4bdc1..c1ea3ab9 100644
--- a/lib/freeze.mk
+++ b/lib/freeze.mk
@@ -62,7 +62,7 @@ m4f_dependencies = $(top_build_prefix)bin/autom4te 
$(AUTOM4TE_CFG)
 m4sugar_m4f_dependencies = \
$(m4f_dependencies) \
$(src_libdir)/m4sugar/m4sugar.m4\
-   $(build_libdir)/m4sugar/version.m4
+   $(build_libdir)/version.m4
 
 m4sh_m4f_dependencies =\
$(m4sugar_m4f_dependencies) \
diff --git a/lib/local.mk b/lib/local.mk
index affe946b..501aa9dd 100644
--- a/lib/local.mk
+++ b/lib/local.mk
@@ -144,32 +144,13 @@ dist_m4sugarlib_DATA = \
   lib/m4sugar/m4sh.m4
 
 nodist_m4sugarlib_DATA = \
-  lib/m4sugar/version.m4 \
   lib/m4sugar/m4sugar.m4f \
   lib/m4sugar/m4sh.m4f
 
-CLEANFILES += $(nodist_m4sugarlib_DATA)
-
-# The ':;' in the second line of the recipe works around a redirected
-# compound command bash exit status bug.
-lib/m4sugar/version.m4: Makefile
-   $(MKDIR_P) $(@D)
-   :;{ \
- echo '# This file is part of -*- Autoconf -*-.' && \
- echo '# Version of Autoconf.' && \
- echo '# Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2009' && \
- echo '# Free Software Foundation, Inc.' && \
- echo  &&\
- echo 'm4_define([m4_PACKAGE_NAME],  [$(PACKAGE_NAME)])' && \
- echo 'm4_define([m4_PACKAGE_TARNAME],   [$(PACKAGE_TARNAME)])' && \
- echo 'm4_define([m4_PACKAGE_VERSION],   [$(PACKAGE_VERSION)])' && \
- echo 'm4_define([m4_PACKAGE_STRING],[$(PACKAGE_STRING)])' && \
- echo 'm4_define([m4_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])' && \
- echo 'm4_define([m4_PACKAGE_URL],   [$(PACKAGE_URL)])' && \
- echo 'm4_define([m4_PACKAGE_YEAR],  [$(RELEASE_YEAR)])'; \
-   } > $@-t
-   mv $@-t $@
+nodist_pkgdata_DATA += \
+  lib/version.m4
 
+CLEANFILES += $(nodist_m4sugarlib_DATA) $(nodist_pkgdata_DATA)
 TAGS_FILES += $(dist_m4sugarlib_DATA)
 
 forbidden_patterns_files += $(dist_m4sugarlib_DATA)
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 0ea671d7..021fb2ed 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -2899,9 +2899,9 @@ m4_define([m4_version_compare],
 # m4_PACKAGE_STRING
 # m4_PACKAGE_BUGREPORT
 # 
-# If m4sugar/version.m4 is present, then define version strings.  This
+# If version.m4 is present, then define version strings.  This
 # file is optional, provided by Autoconf but absent in Bison.
-m4_sinclude([m4sugar/version.m4])
+m4_sinclude([version.m4])
 
 
 # m4_version_prereq(VERSION, [IF-OK], [IF-NOT = FAIL])
@@ -2915,7 +2915,7 @@ m4_ifdef([m4_PACKAGE_VERSION],
[m4_fatal([Autoconf version $1 or higher is required],
  [63])])],
[$2])]],
-[[m4_fatal([m4sugar/version.m4 not found])]]))
+[[m4_fatal([version.m4 not found])]]))
 
 
 ## -- ##
diff --git a/lib/version.in b/lib/version.in
new file mode 100644
index ..3c0e0263
--- /dev/null
+++ b/lib/version.in
@@ -0,0 +1,12 @@
+# Version information for -*- Autoconf -*-.
+# @configure_input@
+# Copyright (C) 1999-2002, 2006-2007, 2009, 2021
+# Free Software Foundation, Inc.
+
+m4_define([m4_PACKAGE_NAME],  [@PACKAGE_NAME@])
+m4_define([m4_PACKAGE_TARNAME],   [@PACKAGE_TARNAME@])
+m4_define([m4_PACKAGE_VERSION],   [@PACKAGE_VERSION@])
+m4_define([m4_PACKAGE_STRING],[@PACKAGE_STRING@])
+m4_define([m4_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])
+m4_define([m4_PACKAGE_URL],   [@PACKAGE_URL@])
+m4_define([m4_PACKAGE_YEAR],  [@RELEASE_YEAR@])
-- 
2.30.0




[PATCH 0/3] RFC: automated bootstrap script

2021-02-05 Thread Zack Weinberg
The procedure for building Autoconf from a git checkout is a little
awkward, involving building it once, then using the just-built
autoconf to regenerate the configure script in the source directory,
then throwing away the entire first build and doing it over again, and
only then is the test suite reliable.

This patch set automates and optimizes the process with a new
top-level, git-only script called ‘bootstrap’.  The idea is copied
from Automake: you run this script instead of ‘autoreconf -i’.  It
does what ‘autoreconf -i’ would do, but it uses the unbuilt autoconf
from the git checkout itself to generate the configure script, so it’s
right the first time.  In addition to being automated and therefore
less error-prone, it’s also substantially faster, because it doesn’t
waste time building all the documentation or tools that aren’t needed
for the bootstrap process.

I have verified that the tarball created by

git clean -xdf
./bootstrap
./configure
make dist

is identical to the tarball created by

git clean -xdf
autoreconf -i
./configure
make
(PATH=$PWD/tests:$PATH; autoreconf -i)
make distclean
./configure
make dist

starting from the same point in the version history.

I would like to land this patchset on both trunk and the 2.70 branch,
because it will help with setting up CI quite a bit.  However, it does
involve some relatively invasive changes to the actual code, notably
rewriting the ‘autoconf’ driver program in Perl so the bootstrap
script doesn’t have to know how to generate M4sh scripts, so I’m
posting this for comments and will wait one week before proceeding.
(I think the code changes are desirable for other reasons, but the
bootstrap process is why I did them now.)

Zack Weinberg (3):
  Generate version.m4 from config.status, in lib/ not lib/m4sugar/.
  Rewrite bin/autoconf in Perl.
  Add a bootstrap script like Automake has.

 .gitignore|   1 -
 README-hacking|  22 ++--
 bin/autoconf.as   | 208 -
 bin/autoconf.in   | 213 ++
 bin/local.mk  |  23 ++--
 bootstrap | 235 ++
 build-aux/help-extract.pl |  49 +---
 configure.ac  |   1 +
 lib/freeze.mk |   2 +-
 lib/local.mk  |  25 +---
 lib/m4sugar/m4sugar.m4|   6 +-
 lib/version.in|  12 ++
 man/autoconf.w|   2 +-
 man/local.mk  |   2 +-
 tests/tools.at|   2 +-
 15 files changed, 493 insertions(+), 310 deletions(-)
 delete mode 100644 bin/autoconf.as
 create mode 100644 bin/autoconf.in
 create mode 100755 bootstrap
 create mode 100644 lib/version.in

-- 
2.30.0




Re: [PATCH] add new AC_PROG_AR helper

2021-02-22 Thread Zack Weinberg
On Mon, Feb 22, 2021 at 11:15 AM Mike Frysinger  wrote:
> This mirrors the existing RANLIB and related toolchain macros that
> autoconf already exports.  Some projects assume `ar` is available
> which isn't always safe, so provide a macro that probes the full
> toolchain settings.
>
> This also makes it easier to use AC_REQUIRE with the macro instead
> of duplicating the AC_CHECK_TOOL call in projects.

LGTM.  Could you please check whether there is code in automake and/or
libtool that is now redundant to this macro?

zw



Re: [PATCH v4] Fortran Cray pointer macro support

2021-08-16 Thread Zack Weinberg
On Mon, Aug 16, 2021, at 10:12 AM, Marshall Ward wrote:
> I haven't received any feedback on these updated PRs, which address
> the issues raised in the first version.

Unfortunately, I have almost no time for Autoconf work until 2022 at the 
earliest, and what time I do have is already earmarked for other projects.

Also, I have no Fortran experience; these patches ought to be reviewed by 
someone who knows, um, *something* about the language.

Sorry I can't be any more help.
zw



Re: [PATCH 0/3] RFC: automated bootstrap script

2021-09-15 Thread Zack Weinberg
On Sat, Feb 6, 2021, at 11:23 AM, Jim Meyering wrote:
> On Fri, Feb 5, 2021 at 7:42 AM Zack Weinberg  wrote:
> > The procedure for building Autoconf from a git checkout is a little
> > awkward, involving building it once, then using the just-built
> > autoconf to regenerate the configure script in the source directory,
> > then throwing away the entire first build and doing it over again, and
> > only then is the test suite reliable.
> >
> > This patch set automates and optimizes the process with a new
> > top-level, git-only script called ‘bootstrap’.  The idea is copied
> > from Automake: you run this script instead of ‘autoreconf -i’.

I finally got some time to land this patch set.  Note that the arguments to 
AC_INIT are now written in a special stylized form so the bootstrap script can 
find them reliably.

zw



Re: [PATCH] add new AC_PROG_AR helper

2022-01-24 Thread Zack Weinberg
On Wed, Jan 19, 2022, at 12:22 AM, Mike Frysinger wrote:
> On 22 Feb 2021 11:26, Zack Weinberg wrote:
>> On Mon, Feb 22, 2021 at 11:15 AM Mike Frysinger wrote:
>> > This mirrors the existing RANLIB and related toolchain macros that
>> > autoconf already exports.  Some projects assume `ar` is available
>> > which isn't always safe, so provide a macro that probes the full
>> > toolchain settings.
>> >
>> > This also makes it easier to use AC_REQUIRE with the macro instead
>> > of duplicating the AC_CHECK_TOOL call in projects.
>> 
>> LGTM.  Could you please check whether there is code in automake and/or
>> libtool that is now redundant to this macro?
>
> are there plans to merge this ?

Sorry about that, I thought you would merge it yourself (do you not have
commit access for autoconf?)  It's merged now.  I had to add a change to
tests/local.at to allow AR to be set.

Did you ever get around to checking whether there was code in automake and/or
libtool that is now redundant to this macro?

zw



Re: [PATCH] add new AC_PROG_AR helper

2022-01-26 Thread Zack Weinberg
On Tue, Jan 25, 2022, at 12:58 AM, Mike Frysinger wrote:
> On 24 Jan 2022 09:35, Zack Weinberg wrote:
>> Sorry about that, I thought you would merge it yourself (do you not have
>> commit access for autoconf?)  It's merged now.  I had to add a change to
>> tests/local.at to allow AR to be set.
>
> ah, i see, that can be confusing.  i don't have access to autoconf.  am i
> supposed to ? :)

I don't see any reason why you shouldn't, so I went ahead and added you in 
Savannah.

>> Did you ever get around to checking whether there was code in automake and/or
>> libtool that is now redundant to this macro?
>
> i posted some findings:
> https://lists.gnu.org/archive/html/autoconf-patches/2021-02/msg00011.html
>
> but i was going to wait for it to be canonical before proposing any patches.

Right, I remember seeing that go by now.  (Has it _really_ been almost a year?!)

It might make sense for Autoconf's AC_PROG_AR to check whether the 'ar' it 
finds is at least basically command-line compatible with traditional Unix 'ar', 
and maybe also check whether it's going to spew "`u' modifier ignored since `D' 
is the default (see `U')" messages like current binutils ar tends to (see e.g. 
https://bugzilla.redhat.com/show_bug.cgi?id=1155273 -- as far as I can tell the 
message is harmless, but if we can reduce the number of junk bug reports that 
random autotools-using projects have to field, that's a Good Thing).  I agree 
that providing glue to support "lib", "link", and other such tools (that also 
create static libraries, but that aren't command line compatible) is out of 
scope for AC_PROG_AR.

zw



Re: How to get autoconf to respect CC="gcc -std=c89"?

2023-10-11 Thread Zack Weinberg
On Wed, Oct 11, 2023, at 3:43 AM, Niels Möller wrote:
> Niels Möller  writes:
>
>> Updated patch below.
>
> How do we move this forward? I think we first need to settle the
> user-visible part, i.e., how AC_C_STANDARD_VERSION should work
...
> Latest patch aims for the following, which seems reasonable to me:
>
> * Single argument, white-space separated list of C language
>   versions, in order of preference. Known versions being c89, c99,
>   c11 (upper- or lower-case).

Do we want "in order of preference" or do we want "of all the entries
in the list, pick the most recent edition that the compiler supports"?
I can see arguments either way.  Bob, do you have an opinion?

I think the macro should accept four-digit years (c1989, c1999, c2011)
as well as two-digit years, and I think "c90" (and "c1990") should be
recognized as a synonym for "c89".  Maybe it should also accept bare
numbers?

Support for C17 and C24 is abstractly desirable as well, but since
Autoconf doesn't currently know how to probe for those editions, it
can wait until we do add the probes.

> Default behavior is unchanged, and equivalent to
>
>   AC_C_STANDARD_VERSION([c11 c99 c89])

Yes.

> * Error on unknown version, error on empty (space-only) argument.

Yes.

Because Autoconf *used* to support this many years ago, if someone
puts the word "traditional" in the list, they should get a custom
error message saying that Autoconf does not support traditional C
compilers anymore.  (We only *intentionally* dropped support in commit
8b5e2016c7ed2d67f31b03a3d2e361858ff5299b, which is post-2.71, but GCC
dropped support for -traditional mode in 2003, so I suspect configure
scripts haven't really worked with traditional compilers for a long
time, and I don't think it's important to be specific about *when*
Autoconf stopped supporting them in this error message.  People can
read through NEWS and/or the commit history if they want to know.)

> * Error if used after AC_PROG_CC, or used multiple times.

I'm not sure if it should *error*.  We have AC_BEFORE, which is
documented as being for this kind of thing, and it just warns.

>(and if that's a good name).

Internally, the terminology is "STDC_EDITION", and I like "edition"
because it emphasizes that it's not the *compiler's* version number
we're talking about.  Since the macro takes a list, it might make
more sense to have the name be in the plural: AC_something_EDITIONS.

Historically, we had AC_PROG_CC_{C89,C99,STDC,TRADITIONAL} that
treated "select this standard edition" as a property of the compiler,
but those are all obsolete and more recently we have been naming "find
out if the compiler supports this feature of C" macros in the AC_C_
namespace instead.

So I propose that the name should be either AC_C_STDC_EDITIONS or
AC_PROG_CC_STDC_EDITIONS, and I slightly prefer the former.  Does
anyone have a strong opinion here?

Your actual code changes look fine to me as far as they go, but
they're not complete.  Let me run down a checklist of additional
things we need before the patch is ready to be reviewed in detail:

* If configure.ac has AC_C_STANDARD_VERSION([c99]) and the compiler
  only supports C89, ./configure should error out (use AC_MSG_ERROR).
  Analogously for any other "compiler is too old for this" situation.

* If the compiler only supports *newer* editions than the newest one
  in the list, on the other hand, I think ./configure should issue a
  warning (AC_MSG_WARN), select the closest edition possible, and
  proceed.  Does anyone disagree with that?  Bob?

* Documentation.

* Tests -- most importantly, a test that, if you say
  AC_C_STDC_EDITIONS([c89]) or AC_C_STDC_EDITIONS([c99]),
  the compiler is put into the mode you asked for, even if
  it supports newer editions, since that's the whole point
  of the feature.

  If the C compiler on the system that's running the test does
  not support multiple editions of the C standard, the test should
  be skipped (AT_SKIP_IF).

  Please write as many more tests as you can think of.

* An analogous macro for C++ is not strictly necessary, but shouldn't
  be too hard to add and people are definitely going to want it.
  Don't bother with ObjC(++) for now, as there isn't exactly a
  *standard* for those; we'd need input from people who use those
  languages on what would actually be useful to them, and it can wait.

> I'd be happy to sign FSF copyright assignment forms, if required.

I think this is big enough, or will be, that we do need that, yes.
Please follow the instructions in the form at
.

Thank you for your work so far!
zw



Re: [PATCH 1/2] Fix detection of GNU M4 on mksh

2023-10-17 Thread Zack Weinberg
On Sun, Oct 15, 2023, at 2:58 AM, KO Myung-Hun wrote:
> Zack Weinberg wrote:
>> On Sat, Oct 14, 2023, at 9:19 AM, KO Myung-Hun wrote:
>>> * m4/m4.m4 (AC_PROG_GNU_M4): Double-quotes $ac_snip2.
>> Please explain why it isn't also necessary to add double quotes
>> around all the other variable expansions in this check, particularly
>> $ac_snippet and $ac_path_M4.
>
> Because this test fails due to $ac_snip2

Details please?

> Anyway I've double-quoted $ac_snippet, too.

I think that's the right thing just as a general defensive measure.

> However, not required to $ac_path_M4, which does not contain NL.

Hmm. I want to say "how do you know it will _never_ contain an IFS
character" but probably Autoconf doesn't handle whitespace in the full
pathnames of programs reliably _anywhere_ and in fact that feature would
conflict with being able to do things like

M4="gm4 -E" autoconf

so let's leave $ac_path_M4 as is.


zw



Re: [PATCH 2/2] Ignore failure of setting mode on a temporary file on OS/2

2023-10-17 Thread Zack Weinberg
On Sun, Oct 15, 2023, at 3:43 AM, KO Myung-Hun wrote:
> Zack Weinberg wrote:
>> On Sat, Oct 14, 2023, at 9:19 AM, KO Myung-Hun wrote:
>>> * bin/autom4te.in (handle_output): Ignore setting mode failure on OS/2.
>>
>> Not OK, for two reasons:
...
> How about this ?
> 1. create and close a temporary file
> 2. chmod() on it
> 3. re-open it with O_TRUNC ?

Multi-user security is probably not a concern for modern-day use of
OS/2.  Also, the temporary files created by the code we’re talking
about are not created in a system-wide scratch directory.  So we
probably *could* do it this way, but I don’t like it, because it’s
not safe in the general case.

The trouble is, on a multi-user system, any time you do any operation
by name on a file whose full pathname includes a world-writable
directory (such as the system-wide scratch directories), even if that
directory is “sticky” (chmod +t), you have to be exquisitely careful,
or a malicious concurrent process might be able to trick you into
overwriting some file elsewhere on the filesystem.  For example, your
steps 2 and 3, if executed as root on a file expected to exist in
/tmp, would give a malicious concurrent process a chance to clobber
the access control bits and/or the contents of *any file*, by moving
the temporary file out of the way, and replacing it with a symlink,
in between steps 1 and 2.  That’s a narrow race window to hit, but
it has been done successfully in the past.

I don’t want to have code in Autoconf that is only safe because of
non-obvious details of the context it’s used in.  People might
reuse the code in a different context where it’s *not* safe, without
realizing the danger.  So I suggest we use the appended patch
instead of your patch.  I’ve tested this on Unix systems with both
Perl 5.6 and Perl 5.38.  Could you please test it on your OS/2 system
as well?

zw

---
diff --git a/bin/autom4te.in b/bin/autom4te.in
index 71d7e6a6..41da77b0 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -222,6 +222,52 @@ Written by Akim Demaille.
 ## Routines.  ##
 ## -- ##
 
+# tempfile_with_mode ($dir, $mode)
+# 
+# Create a temporary file in $dir with access control bits $mode.
+# Returns a list ($fh, $fname) where $fh is a filehandle open for
+# writing to the file, and $fname is the name of the file.
+sub tempfile_with_mode ($$)
+{
+  my ($dir, $mode) = @_;
+
+  require File::Temp;
+  my $template = "actmp." . File::Temp::TEMPXXX;
+
+  # The PERMS argument was added to File::Temp::tempfile in version
+  # 0.2310 of the File::Temp module; it will be silently ignored if
+  # passed to an older version of the function.  This is the simplest
+  # way to do a non-fatal version check without features of Perl 5.10.
+  local $@;
+  if (eval { File::Temp->VERSION("0.2310"); 1 })
+{
+  # Can use PERMS argument to tempfile().
+  return File::Temp::tempfile ($template, DIR => $dir, PERMS => $mode,
+   UNLINK => 0);
+}
+  else
+{
+  # PERMS is not available.
+  # This is functionally equivalent to what it would do.
+  require Fcntl;
+  my $openflags = Fcntl::O_RDWR | Fcntl::O_CREAT | Fcntl::O_EXCL;
+
+  require File::Spec;
+  $template = File::Spec->catfile($dir, $template);
+
+  # 50 = $MAX_GUESS in File::Temp (not an exported constant).
+  for (my $i = 0; $i < 50; $i++)
+{
+  my $filename = File::Temp::mktemp($template);
+  my $fh;
+  my $success = sysopen ($fh, $filename, $openflags, $mode);
+  return ($fh, $filename) if $success;
+  fatal "Could not create temp file $filename: $!"
+unless $!{EEXIST};
+}
+  fatal "Could not create any temp file from $template: $!";
+}
+}
 
 # $OPTION
 # files_to_options (@FILE)
@@ -563,15 +609,7 @@ sub handle_output ($$)
   else
 {
   my (undef, $outdir, undef) = fileparse ($output);
-
-  use File::Temp qw (tempfile);
-  ($out, $scratchfile) = tempfile (UNLINK => 0, DIR => $outdir);
-  fatal "cannot create a file in $outdir: $!"
-unless $out;
-
-  # File::Temp doesn't give us access to 3-arg open(2), unfortunately.
-  chmod (oct ($mode) & ~(umask), $scratchfile)
-or fatal "setting mode of " . $scratchfile . ": $!";
+  ($out, $scratchfile) = tempfile_with_mode ($outdir, oct($mode));
 }
 
   my $in = new Autom4te::XFile ($ocache . $req->id, "<");
---



Re: [PATCH 2/2] Ignore failure of setting mode on a temporary file on OS/2

2023-10-17 Thread Zack Weinberg
On Sat, Oct 14, 2023, at 1:27 PM, Russ Allbery wrote:
> The standard Perl command corelist -a  tells you the versions of
> that module that shipped with each version of Perl.  The first version of
> Perl that included a version of File::Temp later than 0.2310 was Perl
> 5.33.3 (which included 0.2311).

Thank you; I had no idea that command existed.

zw



Re: [PATCH 1/2] Fix detection of GNU M4 on mksh

2023-10-18 Thread Zack Weinberg
On Wed, Oct 18, 2023, at 10:09 AM, KO Myung-Hun wrote:
> Zack Weinberg wrote:
>> Details please?
>
> Commit message was not enough ?

I'm afraid not.  I needed to know everything you say in the next two
paragraphs:

> $ac_snip2 contains NL. And in order to print it, `print -r --' command
> is used on mksh.
>
> BTW, printing without double-quoting, NL in $ac_snip2 is replaced with
> a space. Because of this, M4 does not return contents expected. As a
> result, test for $ac_snip2 fails.

With this information I can understand your suggested change easily;
without it I thought I might have to construct my own OS/2+mksh
environment in order to figure out why this test was failing *only* in
that environment.

The reason this test is failing only in your environment, is because
you generated the configure script *for Autoconf itself* with an older
version of Autoconf.  Current versions do not use `print -r` in the
implementation of AS_ECHO.  If you are building Autoconf from a git
checkout, you should use the "bootstrap" script in the source directory
to generate the configure script; if you are building from a release
tarball you should use the configure script included in that tarball.
Either of these should have masked the bug you found.

Having said that, you *have* found a genuine bug. Autoconf's
documentation is quite clear that the argument to AS_ECHO must be a
"single shell word", in particular, not containing any unquoted
whitespace (not just no newlines) after variable expansion.  *Both*
$ac_snippet and $ac_snip2 contain whitespace and therefore need to be
quoted.  It happens that replacing newlines with horizontal spaces
breaks $ac_snip2 but not $ac_snippet, and it also happens that the
`printf`-based implementation of AS_ECHO (which is used unconditionally
by current Autoconf) mangles both in a different way that doesn't break
either of them.  But we should not be relying on either of these things.
So I'm going to go ahead and commit your patch with quoting added to
both $ac_snip2 and $ac_snippet.  Final patch below.

zw

>From 88011e1f263fd7e794caa6e0984e623769d1c8c3 Mon Sep 17 00:00:00 2001
From: KO Myung-Hun 
Date: Wed, 18 Oct 2023 14:00:11 -0400
Subject: [PATCH] m4/m4.m4: Quote argument to AS_ECHO correctly.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

AS_ECHO’s argument is required to be “a single shell word,”
and this more precisely means it must not be altered by shell
word splitting.  In particular, if the argument contains shell
variables whose values contain whitespace then it needs to be
wrapped in "shell double quotes".

The absence of these quotes caused one of the embedded M4 scripts
to be mangled by the Autoconf 2.69 implementation of AS_ECHO.
We don’t officially support bootstrapping with an older version
of Autoconf (use the ./bootstrap script instead) but the absence
of quotes is still incorrect.

For consistency add [M4 quotes] to the use of AS_ECHO that was
shell-quoted but not M4-quoted.

* m4/m4.m4 (AC_PROG_GNU_M4): Quote argument to AS_ECHO correctly.
---
 m4/m4.m4 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/m4/m4.m4 b/m4/m4.m4
index e6203118..919dbf4a 100644
--- a/m4/m4.m4
+++ b/m4/m4.m4
@@ -41,12 +41,12 @@ AC_PATH_PROGS_FEATURE_CHECK([M4], [m4 gm4 gnum4],
   ac_snip2=change'quote(<,>)def''ine(,<>)d'nl
   ac_snip2=${ac_snip2}${as_nl}def'ine(,)>)d'nl
   ac_snip2=${ac_snip2}${as_nl}m4'wrap()d'nl
-  AS_ECHO("$as_me:${as_lineno-$LINENO}: trying $ac_path_M4") \
+  AS_ECHO(["$as_me:${as_lineno-$LINENO}: trying $ac_path_M4"]) \
   >_MESSAGE_LOG_FD
   test -z "`$ac_path_M4 -F conftest.m4f &1`" \
-  && test -z "`AS_ECHO([$ac_snippet]) | $ac_path_M4 --trace=mac 2>&1`" \
+  && test -z "`AS_ECHO(["$ac_snippet"]) | $ac_path_M4 --trace=mac 2>&1`" \
   && test -f conftest.m4f \
-  && test x"`AS_ECHO([$ac_snip2]) | \
+  && test x"`AS_ECHO(["$ac_snip2"]) | \
 $ac_path_M4 --trace=T --debug=aflq 2>&1`" = \
   x'm4trace:stdin:3: -1- T()' \
   && ac_cv_path_M4=$ac_path_M4 ac_path_M4_found=:
-- 
2.41.0




Re: [PATCH 2/2] Ignore failure of setting mode on a temporary file on OS/2

2023-10-18 Thread Zack Weinberg
On Tue, Oct 17, 2023, at 2:58 PM, Paul Eggert wrote:
> On 10/17/23 11:16, Zack Weinberg wrote:
...
>> you have to be exquisitely careful, or a malicious concurrent process
>> might be able to trick you into overwriting some file elsewhere on
>> the filesystem.
...
> ? If /tmp is sticky, a malicious process can't rename /tmp/foo.

I might be wrong about that specific thing.  It's been long enough that
I no longer remember the exact details, but there was a CVE reported
against GCC ... I want to say circa version 2.95 ... because it would
create temporary files with predictable names in /tmp and it was
*somehow* possible for a malicious process to substitute symlinks
pointing into /etc, and if you were running the compiler as root, which
you shouldn't but it happens all the time, boom, trashed /etc/shadow or
something equally important.

It is possible that this exploit depended on a kernel bug where the
sticky bit didn't do everything it needed to do, but since people
still want to run autoconf proper (not just configure scripts) on
ancient systems, I think we need to be careful anyway.

zw



Re: [PATCH 2/2] Ignore failure of setting mode on a temporary file on OS/2

2023-10-18 Thread Zack Weinberg
On Wed, Oct 18, 2023, at 10:21 AM, KO Myung-Hun wrote:
> Zack Weinberg wrote:
>> I don’t want to have code in Autoconf that is only safe because of
>> non-obvious details of the context it’s used in.  People might
>> reuse the code in a different context where it’s *not* safe, without
>> realizing the danger.  So I suggest we use the appended patch
>> instead of your patch.  I’ve tested this on Unix systems with both
>> Perl 5.6 and Perl 5.38.  Could you please test it on your OS/2 system
>> as well?
>
> It works well here.

Great! I have committed the version below.

zw

>From c4a695510d240491f89d78204a3d5a6fdbe03648 Mon Sep 17 00:00:00 2001
From: Zack Weinberg 
Date: Wed, 18 Oct 2023 13:23:36 -0400
Subject: [PATCH] autom4te: OS/2 compat: Do not attempt to chmod an open file.

On OS/2, chmod(2) cannot be applied to an open file.

Instead set the desired permissions when the file is initially
created, using the PERMS argument to File::Temp::tempfile if
possible, or by manually emulating that feature if the system
perl does not provide a new enough version of File::Temp.

This has the nice side effect that we no longer need to handle
the umask manually.

* autom4te.in (tempfile_with_mode): New function.
  (handle_output): Use tempfile_with_mode instead of directly using
  File::Temp plus chmod.

Co-authored-by: KO Myung-Hun 
---
 bin/autom4te.in | 56 +
 1 file changed, 47 insertions(+), 9 deletions(-)

diff --git a/bin/autom4te.in b/bin/autom4te.in
index 71d7e6a6..41da77b0 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -222,6 +222,52 @@ Written by Akim Demaille.
 ## Routines.  ##
 ## -- ##
 
+# tempfile_with_mode ($dir, $mode)
+# 
+# Create a temporary file in $dir with access control bits $mode.
+# Returns a list ($fh, $fname) where $fh is a filehandle open for
+# writing to the file, and $fname is the name of the file.
+sub tempfile_with_mode ($$)
+{
+  my ($dir, $mode) = @_;
+
+  require File::Temp;
+  my $template = "actmp." . File::Temp::TEMPXXX;
+
+  # The PERMS argument was added to File::Temp::tempfile in version
+  # 0.2310 of the File::Temp module; it will be silently ignored if
+  # passed to an older version of the function.  This is the simplest
+  # way to do a non-fatal version check without features of Perl 5.10.
+  local $@;
+  if (eval { File::Temp->VERSION("0.2310"); 1 })
+{
+  # Can use PERMS argument to tempfile().
+  return File::Temp::tempfile ($template, DIR => $dir, PERMS => $mode,
+   UNLINK => 0);
+}
+  else
+{
+  # PERMS is not available.
+  # This is functionally equivalent to what it would do.
+  require Fcntl;
+  my $openflags = Fcntl::O_RDWR | Fcntl::O_CREAT | Fcntl::O_EXCL;
+
+  require File::Spec;
+  $template = File::Spec->catfile($dir, $template);
+
+  # 50 = $MAX_GUESS in File::Temp (not an exported constant).
+  for (my $i = 0; $i < 50; $i++)
+{
+  my $filename = File::Temp::mktemp($template);
+  my $fh;
+  my $success = sysopen ($fh, $filename, $openflags, $mode);
+  return ($fh, $filename) if $success;
+  fatal "Could not create temp file $filename: $!"
+unless $!{EEXIST};
+}
+  fatal "Could not create any temp file from $template: $!";
+}
+}
 
 # $OPTION
 # files_to_options (@FILE)
@@ -563,15 +609,7 @@ sub handle_output ($$)
   else
 {
   my (undef, $outdir, undef) = fileparse ($output);
-
-  use File::Temp qw (tempfile);
-  ($out, $scratchfile) = tempfile (UNLINK => 0, DIR => $outdir);
-  fatal "cannot create a file in $outdir: $!"
-unless $out;
-
-  # File::Temp doesn't give us access to 3-arg open(2), unfortunately.
-  chmod (oct ($mode) & ~(umask), $scratchfile)
-or fatal "setting mode of " . $scratchfile . ": $!";
+  ($out, $scratchfile) = tempfile_with_mode ($outdir, oct($mode));
 }
 
   my $in = new Autom4te::XFile ($ocache . $req->id, "<");
-- 
2.41.0




Re: [PATCH 1/2] Fix detection of GNU M4 on mksh

2023-10-14 Thread Zack Weinberg
On Sat, Oct 14, 2023, at 9:19 AM, KO Myung-Hun wrote:
> * m4/m4.m4 (AC_PROG_GNU_M4): Double-quotes $ac_snip2.

Please explain why it isn't also necessary to add double quotes
around all the other variable expansions in this check, particularly
$ac_snippet and $ac_path_M4.

Also, typo in your commit message: "Double-quotes" should be "Double-quote".

zw



Re: [PATCH 2/2] Ignore failure of setting mode on a temporary file on OS/2

2023-10-14 Thread Zack Weinberg
On Sat, Oct 14, 2023, at 9:19 AM, KO Myung-Hun wrote:
> OS/2 does not allow chmod() on an opened file.
>
> * bin/autom4te.in (handle_output): Ignore setting mode failure on OS/2.

Not OK, for two reasons: (1) IIRC this is used to create scripts with the
execute bit set in at least one place.  Ignoring the chmod failure will
cause confusing errors downstream of where the problem actually was.  (2)
Having a temporary file that's potentially writable by other user ids,
even briefly, risks a variety of security problems.

Also, for maintainability's sake, no checks of $^O anywhere in autoconf's
Perl code unless there is absolutely no alternative.

Really what we need here is for File::Temp to allow us to supply the third
argument to the open() system call.  That feature was added in version
0.2310 of the File::Temp module.  Does anyone have time right now to do the
archaeology on what version of File::Temp shipped with the oldest version of
Perl we currently support?

zw



Re: [PATCH] m4: Update invocation of AC_PROG_LEX

2023-08-16 Thread Zack Weinberg
On Wed, Aug 16, 2023, at 2:38 AM, Łukasz Stelmach wrote:
> Commit 73f1be5e42e3 to autoconf has introduced an argument to
> AC_PROG_LEX. Invocation without the argument has been treated as
> obsolete since then.

This should go to automake-patches, not autoconf-patches.  Also, you
should update the manual (automake.texi) to document that AM_PROG_LEX
now takes an argument and what that argument is.  Finally, I'd like to
suggest a small improvement to the code: instead of

> -AC_REQUIRE([AC_PROG_LEX])dnl
> +AC_PROG_LEX([$1])dnl

you should have

-AC_REQUIRE([AC_PROG_LEX])dnl
+AC_PROVIDE_IFELSE([AC_PROG_LEX], [], [AC_PROG_LEX([$@])])dnl

This change ensures that AC_PROG_LEX will not be invoked a second time
if it has already been used directly, which is important both because
that's the way it has always worked, and because we (autoconf maintainers)
have been telling people to work around the problem you're fixing by using
AC_PROG_LEX _as well as_ AM_PROG_LEX.  It also makes AM_PROG_LEX oblivious
to how many arguments AC_PROG_LEX actually takes, which could be important
future-proofing.

zw



[PATCH 2/5] make fetch

2022-07-10 Thread Zack Weinberg
Our local patches to lib/Autom4te/FileUtils.pm and maint.mk were
manually reapplied.
---
 GNUmakefile  |2 +-
 build-aux/announce-gen   |  114 ++-
 build-aux/config.guess   | 1262 --
 build-aux/config.sub |   94 ++-
 build-aux/gendocs.sh |   12 +-
 build-aux/git-version-gen|   21 +-
 build-aux/gitlog-to-changelog|7 +-
 build-aux/gnupload   |   13 +-
 build-aux/move-if-change |2 +-
 build-aux/texinfo.tex|  347 +++-
 build-aux/update-copyright   |4 +-
 build-aux/useless-if-before-free |   20 +-
 build-aux/vc-list-files  |2 +-
 doc/gendocs_template |4 +-
 doc/standards.texi   |   51 +-
 lib/Autom4te/ChannelDefs.pm  |2 +-
 lib/Autom4te/Channels.pm |2 +-
 lib/Autom4te/Configure_ac.pm |2 +-
 lib/Autom4te/FileUtils.pm|2 +-
 lib/Autom4te/Getopt.pm   |2 +-
 lib/Autom4te/XFile.pm|2 +-
 m4/autobuild.m4  |2 +-
 maint.mk |   59 +-
 23 files changed, 1053 insertions(+), 975 deletions(-)

diff --git a/GNUmakefile b/GNUmakefile
index 0c99d584..7a08c9d5 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -5,7 +5,7 @@
 # It is necessary if you want to build targets usually of interest
 # only to the maintainer.
 
-# Copyright (C) 2001, 2003, 2006-2021 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2006-2022 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
diff --git a/build-aux/announce-gen b/build-aux/announce-gen
index 84d2d637..3847a568 100755
--- a/build-aux/announce-gen
+++ b/build-aux/announce-gen
@@ -3,7 +3,7 @@
 
 # Generate a release announcement message.
 
-# Copyright (C) 2002-2021 Free Software Foundation, Inc.
+# Copyright (C) 2002-2022 Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -35,12 +35,14 @@
 eval 'exec perl -wSx "$0" "$@"'
  if 0;
 
-my $VERSION = '2020-05-10 16:13'; # UTC
+my $VERSION = '2022-07-10 01:47'; # UTC
 # The definition above must lie within the first 8 lines in order
 # for the Emacs time-stamp write hook (at end) to update it.
 # If you change this file with Emacs, please let the write hook
 # do its job.  Otherwise, update this string manually.
 
+my $copyright_year = '2022';
+
 use strict;
 use Getopt::Long;
 use POSIX qw(strftime);
@@ -49,12 +51,6 @@ use POSIX qw(strftime);
 
 my %valid_release_types = map {$_ => 1} qw (alpha beta stable);
 my @archive_suffixes = qw (tar.gz tar.bz2 tar.lz tar.lzma tar.xz);
-my %digest_classes =
-  (
-   'md5' => (eval { require Digest::MD5; } and 'Digest::MD5'),
-   'sha1' => ((eval { require Digest::SHA; } and 'Digest::SHA')
-  or (eval { require Digest::SHA1; } and 'Digest::SHA1'))
-  );
 my $srcdir = '.';
 
 sub usage ($)
@@ -94,7 +90,11 @@ The following are optional:
 VERSION is the result of running git describe
 in the gnulib source directory.
 required if gnulib is in TOOL_LIST.
-   --no-print-checksums do not emit MD5 or SHA1 checksums
+   --gpg-key-email=EMAILThe email address of the key used to
+sign the tarballs
+   --gpg-keyring-url=URLURL pointing to keyring containing the key used
+to sign the tarballs
+   --no-print-checksums do not emit SHA1 or SHA256 checksums
--archive-suffix=SUF add SUF to the list of archive suffixes
--mail-headers=HEADERS   a space-separated list of mail headers, e.g.,
 To: x\@example.com Cc: 
y-announce\@example.com,...
@@ -161,7 +161,7 @@ sub print_locations ($\@\%@)
 
 =item C.
+Print the SHA1 and SHA256 signature section for each C<@file>.
 
 =cut
 
@@ -169,23 +169,18 @@ sub print_checksums (@)
 {
   my (@file) = @_;
 
-  print "Here are the MD5 and SHA1 checksums:\n";
+  print "Here are the SHA1 and SHA256 checksums:\n";
   print "\n";
 
-  foreach my $meth (qw (md5 sha1))
+  use Digest::file qw(digest_file_hex digest_file_base64);
+
+  foreach my $f (@file)
 {
-  my $class = $digest_classes{$meth} or next;
-  foreach my $f (@file)
-{
-  open IN, '<', $f
-or die "$ME: $f: cannot open for reading: $!\n";
-  binmode IN;
-  my $dig = $class->new->addfile(*IN)->hexdigest;
-  close IN;
-  print "$dig  $f\n";
-}
+  print digest_file_hex($f, "SHA-1"), "  $f\n";
+  print digest_file_base64($f, "SHA-256"), "  $f\n";
 }
-  print "\n";
+  print "\nThe SHA256 checksum is base64 encoded, instead of the\n";
+  

[PATCH 4/5] Make help-extract.pl work with Perl 5.10.x.

2022-07-10 Thread Zack Weinberg
The main issue was use of s///r; the /r modifier was added in 5.14.
Since the baseline is now 5.10.0 instead of 5.6.0, a couple places
can be tidied up using slightly newer constructs.

* help-extract.pl: Use File::Spec::Functions instead of File::Spec
  for reduced clunkiness.
  (eval_qq_no_interpolation): Don’t use s///r.  Do use \K and (?=...)
  to match the empty string (but only in just the right locations),
  so we don’t need to use $& in the replacement.
  (main): Don’t use s///r.

---
 build-aux/help-extract.pl | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/build-aux/help-extract.pl b/build-aux/help-extract.pl
index 931331e3..a53a7db7 100644
--- a/build-aux/help-extract.pl
+++ b/build-aux/help-extract.pl
@@ -19,10 +19,7 @@
 use 5.010;
 use strict;
 use warnings;
-
-# File::Spec itself was added in 5.005.
-# File::Spec::Functions was added in 5.6.1 which is just barely too new.
-use File::Spec;
+use File::Spec::Functions qw(catfile);
 
 # This script is not intended to be used directly.  It's run by
 # help2man via wrappers in man/, e.g.  man/autoconf.w, as if it were
@@ -51,11 +48,17 @@ sub eval_qq_no_interpolation ($)
   # The argument is expected to be a "double quoted string" including the
   # leading and trailing delimiters.  Returns the text of this string after
   # processing backslash escapes but NOT interpolation.
-  # / (?)* blah /x means match blah preceded by an
-  # *even* number of backslashes.  It would be nice if we could use \K
-  # to exclude the backslashes from the matched text, but that was only
-  # added in Perl 5.10 and we still support back to 5.006.
-  return eval $_[0] =~ s/ (?)* [\$\@] /\\$&/xrg;
+  my $s = $_[0];
+
+  # Escape $ and @ inside the string, if they are not already escaped.
+  # The regex matches the empty string, but only if it is preceded by an
+  # even number of backslashes (including zero) and followed by either a
+  # literal $ or a literal @. Then we insert a backslash at the position
+  # of the match.
+  $s =~ s/ (?:\A|[^\\]) (?:)* \K (?=[\$\@]) /\\/xg;
+
+  # It is now safe to feed the string to 'eval'.
+  return eval $s;
 }
 
 sub extract_channeldefs_usage ($)
@@ -198,9 +201,10 @@ The script-source argument should also be relative to 
top_srcdir.
   die $usage;
 }
 
-  my $cmd_name= $source =~ s{^.*/([^./]+)\.in$}{$1}r;
-  $source = File::Spec->catfile($top_srcdir, $source);
-  $channeldefs_pm = File::Spec->catfile($top_srcdir, $channeldefs_pm);
+  my $cmd_name= $source;
+  $cmd_name   =~ s{^.*/([^./]+)\.in$}{$1};
+  $source = catfile($top_srcdir, $source);
+  $channeldefs_pm = catfile($top_srcdir, $channeldefs_pm);
 
   my $text = extract_assignment ($source, $channeldefs_pm, $what);
   $text =~ s/\$0\b/$cmd_name/g;
-- 
2.36.1




[PATCH 5/5] Fix testsuite failures on Darwin (aka macOS).

2022-07-10 Thread Zack Weinberg
Tests of AC_{CHECK_,}HEADER_STDBOOL were failing on Darwin for two
reasons: an m4 quoting bug in tests/local.at causing Darwin sed to
throw syntax errors, and an excessively precise interpretation of how
C99 and C++11 interact.  The latter is worth mentioning in NEWS.

 * tests/local.at (_AT_DEFINES_CMP_PRUNE): Insert [] before ‘dnl’ in
   two places to keep it separate from the result of the m4_bpatsubsts
   operation that immediately precedes it.
 * lib/autoconf/headers.m4 (AC_CHECK_HEADER_STDBOOL): Allow ‘bool’,
   ‘true’, and ‘false’ not to be macros, after including stdbool.h,
   whenever __cplusplus is defined.
 * NEWS: Document change to AC_{CHECK_,}HEADER_STDBOOL.
---
 NEWS| 13 +
 lib/autoconf/headers.m4 |  6 --
 tests/local.at  |  4 ++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index a8475707..ef0f5f83 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,19 @@ GNU Autoconf NEWS - User visible changes.
   represent cache file timestamps, thus avoiding some problems where
   automake incorrectly decides not to regenerate stale caches.
 
+*** AC_HEADER_STDBOOL and AC_CHECK_HEADER_STDBOOL are less picky.
+
+  When compiling C++, a ‘stdbool.h’ that exists, but does nothing, is
+  acceptable no matter what version of the C++ standard is in use.
+
+  (ISO C++ 2011 says that ‘stdbool.h’ should exist for compatibility
+  with C, but should *not* define ‘bool’, ‘true’, or ‘false’ as
+  macros.  ISO C++ 1998 doesn’t mention ‘stdbool.h’ at all.  Some C++
+  compilers implement the 2011 rule in their C++98 mode as well.
+  ‘bool’, ‘true’, and ‘false’ have been built into the C++ language
+  since the beginning, so a ‘stdbool.h’ that exists but does nothing
+  should be fine for all reasonable C++ programs.)
+
 * Noteworthy changes in release 2.71 (2021-01-28) [stable]
 
 ** Bug fixes, including:
diff --git a/lib/autoconf/headers.m4 b/lib/autoconf/headers.m4
index 8944da41..5cd1f4d5 100644
--- a/lib/autoconf/headers.m4
+++ b/lib/autoconf/headers.m4
@@ -633,8 +633,10 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
  bool *pp = 
 
  /* C 1999 specifies that bool, true, and false are to be
-macros, but C++ 2011 and later overrule this.  */
- #if __cplusplus < 201103
+macros, but C++ 2011 overrules this.  The C++ committee
+was codifying existing practice, so we allow them to
+not be macros whenever __cplusplus is defined.  */
+ #ifndef __cplusplus
   #ifndef bool
#error "bool is not defined"
   #endif
diff --git a/tests/local.at b/tests/local.at
index 3f348929..f79f57ff 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -593,9 +593,9 @@ AT_CMP([at_defines-$1], [at_defines-$2])[]dnl
 m4_define([_AT_DEFINES_CMP_PRUNE],
 [m4_bmatch([$1],
   [^vary:],
-[  /@%:@define ]m4_bpatsubsts([$1], [\@/ d ;@%:@@:}@
-   /@%:@undef ]m4_bpatsubsts([$1], [\@/ d ;@%:@@:}@
 ],
   [m4_fatal([unrecognized AT_DEFINES_CMP variance token: "$1"])])])
-- 
2.36.1




[PATCH 1/5] Require Perl 5.10.0 or later.

2022-07-10 Thread Zack Weinberg
The minimum Perl version was raised to 5.8.0 from 5.6.0 in commit
3a9802d60156809c139e9b4620bf04917e143ee2 (but not documented as
such until e8c2d79ec42c70b6e4fa282bc0c024bf42f0585f, and not
actually *enforced* by our own configure script until, er, now)
in order to use Time::HiRes::stat.

Unfortunately, while the Time::HiRes *module* was added in 5.8.0, it
did not export a ‘stat’ function until 5.8.9.  More precisely, this
feature was added to Time::HiRes in version 1.92 of that module; Perl
core 5.8.8 shipped Time::HiRes 1.86, 5.8.9 shipped 1.9715.  The only
system I have convenient access to, that has older Perls installed,
offers me a choice of 5.8.8 or 5.10.1, so the new requirement means
I cannot test with 5.8.x anymore.

Per https://perldoc.perl.org/perlhist the release history of these
versions of Perl is, in chronological order,

  5.8.0 2002-Jul-18
  5.8.8 2006-Jan-31
  5.10.02007-Dec-18
  5.8.9 2008-Dec-14  <-- almost a year later than 5.10.0
  5.10.12009-Aug-22
  5.12.02010-Apr-12

Per https://perldoc.perl.org/perl5101delta the differences between
5.10.0 and 5.10.1 are small, and do not make me worry about
accidentally introducing code that works on my test boxes but not for
our users, unlike the gulf between 5.8.x and 5.10.x.

Requiring 5.10 will mean that we have access to Digest::SHA, the //
and //= operators, the regexp \K escape, and ‘state’ variables
(lexical scope, persistent value) all of which I can think
of uses for (but none of them are actually used in this patch).

Putting it all together, I think a requirement bump to version 5.10.0
is justified.  We are already chopping off the trailing edge at 2006
due to the requirement for M4 1.4.8 (/de facto/ since 2.70) and late
2007 is still 15 years ago.

This patch also makes configure search $PATH for executables named
‘perl5*’ and ‘perl-5.*’ if bare ‘perl’ is too old.  To do this, it
introduces a helper macro AClocal_PATH_PROG_GLOBS_FEATURE_CHECK, which
I would *like* to promote to a new Autoconf feature, but I got stuck
on quoting issues — see comments in m4/perl-time-hires.m4.

* NEWS: Document requirement for Perl 5.10.
* m4/perl-time-hires.m4: New file.
* configure.ac: Use AC_PATH_PERL_WITH_TIME_HIRES_STAT to probe for
  perl.
* build-aux/fetch.pl (fetch): For .pm files fetched from Automake,
  rewrite “use 5.006” to “use 5.010”.

* build-aux/help-extract.pl
* lib/Autom4te/C4che.pm
* lib/Autom4te/ChannelDefs.pm
* lib/Autom4te/Channels.pm
* lib/Autom4te/Config.pm
* lib/Autom4te/Configure_ac.pm
* lib/Autom4te/FileUtils.pm
* lib/Autom4te/General.pm
* lib/Autom4te/Getopt.pm
* lib/Autom4te/Request.pm
* lib/Autom4te/XFile.pm
* tests/mktests.pl: Change “use 5.006” to “use 5.010”.
---
 NEWS |  2 +-
 build-aux/fetch.pl   |  1 +
 build-aux/help-extract.pl|  1 +
 configure.ac |  9 +
 lib/Autom4te/C4che.pm|  2 +-
 lib/Autom4te/ChannelDefs.pm  |  2 +-
 lib/Autom4te/Channels.pm |  2 +-
 lib/Autom4te/Config.pm   |  2 +-
 lib/Autom4te/Configure_ac.pm |  2 +-
 lib/Autom4te/FileUtils.pm|  2 +-
 lib/Autom4te/General.pm  |  2 +-
 lib/Autom4te/Getopt.pm   |  2 +-
 lib/Autom4te/Request.pm  |  2 +-
 lib/Autom4te/XFile.pm|  2 +-
 m4/perl-time-hires.m4| 74 
 tests/mktests.pl |  2 +-
 16 files changed, 89 insertions(+), 20 deletions(-)
 create mode 100644 m4/perl-time-hires.m4

diff --git a/NEWS b/NEWS
index 91164390..a8475707 100644
--- a/NEWS
+++ b/NEWS
@@ -4,7 +4,7 @@ GNU Autoconf NEWS - User visible changes.
 
 ** Backward incompatibilities
 
-*** Autoconf now requires perl 5.8 (2002) or later.
+*** Autoconf now requires perl 5.10 (2007) or later.
   Generated 'configure' scripts continue to run without perl.
 
 *** Autoconf now requires GNU M4 1.4.8 (2006) or later.
diff --git a/build-aux/fetch.pl b/build-aux/fetch.pl
index e4a4a484..3dc9bc78 100755
--- a/build-aux/fetch.pl
+++ b/build-aux/fetch.pl
@@ -240,6 +240,7 @@ sub fetch ($$)
   # don't use \s here or it will eat blank lines
   $content =~ s/[ \t]+$//gm;
   $content =~ s/\bAutomake::/Autom4te::/g if $edit;
+  $content =~ s/^use 5\.006;$/use 5.010;/mg if $edit;
 
   replace_if_change ($destpath, $content, $quiet);
 }
diff --git a/build-aux/help-extract.pl b/build-aux/help-extract.pl
index bcec8504..931331e3 100644
--- a/build-aux/help-extract.pl
+++ b/build-aux/help-extract.pl
@@ -16,6 +16,7 @@
 
 # Written by Zack Weinberg.
 
+use 5.010;
 use strict;
 use warnings;
 
diff --git a/configure.ac b/configure.ac
index 9362ddf3..3d849ac4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,14 +153,7 @@ AM_MISSING_PROG([HELP2MAN], [help2man])
 ## -- ##
 
 # We use an absolute name for perl so the #! line in autoscan will work.
-AC_PATH_PROG([PERL], [perl], [no])
-AC_SUBST([PERL])dnl
-if test "$PERL" = no; then
-  AC_MSG_ERROR([perl is not found])
-fi
-$PERL -e 'require 5.006;' || {
-  

[PATCH 3/5] Remove ancient backward compatibility code from m4/m4.m4.

2022-07-10 Thread Zack Weinberg
We have had AC_PREREQ([2.69]) in our own configure.ac since 2021,
and before that it was AC_PREREQ([2.62]) since 2012, so backcompat
code for 2.61 is not necessary anymore.

Also add logging of the name of each candidate executable and bump the
serial number.
---
 m4/m4.m4 | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/m4/m4.m4 b/m4/m4.m4
index 66e7341f..42612162 100644
--- a/m4/m4.m4
+++ b/m4/m4.m4
@@ -1,4 +1,4 @@
-# m4.m4 serial 12
+# m4.m4 serial 13
 
 # Copyright (C) 2000, 2006-2017, 2020-2022 Free Software Foundation,
 # Inc.
@@ -41,6 +41,8 @@ AC_PATH_PROGS_FEATURE_CHECK([M4], [m4 gm4 gnum4],
   ac_snip2=change'quote(<,>)def''ine(,<>)d'nl
   ac_snip2=${ac_snip2}${as_nl}def'ine(,)>)d'nl
   ac_snip2=${ac_snip2}${as_nl}m4'wrap()d'nl
+  AS_ECHO("$as_me:${as_lineno-$LINENO}: trying $ac_path_M4") \
+  >_MESSAGE_LOG_FD
   test -z "`$ac_path_M4 -F conftest.m4f &1`" \
   && test -z "`AS_ECHO([$ac_snippet]) | $ac_path_M4 --trace=mac 2>&1`" \
   && test -f conftest.m4f \
@@ -80,12 +82,3 @@ Glibc 2.9 - 2.12 and GNU M4 1.4.11 - 1.4.15 have another 
strstr bug.])])])
 esac])
   AC_SUBST([M4_DEBUGFILE], [$ac_cv_prog_gnu_m4_debugfile])
 ])
-
-# Compatibility for bootstrapping with Autoconf 2.61.
-dnl FIXME - replace this with AC_PREREQ([2.62]) after the release.
-# AC_PATH_PROGS_FEATURE_CHECK was added the same time the slightly broken,
-# undocumented _AC_PATH_PROG_FEATURE_CHECK was deleted.
-m4_ifndef([AC_PATH_PROGS_FEATURE_CHECK],
-  [m4_define([AC_PATH_PROGS_FEATURE_CHECK],
-[_AC_PATH_PROG_FEATURE_CHECK([$1], [$2], [$3], [$5])
-])])
-- 
2.36.1




  1   2   >