From: Eric Blake Date: Mon, 15 Jun 2009 12:49:58 +0000 (-0600) Subject: Add m4_copy_force, m4_rename_force. X-Git-Tag: v2.64~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba32f02aed51b4781e713cae5a2a73d441088f58;p=thirdparty%2Fautoconf.git Add m4_copy_force, m4_rename_force. * lib/m4sugar/m4sugar.m4 (m4_copy_force, m4_rename_force): New macros. * tests/m4sugar.at (m4@&t@_defn): Test them. * doc/autoconf.texi (Redefined M4 Macros) : Document them. * NEWS: Likewise. Suggested by Ralf Wildenhues. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index f1313f6c8..4acbea59d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2009-06-15 Eric Blake + Add m4_copy_force, m4_rename_force. + * lib/m4sugar/m4sugar.m4 (m4_copy_force, m4_rename_force): New + macros. + * tests/m4sugar.at (m4@&t@_defn): Test them. + * doc/autoconf.texi (Redefined M4 Macros) : Document + them. + * NEWS: Likewise. + Suggested by Ralf Wildenhues. + Reinstate _AC_CHECK_HEADER_OLD for gcc. * lib/autoconf/headers.m4 (_AC_CHECK_HEADER_NEW) (_AC_CHECK_HEADER_OLD): Provide autoupdate versions, since gcc and diff --git a/NEWS b/NEWS index 82ba63515..93a09c9e0 100644 --- a/NEWS +++ b/NEWS @@ -26,8 +26,8 @@ GNU Autoconf NEWS - User visible changes. AT_CHECK_UNQUOTED ** The following documented m4sugar macros are new: - m4_argn m4_default_nblank m4_default_nblank_quoted m4_ifblank - m4_ifnblank + m4_argn m4_copy_force m4_default_nblank m4_default_nblank_quoted + m4_ifblank m4_ifnblank m4_rename_force * 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 9e3327e7c..4b08042a3 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -10642,16 +10642,23 @@ released and supports extended regular expression syntax. @end defmac @defmac m4_copy (@var{source}, @var{dest}) +@defmacx m4_copy_force (@var{source}, @var{dest}) @defmacx m4_rename (@var{source}, @var{dest}) +@defmacx m4_rename_force (@var{source}, @var{dest}) @msindex{copy} +@msindex{copy_force} @msindex{rename} +@msindex{rename_force} These macros aren't directly builtins, but are closely related to -@code{m4_pushdef} and @code{m4_defn}. They both ensure that @var{dest} -is undefined, then proceed to copy the entire pushdef stack of -definitions of @var{source}. @code{m4_copy} preserves the source -(including in the special case where @var{source} is undefined), while -@code{m4_rename} undefines the original macro name (making it an error -to rename an undefined @var{source}). +@code{m4_pushdef} and @code{m4_defn}. @code{m4_copy} and +@code{m4_rename} ensure that @var{dest} is undefined, while +@code{m4_copy_force} and @code{m4_rename_force} overwrite any existing +definition. All four macros then proceed to copy the entire pushdef +stack of definitions of @var{source} over to @var{dest}. @code{m4_copy} +and @code{m4_copy_force} preserve the source (including in the special +case where @var{source} is undefined), while @code{m4_rename} and +@code{m4_rename_force} undefine the original macro name (making it an +error to rename an undefined @var{source}). Note that attempting to invoke a renamed macro might not work, since the macro may have a dependence on helper macros accessed via composition of diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index f5a1f1c1a..83f6dba5d 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -579,7 +579,8 @@ m4_define([_m4_bpatsubsts], # give an error if DST is already defined. This is particularly nice # for copying self-modifying pushdef stacks, where the top definition # includes one-shot initialization that is later popped to the normal -# definition. +# definition. This version intentionally does nothing if SRC is +# undefined. # # Some macros simply can't be renamed with this method: namely, anything # involved in the implementation of m4_stack_foreach_sep. @@ -589,6 +590,19 @@ m4_define([m4_copy], [m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])]) +# m4_copy_force(SRC, DST) +# m4_rename_force(SRC, DST) +# ------------------------- +# Like m4_copy/m4_rename, except blindly overwrite any existing DST. +# Note that m4_copy_force tolerates undefined SRC, while m4_rename_force +# does not. +m4_define([m4_copy_force], +[m4_ifdef([$2], [_m4_undefine([$2])])m4_copy($@)]) + +m4_define([m4_rename_force], +[m4_ifdef([$2], [_m4_undefine([$2])])m4_rename($@)]) + + # m4_define_default(MACRO, VALUE) # ------------------------------- # If MACRO is undefined, set it to VALUE. diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 4bc7bd43c..04f06b9aa 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -104,7 +104,8 @@ AT_CLEANUP AT_SETUP([m4@&t@_defn]) -AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine m4@&t@_copy m4@&t@_rename]) +AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine m4@&t@_copy m4@&t@_rename +m4@&t@_copy_force m4@&t@_rename_force]) # Ensure that m4sugar dies when dereferencing undefined macros, whether # this is provided by m4 natively or faked by wrappers in m4sugar. @@ -161,12 +162,21 @@ m4_popdef([b], [c])dnl a b c dnl m4_copy is intentionally a no-op on undefined source m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl +dnl allow forceful overwrites +m4_define([d], [4])m4_define([e], [5])m4_define([f], [6])dnl +m4_copy_force([d], [e])dnl +m4_rename_force([d], [f])dnl +d e f +m4_popdef([e], [f])dnl +d e f ]], [[0 b c a 0 c a 0 0 a 2 2 a 1 1 a b c +d 4 4 +d e f ]]) AT_CLEANUP