2009-06-15 Eric Blake <ebb9@byu.net>
+ 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) <m4_copy>: 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
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.*.
@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
# 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.
[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.
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.
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