Re: AS_IF

Bruno Haible <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches,gmane.comp.lib.gnulib.bugs
Message-ID <2665725.7ejQqcbjGi@omega>
[CCing autoconf-patches]

Paul Eggert wrote in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-10/msg00019.html>:
> > 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.
> 
> I was playing it safe based on this NEWS item from Autoconf 2.69c:
> 
>     - Autoconf macros that use AC_REQUIRE internally, are not safe to
>       use inside of hand-written shell control-flow constructs.  Use
>       AS_IF, AS_CASE, AS_FOR, etc. instead.  (See the “Prerequisite
>       Macros” section of the manual for further explanation.)
> 
> Since I didn't know whether the macros in question used AC_REQUIRE internally, I 
> played it safe.
> 
> 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.

Proposed patch attached.

Bruno
0001-Clarify-that-AS_IF-and-AS_CASE-are-overkill-inside-A.patch (text/x-patch, 2.8 KB)
From 11b827d202aa07b2b8c8f894d8f49844d570dfe9 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Tue, 6 Oct 2020 23:46:42 +0200
Subject: [PATCH] Clarify that AS_IF and AS_CASE are overkill inside AC_DEFUN.

* doc/autoconf.texi (Common Shell Constructs): Document that AS_IF and AS_CASE
provide no benefit regarding required macros when used inside macros defined
by AC_DEFUN or AC_DEFUN_ONCE.
* NEWS: Don't mention the undocumented macro AS_FOR.
---
 NEWS              |  4 ++--
 doc/autoconf.texi | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 55e938b..5335709 100644
--- a/NEWS
+++ b/NEWS
@@ -36,8 +36,8 @@ GNU Autoconf NEWS - User visible changes.
 
    - Autoconf macros that use AC_REQUIRE internally, are not safe to
      use inside of hand-written shell control-flow constructs.  Use
-     AS_IF, AS_CASE, AS_FOR, etc. instead.  (See the “Prerequisite
-     Macros” section of the manual for further explanation.)
+     AS_IF, AS_CASE, etc. instead.  (See the “Prerequisite Macros”
+     section of the manual for further explanation.)
 
      The set of macros that use AC_REQUIRE internally may change from
      release to release.  The only macros that are guaranteed *not* to
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index dea85e4..f8d8f8b 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -13759,7 +13759,15 @@ Expand into a shell @samp{case} statement, where @var{word} is matched
 against one or more patterns.  @var{if-matched} is run if the
 corresponding pattern matched @var{word}, else @var{default} is run.
 Avoids several portability issues (@pxref{case, , Limitations of Shell
-Builtins}).
+Builtins}).  Also, @code{AS_CASE} ensures any macros required by
+@var{if-matched1}, @dots{}, @var{default} are expanded before the
+@samp{case} statement.
+
+The handling of required macros provided by @code{AS_CASE} is useful
+in @file{configure.ac}, outside of macros defined by @code{AC_DEFUN}
+or @code{AC_DEFUN_ONCE}.  Inside macros defined by @code{AC_DEFUN}
+or @code{AC_DEFUN_ONCE}, @code{AS_CASE} and the plain shell @samp{case}
+syntax are equivalent.
 @end defmac
 
 @c Deprecated, to be replaced by a better API
@@ -13881,6 +13889,12 @@ blanks, or expand to a nonempty shell command.  For example,
 argument contains the nonblank characters @code{[]} which expand to
 nothing.  This restriction on @var{run-if-false} also applies to other
 macros with ``if-false'' arguments denoting shell commands.
+
+The handling of required macros provided by @code{AS_IF} is useful
+in @file{configure.ac}, outside of macros defined by @code{AC_DEFUN}
+or @code{AC_DEFUN_ONCE}.  Inside macros defined by @code{AC_DEFUN}
+or @code{AC_DEFUN_ONCE}, @code{AS_IF} and the plain shell @samp{if}
+syntax are equivalent.
 @end defmac
 
 @defmac AS_MKDIR_P (@var{file-name})
-- 
2.7.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.