autoconf-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Autoconf source repository branch, master, updated. v2.63b-20-


From: Eric Blake
Subject: [SCM] GNU Autoconf source repository branch, master, updated. v2.63b-20-ge9a5c22
Date: Tue, 14 Apr 2009 12:57:52 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Autoconf source repository".

http://git.sv.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=e9a5c2211af530705faca81f97bcd245de362154

The branch, master has been updated
       via  e9a5c2211af530705faca81f97bcd245de362154 (commit)
       via  d7f226ee0b85088148d55a51b489b01215beba52 (commit)
       via  0cd7cde0607fff469ac42f173e36c2dd8aad7ea3 (commit)
       via  ff97bd9a3f2649a407dccf3ca0cb8f890264aa68 (commit)
       via  52b83b8c374080dceeaeec57b80a6ed0d2b3d38f (commit)
       via  723c9e5c0f2c3aa7ef46534ad084974fa2282435 (commit)
      from  15163ab08a7fa5bf47eaec1a7793f97a0e261613 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e9a5c2211af530705faca81f97bcd245de362154
Author: Eric Blake <address@hidden>
Date:   Fri Apr 10 14:43:33 2009 -0600

    Improve documentation related to expanded-before-required.
    
    * doc/autoconf.texi (Expanded Before Required): Add a case study.
    (Running the Compiler) <AC_COMPILE_IFELSE>: Remind users that
    running a compile test will AC_REQUIRE the compiler check.
    (Macro Definitions) <AC_DEFUN>: Contrast AC_DEFUN and m4_define.
    (C Compiler) <AC_PROG_CC>: Mention the fact that only first
    invocation of this macro checks for $EXEEXT, and that many other
    macros use it via AC_REQUIRE.
    Reported by Andreas Schwab.
    
    Signed-off-by: Eric Blake <address@hidden>

commit d7f226ee0b85088148d55a51b489b01215beba52
Author: Eric Blake <address@hidden>
Date:   Fri Apr 10 10:56:40 2009 -0600

    Mention latest rules about make and set -e.
    
    * doc/autoconf.texi (Failure in Make Rules): Posix is now clear
    that make must use set -e.
    (Limitations of Builtins) <set>: Clarify more about set -e
    behavior.
    
    Signed-off-by: Eric Blake <address@hidden>

commit 0cd7cde0607fff469ac42f173e36c2dd8aad7ea3
Author: Eric Blake <address@hidden>
Date:   Thu Apr 9 22:33:37 2009 -0600

    Improve documentation about if exit status.
    
    * doc/autoconf.texi (Limitations of Builtins) <if>: Mention that
    exit status bugs don't affect modern targets.
    Reported by Andreas Schwab.
    
    Signed-off-by: Eric Blake <address@hidden>

commit ff97bd9a3f2649a407dccf3ca0cb8f890264aa68
Author: Eric Blake <address@hidden>
Date:   Thu Apr 9 23:00:22 2009 -0600

    Add cross-reference to new macros.
    
    * doc/autoconf.texi (Text processing Macros) <m4_normalize>
    <m4_strip>: Reference the new m4_ifblank.
    Suggested by Mike Frysinger.
    
    Signed-off-by: Eric Blake <address@hidden>

commit 52b83b8c374080dceeaeec57b80a6ed0d2b3d38f
Author: Eric Blake <address@hidden>
Date:   Thu Apr 9 21:45:18 2009 -0600

    Make AS_IF, AS_CASE, and AS_FOR more robust to blank arguments.
    
    * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT, AS_FOR, _AS_IF)
    (_AS_IF_ELSE, AS_IF): Avoid syntax error on blank argument,
    including a macro with an empty expansion.
    * NEWS: Mention this.
    * tests/m4sh.at (AS@&address@hidden and AS@&address@hidden, 
AS@&address@hidden): Update
    tests.
    Reported by Mike Frysinger.
    
    Signed-off-by: Eric Blake <address@hidden>

commit 723c9e5c0f2c3aa7ef46534ad084974fa2282435
Author: Eric Blake <address@hidden>
Date:   Thu Apr 9 07:05:00 2009 -0600

    Add m4_blank and friends.
    
    * lib/m4sugar/m4sugar.m4 (m4_blank, m4_nblank, m4_default_nblank)
    (m4_default_nblank_quoted): New macros.
    * NEWS: Document them.
    * doc/autoconf.texi (Conditional constructs): Likewise.
    * tests/m4sugar.at (m4sugar shorthand conditionals): New test.
    Suggested by Mike Frysinger.
    
    Signed-off-by: Eric Blake <address@hidden>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog              |   45 +++++++++
 NEWS                   |    6 +
 doc/autoconf.texi      |  247 +++++++++++++++++++++++++++++++++++++++++++-----
 lib/m4sugar/m4sh.m4    |   29 +++---
 lib/m4sugar/m4sugar.m4 |   47 ++++++++-
 tests/m4sh.at          |   11 ++-
 tests/m4sugar.at       |   85 +++++++++++++++++
 7 files changed, 428 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index efa2056..c1894d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,50 @@
 2009-04-13  Eric Blake  <address@hidden>
 
+       Improve documentation related to expanded-before-required.
+       * doc/autoconf.texi (Expanded Before Required): Add a case study.
+       (Running the Compiler) <AC_COMPILE_IFELSE>: Remind users that
+       running a compile test will AC_REQUIRE the compiler check.
+       (Macro Definitions) <AC_DEFUN>: Contrast AC_DEFUN and m4_define.
+       (C Compiler) <AC_PROG_CC>: Mention the fact that only first
+       invocation of this macro checks for $EXEEXT, and that many other
+       macros use it via AC_REQUIRE.
+       Reported by Andreas Schwab.
+
+       Mention latest rules about make and set -e.
+       * doc/autoconf.texi (Failure in Make Rules): Posix is now clear
+       that make must use set -e.
+       (Limitations of Builtins) <set>: Clarify more about set -e
+       behavior.
+
+       Improve documentation about if exit status.
+       * doc/autoconf.texi (Limitations of Builtins) <if>: Mention that
+       exit status bugs don't affect modern targets.
+       Reported by Andreas Schwab.
+
+       Add cross-reference to new macros.
+       * doc/autoconf.texi (Text processing Macros) <m4_normalize>
+       <m4_strip>: Reference the new m4_ifblank.
+       Suggested by Mike Frysinger.
+
+       Make AS_IF, AS_CASE, and AS_FOR more robust to blank arguments.
+       * lib/m4sugar/m4sh.m4 (_AS_CASE, _AS_CASE_DEFAULT, AS_FOR, _AS_IF)
+       (_AS_IF_ELSE, AS_IF): Avoid syntax error on blank argument,
+       including a macro with an empty expansion.
+       * NEWS: Mention this.
+       * tests/m4sh.at (AS@&address@hidden and AS@&address@hidden, 
AS@&address@hidden): Update
+       tests.
+       Reported by Mike Frysinger.
+
+       Add m4_blank and friends.
+       * lib/m4sugar/m4sugar.m4 (m4_blank, m4_nblank, m4_default_nblank)
+       (m4_default_nblank_quoted): New macros.
+       * NEWS: Document them.
+       * doc/autoconf.texi (Conditional constructs): Likewise.
+       * tests/m4sugar.at (m4sugar shorthand conditionals): New test.
+       Suggested by Mike Frysinger.
+
+2009-04-13  Eric Blake  <address@hidden>
+
        Finish upgrade to GFDL 1.3.
        * doc/autoconf.texi (copying): Use correct license; comment change
        was missed on 2008-11-04.
diff --git a/NEWS b/NEWS
index e91fc39..8eb3a06 100644
--- a/NEWS
+++ b/NEWS
@@ -3,10 +3,16 @@ GNU Autoconf NEWS - User visible changes.
 * Major changes in Autoconf 2.64 (2009-??-??) [stable]
   Released by Eric Blake, based on git versions 2.63b.*.
 
+** AS_IF, AS_CASE, and AS_FOR have been taught to avoid syntax errors
+   even when given arguments that expand to just whitespace.
+
 ** Ensure AT_CHECK can support commands that include a # given with
    proper m4 quoting.  For shell comments, this is a new feature; for
    non-shell comments, this fixes a regression introduced in 2.63b.
 
+** The following documented m4sugar macros are new:
+   m4_default_nblank  m4_default_nblank_quoted  m4_ifblank  m4_ifnblank
+
 * Major changes in Autoconf 2.63b (2009-03-31) [beta]
   Released by Eric Blake, based on git versions 2.63.*.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 8dd22d6..38b0972 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6737,6 +6737,15 @@ If using the @acronym{GNU} C compiler, set shell 
variable @code{GCC} to
 it to @option{-g -O2} for the @acronym{GNU} C compiler (@option{-O2} on systems
 where @acronym{GCC} does not accept @option{-g}), or @option{-g} for
 other compilers.
+
+Many Autoconf macros use a compiler, and thus call
address@hidden([AC_PROG_CC])} to ensure that the compiler has been
+determined before the body of the outermost @code{AC_DEFUN} macro.
+Although @code{AC_PROG_CC} is safe to directly expand multiple times, it
+performs certain checks (such as the proper value of @env{EXEEXT}) only
+on the first invocation.  Therefore, care must be used when invoking
+this macro from within another macro rather than at the top level
+(@pxref{Expanded Before Required}).
 @end defmac
 
 @anchor{AC_PROG_CC_C_O}
@@ -8371,6 +8380,12 @@ It is customary to report unexpected failures with
 @code{AC_MSG_FAILURE}.  This macro does not try to link; use
 @code{AC_LINK_IFELSE} if you need to do that (@pxref{Running the
 Linker}).
+
+This macro uses @code{AC_REQUIRE} for the compiler associated with the
+current language, which means that if the compiler has not yet been
+determined, the compiler determination will be made prior to the body of
+the outermust @code{AC_DEFUN} macro that triggered this macro to
+expand (@pxref{Expanded Before Required}).
 @end defmac
 
 @ovindex ERL
@@ -10988,25 +11003,74 @@ m4_cond([m4_index([$1], [\])], [-1], [$2],
 
 @defmac m4_default (@var{expr-1}, @var{expr-2})
 @defmacx m4_default_quoted (@var{expr-1}, @var{expr-2})
address@hidden m4_default_nblank (@var{expr-1}, @ovar{expr-2})
address@hidden m4_default_nblank_quoted (@var{expr-1}, @ovar{expr-2})
 @msindex{default}
 @msindex{default_quoted}
-If @var{expr-1} is not empty, use it.  Otherwise, select @var{expr-2}.
address@hidden
address@hidden
+If @var{expr-1} contains text, use it.  Otherwise, select @var{expr-2}.
 @code{m4_default} expands the result, while @code{m4_default_quoted}
 does not.  Useful for providing a fixed default if the expression that
-results in @var{expr-1} would otherwise be empty.
+results in @var{expr-1} would otherwise be empty.  The difference
+between @code{m4_default} and @code{m4_default_nblank} is whether an
+argument consisting of just blanks (space, tab, newline) is
+significant.  When using the expanding versions, note that an argument
+may contain text but still expand to an empty string.
 
 @example
 m4_define([active], [ACTIVE])dnl
+m4_define([empty], [])dnl
 m4_define([demo1], [m4_default([$1], [$2])])dnl
 m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
+m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
+m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
 demo1([active], [default])
 @result{}ACTIVE
 demo1([], [active])
 @result{}ACTIVE
+demo1([empty], [text])
address@hidden
+-demo1([ ], [active])-
address@hidden -
 demo2([active], [default])
 @result{}active
 demo2([], [active])
 @result{}active
+demo2([empty], [text])
address@hidden
+-demo2([ ], [active])-
address@hidden -
+demo3([active], [default])
address@hidden
+demo3([], [active])
address@hidden
+demo3([empty], [text])
address@hidden
+-demo3([ ], [active])-
address@hidden
+demo4([active], [default])
address@hidden
+demo4([], [active])
address@hidden
+demo4([empty], [text])
address@hidden
+-demo4([ ], [active])-
address@hidden
address@hidden example
address@hidden defmac
+
address@hidden m4_ifblank (@var{cond}, @ovar{if-blank}, @ovar{if-text})
address@hidden m4_ifnblank (@var{cond}, @ovar{if-text}, @ovar{if-blank})
address@hidden
address@hidden
+If @var{cond} is empty or consists only of blanks (space, tab, newline),
+then expand @var{if-blank}; otherwise, expand @var{if-text}.  Two
+variants exist, in order to make it easier to select the correct logical
+sense when using only two parameters.  Note that this is more efficient
+than the equivalent behavior of:
address@hidden
+m4_ifval(m4_normalize(address@hidden), @var{if-text}, @var{if-cond})
 @end example
 @end defmac
 
@@ -11762,7 +11826,9 @@ that M4 does not discard leading whitespace during 
argument collection.
 Remove leading and trailing spaces and tabs, sequences of
 backslash-then-newline, and replace multiple spaces, tabs, and newlines
 with a single space.  This is a combination of @code{m4_flatten} and
address@hidden
address@hidden  To determine if @var{string} consists only of bytes
+that would be removed by @code{m4_normalize}, you can use
address@hidden
 @end defmac
 
 @defmac m4_re_escape (@var{string})
@@ -11785,7 +11851,8 @@ Strip whitespace from @var{string}.  Sequences of 
spaces and tabs are
 reduced to a single space, then leading and trailing spaces are removed.
 The result is still a quoted string.  Note that this does not interfere
 with newlines; if you want newlines stripped as well, consider
address@hidden, or do it all at once with @code{m4_normalize}.
address@hidden, or do it all at once with @code{m4_normalize}.  To
+quickly test if @var{string} has only whitespace, use @code{m4_ifblank}.
 @end defmac
 
 @defmac m4_text_box (@var{message}, @dvar{frame, -})
@@ -12945,6 +13012,24 @@ Keep in mind that @code{dnl} is rarely needed to 
introduce comments;
 @code{dnl} is more useful to get rid of the newlines following macros
 that produce no output, such as @code{AC_REQUIRE}.
 
+Public third-party macros need to use @code{AC_DEFUN}, and not
address@hidden, in order to be found by @command{aclocal}
+(@pxref{Extending aclocal,,, automake, @acronym{GNU} Automake}).
+Additionally, if it is ever determined that a macro should be made
+obsolete, it is easy to convert from @code{AC_DEFUN} to @code{AU_DEFUN}
+in order to have @command{autoupdate} assist the user in choosing a
+better alternative, but there is no corresponding way to make
address@hidden issue an upgrade notice (@pxref{AU_DEFUN}).
+
+There is another subtle, but important, difference between using
address@hidden and @code{AC_DEFUN}: only the former is unaffected by
address@hidden  When writing a file, it is always safe to replace a
+block of text with a @code{m4_define} macro that will expand to the same
+text.  But replacing a block of text with an @code{AC_DEFUN} macro with
+the same content does not necessarily give the same results, because it
+changes the location where any embedded but unsatisfied
address@hidden invocations within the block will be expanded.  For an
+example of this, see @ref{Expanded Before Required}.
 
 @node Macro Names
 @section Macro Names
@@ -15784,7 +15869,8 @@ AS_IF([cmp -s file file.new], [], [mv file.new file])
 This is especially useful in other M4 macros, where the @dfn{then} and
 @dfn{else} branches might be macro arguments.
 
-There are shells that do not reset the exit status from an @command{if}:
+Some very old shells did not reset the exit status from an @command{if}
+with no @command{else}:
 
 @example
 $ @kbd{if (exit 42); then true; fi; echo $?}
@@ -15792,9 +15878,10 @@ $ @kbd{if (exit 42); then true; fi; echo $?}
 @end example
 
 @noindent
-whereas a proper shell should have printed @samp{0}.  This is especially
-bad in makefiles since it produces false failures.  This is why properly
-written makefiles, such as Automake's, have such hairy constructs:
+whereas a proper shell should have printed @samp{0}.  But this is no
+longer a portability problem; any shell that supports functions gets it
+correct.  However, it explains why some makefiles have lengthy
+constructs:
 
 @example
 if test -f "$file"; then
@@ -15917,16 +16004,42 @@ better to combine them:
 set -ex
 @end example
 
address@hidden @command{set -e}
+The option @option{-e} has historically been underspecified, with enough
+ambiguities to cause numerous differences across various shell
+implementations.  Perhaps the best reference is
address@hidden://www.opengroup.org/@/austin/@/mailarchives/@/ag-review/@/msg03507.html,
+this link}, recommending a change to Posix 2008 to match @command{ksh88}
+behavior.  Note that mixing @code{set -e} and shell functions is asking
+for surprises:
+
address@hidden
+set -e
+doit()
address@hidden
+  rm file
+  echo one
address@hidden
+doit || echo two
address@hidden example
+
address@hidden
+According to the recommendation, @samp{one} should always be output
+regardless of whether the @command{rm} failed, because it occurs within
+the body of the shell function @samp{doit} invoked on the left side of
address@hidden||}, where the effects of @samp{set -e} are not enforced.
+Likewise, @samp{two} should never be printed, since the failure of
address@hidden does not abort the function, such that the status of
address@hidden is 0.
+
 The @acronym{BSD} shell has had several problems with the @option{-e}
-option, partly because @acronym{BSD} @command{make} traditionally used
address@hidden even though this was incompatible with Posix
-(@pxref{Failure in Make Rules}).  Older versions of the @acronym{BSD}
+option.  Older versions of the @acronym{BSD}
 shell (circa 1990) mishandled @samp{&&}, @samp{||}, @samp{if}, and
 @samp{case} when @option{-e} was in effect, causing the shell to exit
 unexpectedly in some cases.  This was particularly a problem with
 makefiles, and led to circumlocutions like @samp{sh -c 'test -f file ||
 touch file'}, where the seemingly-unnecessary @samp{sh -c '@dots{}'}
-wrapper works around the bug.
+wrapper works around the bug (@pxref{Failure in Make Rules}).
 
 Even relatively-recent versions of the @acronym{BSD} shell (e.g.,
 address@hidden 3.4) wrongly exit with @option{-e} if a command within
@@ -17446,16 +17559,15 @@ later) @command{make} diagnoses these uses and errors 
out.
 @node Failure in Make Rules
 @section Failure in Make Rules
 
-Since 1992 Posix has required that @command{make} must invoke
-each command with the equivalent of a @samp{sh -c} subshell.  However,
-many @command{make} implementations, including @acronym{BSD} make through 2004,
-use @samp{sh -e -c} instead, and the @option{-e} option causes the
-subshell to exit immediately if a subsidiary simple-command fails.  For
-example, the command @samp{touch T; rm -f U} always attempts to
-remove @file{U} with Posix make, but incompatible
address@hidden implementations skip the @command{rm} if the
address@hidden fails.  One way to work around this is to reword the
-affected simple-commands so that they always succeed, e.g., @samp{touch
+Posix 2008 requires that @command{make} must invoke each command with
+the equivalent of a @samp{sh -e -c} subshell, which causes the
+subshell to exit immediately if a subsidiary simple-command fails,
+although not all @command{make} implementations have historically
+followed this rule.  For
+example, the command @samp{touch T; rm -f U} may attempt to
+remove @file{U} even if the @command{touch} fails, although this is not
+permitted with Posix make.  One way to work around failures in simple
+commands is to reword them so that they always succeed, e.g., @samp{touch
 T || :; rm -f U}.
 However, even this approach can run into common bugs in @acronym{BSD}
 implementations of the @option{-e} option of @command{sh} and
@@ -23031,6 +23143,97 @@ by arguments or by the current definition of other 
macros in the m4
 environment, then the macro should always be directly expanded instead
 of required.
 
+For another case study, consider this example trimmed down from an
+actual package.  Originally, the package contained shell code and
+multiple macro invocations at the top level of @file{configure.ac}:
+
address@hidden
+AC_DEFUN([FOO], [AC_COMPILE_IFELSE(address@hidden)])
+foobar=
+AC_PROG_CC
+FOO
address@hidden example
+
address@hidden
+but that was getting complex, so the author wanted to offload some of
+the text into a new macro in another file included via
address@hidden  The na@"ive approach merely wraps the text in a new
+macro:
+
address@hidden
+AC_DEFUN([FOO], [AC_COMPILE_IFELSE(address@hidden)])
+AC_DEFUN([BAR], [
+foobar=
+AC_PROG_CC
+FOO
+])
+BAR
address@hidden example
+
address@hidden
+With older versions of Autoconf, the setting of @samp{foobar=} occurs
+before the single compiler check, as the author intended.  But with
+Autoconf 2.64, this issues the ``expanded before it was required''
+warning for @code{AC_PROG_CC}, and outputs two copies of the compiler
+check, one before @samp{foobar=}, and one after.  To understand why this
+is happening, remember that the use of @code{AC_COMPILE_IFELSE} includes
+a call to @code{AC_REQUIRE([AC_PROG_CC])} under the hood.  According to
+the documented semantics of @code{AC_REQUIRE}, this means that
address@hidden @emph{must} occur before the body of the outermost
address@hidden, which in this case is @code{BAR}, thus preceeding the
+use of @samp{foobar=}.  The older versions of Autoconf were broken with
+regards to the rules of @code{AC_REQUIRE}, which explains why the code
+changed from one over to two copies of @code{AC_PROG_CC} when upgrading
+autoconf.  In other words, the author was unknowingly relying on a bug
+exploit to get the desired results, and that exploit broke once the bug
+was fixed.
+
+So, what recourse does the author have, to restore their intended
+semantics of setting @samp{foobar=} prior to a single compiler check,
+regardless of whether Autoconf 2.63 or 2.64 is used?  One idea is to
+remember that only @code{AC_DEFUN} is impacted by @code{AC_REQUIRE};
+there is always the possibility of using the lower-level
address@hidden:
+
address@hidden
+AC_DEFUN([FOO], [AC_COMPILE_IFELSE(address@hidden)])
+m4_define([BAR], [
+foobar=
+AC_PROG_CC
+FOO
+])
+BAR
address@hidden example
+
address@hidden
+This works great if everything is in the same file.  However, it does
+not help in the case where the author wants to have @command{aclocal}
+find the definition of @code{BAR} from its own file, since
address@hidden requires the use of @code{AC_DEFUN}.  In this case, a
+better fix is to recognize that if @code{BAR} also uses
address@hidden, then there will no longer be direct expansion prior
+to a subsequent require.  Then, by creating yet another helper macro,
+the author can once again guarantee a single invocation of
address@hidden, which will still occur after @code{foobar=}.  The
+author can also use @code{AC_BEFORE} to make sure no other macro
+appearing before @code{BAR} has triggered an unwanted expansion of
address@hidden
+
address@hidden
+AC_DEFUN([FOO], [AC_COMPILE_IFELSE(address@hidden)])
+AC_DEFUN([BEFORE_CC], [
+foobar=
+])
+AC_DEFUN([BAR], [
+AC_BEFORE([$0], [AC_PROG_CC])dnl
+AC_REQUIRE([BEFORE_CC])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+FOO
+])
+BAR
address@hidden example
+
+
 @c ===================================================== History of Autoconf.
 
 @node History
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 2b32802..052c7eb 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -514,14 +514,16 @@ _AS_UNSET_PREPARE
 # | esac
 # The shell comments are intentional, to work around people who don't
 # realize the impacts of using insufficient m4 quoting.  This macro
-# always provides a default case, to work around a Solaris /bin/sh
-# bug regarding the exit status when no case matches.
+# always uses : and provides a default case, to work around Solaris
+# /bin/sh bugs regarding the exit status.
 m4_define([_AS_CASE],
 [ address@hidden:@(]
-  $1[)] m4_default([$2], [:]) ;;])
+  $1[)] :
+    $2 ;;])
 m4_define([_AS_CASE_DEFAULT],
 [ address@hidden:@(]
-  *[)] m4_default([$1], [:]) ;;])
+  *[)] :
+    $1 ;;])
 
 m4_defun([AS_CASE],
 [case $1 in[]m4_map_args_pair([_$0], [_$0_DEFAULT],
@@ -583,8 +585,8 @@ m4_defun([AS_FOR],
 [m4_pushdef([$1], m4_if([$3], [], [[$$2]], m4_translit([$3], ]dnl
 m4_dquote(_m4_defn([m4_cr_symbols2]))[[%+=:,./-]), [], [[$3]], [[$$2]]))]dnl
 [for $2[]m4_ifval([$3], [ in $3])
-do
-  m4_default([$4], [:])
+do :
+  $4
 done[]_m4_popdef([$1])])
 
 
@@ -602,17 +604,18 @@ done[]_m4_popdef([$1])])
 # with simplifications if IF-TRUE1 and/or IF-FALSE is empty.
 #
 m4_define([_AS_IF],
-[elif $1; then
-  m4_default([$2], [:])
+[elif $1; then :
+  $2
 ])
 m4_define([_AS_IF_ELSE],
-[m4_ifvaln([$1],
-[else
-  $1])])
+[m4_ifnblank([$1],
+[else :
+  $1
+])])
 
 m4_defun([AS_IF],
-[if $1; then
-  m4_default([$2], [:])
+[if $1; then :
+  $2
 m4_map_args_pair([_$0], [_$0_ELSE], m4_shift2($@))]dnl
 [fi[]])# AS_IF
 
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 8356d08..420fd99 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -335,6 +335,29 @@ m4_builtin([sinclude], [$1])])
 # it runs TRUE, etc.
 
 
+# m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
+# m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
+# ----------------------------------------
+# If COND is empty, or consists only of blanks (space, tab, newline),
+# then expand IF-BLANK, otherwise expand IF-TEXT.  This differs from
+# m4_ifval only if COND has just whitespace, but it helps optimize in
+# spite of users who mistakenly leave trailing space after what they
+# thought was an empty argument:
+#   macro(
+#         []
+#        )
+#
+# Writing one macro in terms of the other causes extra overhead, so
+# we inline both definitions.
+m4_define([m4_ifblank],
+[m4_if(m4_translit([[$1]],  [ ][       ][
+]), [], [$2], [$3])])
+
+m4_define([m4_ifnblank],
+[m4_if(m4_translit([[$1]],  [ ][       ][
+]), [], [$3], [$2])])
+
+
 # m4_ifval(COND, [IF-TRUE], [IF-FALSE])
 # -------------------------------------
 # If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
@@ -559,31 +582,43 @@ m4_define([m4_define_default],
 
 
 # m4_default(EXP1, EXP2)
-# ----------------------
-# Returns EXP1 if non empty, otherwise EXP2.  Expand the result.
+# m4_default_nblank(EXP1, EXP2)
+# -----------------------------
+# Returns EXP1 if not empty/blank, otherwise EXP2.  Expand the result.
 #
-# This macro is called on hot paths, so inline the contents of m4_ifval,
+# m4_default is called on hot paths, so inline the contents of m4_ifval,
 # for one less round of expansion.
 m4_define([m4_default],
 [m4_if([$1], [], [$2], [$1])])
 
+m4_define([m4_default_nblank],
+[m4_ifblank([$1], [$2], [$1])])
+
 
 # m4_default_quoted(EXP1, EXP2)
-# -----------------------------
-# Returns EXP1 if non empty, otherwise EXP2.  Leave the result quoted.
+# m4_default_nblank_quoted(EXP1, EXP2)
+# ------------------------------------
+# Returns EXP1 if non empty/blank, otherwise EXP2.  Leave the result quoted.
 #
 # For comparison:
 #   m4_define([active], [ACTIVE])
 #   m4_default([active], [default]) => ACTIVE
 #   m4_default([], [active]) => ACTIVE
+#   -m4_default([ ], [active])- => - -
+#   -m4_default_nblank([ ], [active])- => -ACTIVE-
 #   m4_default_quoted([active], [default]) => active
 #   m4_default_quoted([], [active]) => active
+#   -m4_default_quoted([ ], [active])- => - -
+#   -m4_default_nblank_quoted([ ], [active])- => -active-
 #
-# This macro is called on hot paths, so inline the contents of m4_ifval,
+# m4_default macro is called on hot paths, so inline the contents of m4_ifval,
 # for one less round of expansion.
 m4_define([m4_default_quoted],
 [m4_if([$1], [], [[$2]], [[$1]])])
 
+m4_define([m4_default_nblank_quoted],
+[m4_ifblank([$1], [[$2]], [[$1]])])
+
 
 # m4_defn(NAME)
 # -------------
diff --git a/tests/m4sh.at b/tests/m4sh.at
index d747bfe..5f7dc84 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -859,6 +859,11 @@ rm -f file
 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
 dnl The next line is badly underquoted; don't intentionally copy this style.
 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
+dnl Handle blank arguments.
+AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
+) && echo seventeen
+m4_define([empty])AS_IF([false], [:], [empty]
+) && AS_CASE([foo], [foo], [empty]) && echo eighteen
 
 # check that require works correctly
 m4_for([n], 1, 9, [],
@@ -911,6 +916,8 @@ thirteen
 fourteen
 fifteen
 sixteen
+seventeen
+eighteen
 foo1=1 bar1=1
 foo2=2 bar2=
 foo3=3 bar3=
@@ -979,13 +986,15 @@ AS_FOR([m4var], [shvar], ['$list'],
 AS_FOR([m4var], [shvar], [\'],
 [echo "m4var $shvar"])
 
-# Syntax checks: cope with empty arguments.
+# Syntax checks: cope with empty/blank arguments.
 set f g
 AS_FOR([], [shvar], [],
 [echo "m4_defn([]) $shvar"])
 rm -f file
 AS_FOR([], [shvar], [`touch file`])
 test -f file || exit 1
+AS_FOR([], [shvar], [], [ ])
+m4_define([empty])AS_FOR([], [shvar], [], [empty])
 
 # Check that break works.
 while :
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index 6286af2..2dd81dc 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -649,6 +649,91 @@ m
 AT_CLEANUP
 
 
+## ------------------------------------------------- ##
+## m4_ifval, m4_ifblank, m4_ifset, m4_default, etc.  ##
+## ------------------------------------------------- ##
+
+AT_SETUP([m4sugar shorthand conditionals])
+AT_KEYWORDS([m4@&address@hidden m4@&address@hidden m4@&address@hidden 
m4@&address@hidden
+m4@&address@hidden m4@&address@hidden m4@&address@hidden
+m4@&address@hidden)
+
+AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])m4_define([empty])
+m4_ifval([active], [yes], [no])
+m4_ifval([empty], [yes], [no])
+m4_ifval([ ], [yes], [no])
+m4_ifval([], [yes], [no])
+m4_ifblank([active], [yes], [no])
+m4_ifblank([empty], [yes], [no])
+m4_ifblank([ ], [yes], [no])
+m4_ifblank([], [yes], [no])
+m4_ifnblank([active], [yes], [no])
+m4_ifnblank([empty], [yes], [no])
+m4_ifnblank([ ], [yes], [no])
+m4_ifnblank([], [yes], [no])
+m4_ifset([active], [yes], [no])
+m4_ifset([empty], [yes], [no])
+m4_ifset([ ], [yes], [no])
+m4_ifset([], [yes], [no])
+---
+m4_define([demo1], [m4_default([$1], [$2])])dnl
+m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
+m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
+m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
+demo1([active], [default])
+demo1([], [active])
+demo1([empty], [text])
+-demo1([ ], [active])-
+demo2([active], [default])
+demo2([], [active])
+demo2([empty], [text])
+-demo2([ ], [active])-
+demo3([active], [default])
+demo3([], [active])
+demo3([empty], [text])
+-demo3([ ], [active])-
+demo4([active], [default])
+demo4([], [active])
+demo4([empty], [text])
+-demo4([ ], [active])-
+]], [[
+yes
+yes
+yes
+no
+no
+no
+yes
+yes
+yes
+yes
+no
+no
+yes
+no
+no
+no
+---
+ACTIVE
+ACTIVE
+
+- -
+active
+active
+empty
+- -
+ACTIVE
+ACTIVE
+
+-ACTIVE-
+active
+active
+empty
+-active-
+]])
+
+AT_CLEANUP
+
 ## --------- ##
 ## m4_cond.  ##
 ## --------- ##


hooks/post-receive
--
GNU Autoconf source repository




reply via email to

[Prev in Thread] Current Thread [Next in Thread]