[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
m4_append [was: m4_defn overhead]
From: |
Eric Blake |
Subject: |
m4_append [was: m4_defn overhead] |
Date: |
Fri, 12 Oct 2007 21:04:13 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Eric Blake <ebb9 <at> byu.net> writes:
> One more argument in favor of keeping the new m4sugar semantics and merely
> patching libtool to work around the older broken m4_append - prior to now,
> m4_append was undocumented (yet another case of libtool using undocumented
> autoconf internals, without any feedback to the autoconf lists on the
> desirability of documenting them).
I stand corrected. m4_append was never mentioned in NEWS, but it was added in
the manual for 2.60 (still, libtool was using m4_append before it was
documented :)
As a result, here's what I'm committing:
From: Eric Blake <address@hidden>
Date: Thu, 11 Oct 2007 14:46:40 -0600
Subject: [PATCH] Document interaction of recent m4_append change with Libtool
HEAD.
* lib/m4sugar/m4sugar.m4 (m4_append): Document semantics change.
(m4_append_uniq): Add new parameters, based on lt_append_uniq.
* tests/m4sugar.at (m4@&address@hidden): New test.
* NEWS: Document semantics change.
* doc/autoconf.texi (Text processing Macros): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 7 +++++
NEWS | 45 ++++++++++++++++++++++++++++---
doc/autoconf.texi | 46 ++++++++++++++++++++++++++++++--
lib/m4sugar/m4sugar.m4 | 41 +++++++++++++++++++---------
tests/m4sugar.at | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 188 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 80567a5..af30a9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2007-10-12 Eric Blake <address@hidden>
+ Document interaction of recent m4_append change with Libtool HEAD.
+ * lib/m4sugar/m4sugar.m4 (m4_append): Document semantics change.
+ (m4_append_uniq): Add new parameters, based on lt_append_uniq.
+ * tests/m4sugar.at (m4@&address@hidden): New test.
+ * NEWS: Document semantics change.
+ * doc/autoconf.texi (Text processing Macros): Likewise.
+
s/AC_VERSION/AC_AUTOCONF_VERSION/.
* doc/autoconf.texi (Versioning): Change the name.
* NEWS: Likewise.
diff --git a/NEWS b/NEWS
index f24c585..1e87c4d 100644
--- a/NEWS
+++ b/NEWS
@@ -73,10 +73,47 @@ GNU Autoconf NEWS - User visible changes.
Autoconf and Automake. GNU M4 1.4.8 or later is recommended. The
configure search for a working M4 is improved.
-** Document the m4sugar macros m4_ifndef and m4_version_compare
- (available without documentation since at least autoconf 2.53).
- Packages using the undocumented m4sugar macro m4_PACKAGE_VERSION
- should consider using the new AC_AUTOCONF_VERSION instead.
+** Documentation for m4sugar is improved.
+
+ - The following macros were previously available as undocumented
+ interfaces; the macros are now documented as stable interfaces.
+
+ m4_bmatch m4_bpatsubsts m4_case m4_default m4_do m4_ifndef
+ m4_ifset m4_ifval m4_ifvaln m4_n m4_shiftn
+ m4_version_compare m4_warn
+
+ - The following macros were previously available as undocumented
+ interfaces, but had bugs. Packages that relied on the
+ undocumented and buggy behavior should analyze their code to make
+ sure it still works with the new documented behavior.
+
+ m4_text_wrap
+
+ - Packages using the undocumented m4sugar macro m4_PACKAGE_VERSION
+ should consider using the new AC_AUTOCONF_VERSION instead.
+
+ - m4sugar macros that are not documented in the manual are still
+ deemed experimental, and should not be used outside of Autoconf.
+
+** The m4sugar macros m4_append and m4_append_uniq, first documented in
+ 2.60, have been fixed to treat both the string and the separator
+ arguments consistently with regards to quoting. Prior to this fix,
+ m4_append_uniq could mistakenly duplicate entries if the expansion
+ of the separator resulted in a different string (for example, if it
+ contained quotes, a comma, or a macro name). However, it means
+ that programs previously using
+ m4_append([name], [string], [[, ]])
+ are now using a four-character separator instead of the intended
+ comma and space. If you need portability to earlier versions of
+ Autoconf, you can insert the following snippet after AC_INIT but
+ before any other macro expansions, to enforce the new semantics:
+ m4_pushdef([m4_append], [m4_define([$1],
+ m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
+ Additionally, m4_append_uniq now takes optional parameters that can
+ be used to take action depending on whether anything was appended.
+
+** The following m4sugar macros are new:
+ m4_cond m4_newline m4_shift2 m4_shift3
** Warnings are now generated by default when an installer invokes
'configure' with an unknown --enable-* or --with-* option.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index f8550a4..239e56f 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10510,14 +10510,54 @@ single space.
@end defmac
@defmac m4_append (@var{macro-name}, @var{string}, @ovar{separator})
address@hidden m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator})
address@hidden m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator}
@
+ @ovar{if-uniq}, @ovar{if-duplicate})
@msindex{append}
@msindex{append_uniq}
Redefine @var{macro-name} to its former contents with @var{separator}
and @var{string} added at the end. If @var{macro-name} was undefined
before (but not if it was defined but empty), then no @var{separator} is
-added. @code{m4_append} can be used to grow strings, and
address@hidden to grow strings without duplicating substrings.
+added. As of Autoconf 2.62, neither @var{string} nor @var{separator}
+are expanded during this macro; instead, they are expanded when
address@hidden is invoked.
+
address@hidden can be used to grow strings, and @code{m4_append_uniq}
+to grow strings without duplicating substrings. Additionally,
address@hidden takes two optional parameters; @var{if-uniq} is
+expanded if @var{string} was appended, and @var{if-duplicate} is
+expanded if @var{string} was already present.
+
address@hidden
+m4_define([active], [ACTIVE])dnl
+m4_append([sentence], [This is an])dnl
+m4_append([sentence], [ active ])dnl
+m4_append([sentence], [symbol.])dnl
+sentence
address@hidden is an ACTIVE symbol.
+m4_undefine([active])dnl
address@hidden is an active symbol.
+m4_append_uniq([list], [one], [, ], [new], [existing])
address@hidden
+m4_append_uniq([list], [one], [, ], [new], [existing])
address@hidden
+m4_append_uniq([list], [two], [, ], [new], [existing])
address@hidden
+m4_append_uniq([list], [three], [, ], [new], [existing])
address@hidden
+m4_append_uniq([list], [two], [, ], [new], [existing])
address@hidden
+list
address@hidden, two, three
+m4_dquote(list)
address@hidden,[two],[three]
+m4_append([list2], [one], [[, ]])dnl
+m4_append_uniq([list2], [two], [[, ]])dnl
+m4_append([list2], [three], [[, ]])dnl
+list2
address@hidden, two, three
+m4_dquote(list2)
address@hidden, two, three]
address@hidden example
@end defmac
@anchor{m4_version_compare}
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 85f2c72..9904bb1 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -1656,13 +1656,16 @@ m4_defun([m4_join],
# in which case no SEPARATOR is added. Be aware that the criterion is
# `not being defined', and not `not being empty'.
#
+# Note that neither STRING nor SEPARATOR are expanded here; rather, when
+# you expand MACRO-NAME, they will be expanded at that point in time.
+#
# This macro is robust to active symbols. It can be used to grow
# strings.
#
-# | m4_define(active, ACTIVE)
-# | m4_append([sentence], [This is an])
-# | m4_append([sentence], [ active ])
-# | m4_append([sentence], [symbol.])
+# | m4_define(active, ACTIVE)dnl
+# | m4_append([sentence], [This is an])dnl
+# | m4_append([sentence], [ active ])dnl
+# | m4_append([sentence], [symbol.])dnl
# | sentence
# | m4_undefine([active])dnl
# | sentence
@@ -1671,10 +1674,10 @@ m4_defun([m4_join],
#
# It can be used to define hooks.
#
-# | m4_define(active, ACTIVE)
-# | m4_append([hooks], [m4_define([act1], [act2])])
-# | m4_append([hooks], [m4_define([act2], [active])])
-# | m4_undefine([active])
+# | m4_define(active, ACTIVE)dnl
+# | m4_append([hooks], [m4_define([act1], [act2])])dnl
+# | m4_append([hooks], [m4_define([act2], [active])])dnl
+# | m4_undefine([active])dnl
# | act1
# | hooks
# | act1
@@ -1682,20 +1685,32 @@ m4_defun([m4_join],
# =>
# => active
#
+# It can also be used to create lists, although this particular usage was
+# broken prior to autoconf 2.62.
+# | m4_append([list], [one], [, ])dnl
+# | m4_append([list], [two], [, ])dnl
+# | m4_append([list], [three], [, ])dnl
+# | list
+# | m4_dquote(list)
+# => one, two, three
+# => [one],[two],[three]
+#
# Use m4_builtin to avoid overhead of m4_defn.
m4_define([m4_append],
[m4_define([$1],
m4_ifdef([$1], [m4_builtin([defn], [$1])[$3]])[$2])])
-# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR])
-# -----------------------------------------------
-# Like `m4_append', but append only if not yet present.
+# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR], [IF-UNIQ], [IF-DUP])
+# --------------------------------------------------------------------
+# Like `m4_append', but append only if not yet present. Additionally,
+# expand IF-UNIQ if STRING was appended, or IF-DUP if STRING was already
+# present.
m4_define([m4_append_uniq],
[m4_ifdef([$1],
[m4_if(m4_index([$3]m4_builtin([defn], [$1])[$3], [$3$2$3]), [-1],
- [m4_append($@)])],
- [m4_append($@)])])
+ [m4_append([$1], [$2], [$3])$4], [$5])],
+ [m4_append([$1], [$2], [$3])$4])])
# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index 81e7919..3c537e0 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -42,6 +42,8 @@ AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
#
# - m4_split
#
+# - m4_append
+#
# - m4_text_wrap
# uses m4_split code.
@@ -182,6 +184,73 @@ m4_split([foo='' bar=``])
AT_CLEANUP
+## ----------- ##
+## m4_append. ##
+## ----------- ##
+
+AT_SETUP([m4@&address@hidden)
+
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([active], [ACTIVE])dnl
+m4_append([sentence], [This is an])dnl
+m4_append([sentence], [ active ])dnl
+m4_append([sentence], [symbol.])dnl
+sentence
+m4_undefine([active])dnl
+sentence
+m4_define([active], [ACTIVE])dnl
+m4_append([hooks], [m4_define([act1], [act2])])dnl
+m4_append([hooks], [m4_define([act2], [active])])dnl
+m4_undefine([active])dnl
+act1
+hooks
+act1
+dnl Test for bug fixed in 2.62 when separator is active.
+m4_define([a], [A])dnl
+m4_append_uniq([foo], [-], [a])dnl
+m4_append_uniq([foo], [-], [a])dnl
+m4_append_uniq([bar], [-], [a])dnl
+m4_append_uniq([bar], [~], [a])dnl
+m4_append_uniq([bar], [-], [a])dnl
+m4_defn([foo])
+m4_defn([bar])
+foo
+bar
+m4_append_uniq([blah], [one], [, ], [new], [existing])
+m4_append_uniq([blah], [two], [, ], [new], [existing])
+m4_append_uniq([blah], [two], [, ], [new], [existing])
+m4_append_uniq([blah], [three], [, ], [new], [existing])
+m4_append([blah], [two], [, ])dnl
+blah
+m4_dquote(blah)
+m4_append([list], [one], [[, ]])dnl
+m4_append([list], [two], [[, ]])dnl
+m4_append([list], [three], [[, ]])dnl
+list
+m4_dquote(list)
+]],
+[[This is an ACTIVE symbol.
+This is an active symbol.
+act1
+
+active
+-
+-a~
+-
+-A~
+new
+new
+existing
+new
+one, two, three, two
+[one],[two],[three],[two]
+one, two, three
+[one, two, three]
+]])
+
+AT_CLEANUP
+
+
## -------------- ##
## m4_text_wrap. ##
## -------------- ##
--
1.5.3.2
- m4_defn overhead, Eric Blake, 2007/10/10
- Re: m4_defn overhead, Ralf Wildenhues, 2007/10/11
- Re: m4_defn overhead, Eric Blake, 2007/10/11
- Re: m4_defn overhead, Ralf Wildenhues, 2007/10/12
- Re: m4_defn overhead, Eric Blake, 2007/10/12
- Handling of single-quoted comma [was: m4_defn overhead], Eric Blake, 2007/10/15
- Re: Handling of single-quoted comma [was: m4_defn overhead], Ralf Wildenhues, 2007/10/16
- Re: Handling of single-quoted comma [was: m4_defn overhead], Eric Blake, 2007/10/16
- Re: Handling of single-quoted comma [was: m4_defn overhead], Eric Blake, 2007/10/19
- Re: Handling of single-quoted comma [was: m4_defn overhead], Ralf Wildenhues, 2007/10/19
- Re: Handling of single-quoted comma [was: m4_defn overhead], Eric Blake, 2007/10/19
- Re: Handling of single-quoted comma [was: m4_defn overhead], Eric Blake, 2007/10/23
- Re: Handling of single-quoted comma [was: m4_defn overhead], Paolo Bonzini, 2007/10/24