autoconf-patches
[Top][All Lists]
Advanced

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

Re: Multi-Line Definitions


From: Ralf Wildenhues
Subject: Re: Multi-Line Definitions
Date: Tue, 18 Sep 2007 21:31:46 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

Hello Eric,

* Eric Lemings wrote on Mon, Sep 17, 2007 at 11:53:23PM CEST:
> 
> I have a Autoconf M4 macro that defines a multi-line preprocessor
> symbol.
[...]
> How hard would it be to handle such macro definitions?  Is it even
> possible?

Multi-line AC_DEFINEs are not supported currently.  Recently (in
Autoconf 2.60), support for multi-line AC_SUBSTs has been implemented.

Why do you need them?  This is an serious question: The preprocessor
will turn your multi-line define into a single-line one anyway.

If we implement them, what should be the semantics: newlines are
interpreted as backslash-newline, or only backslash-newline is accepted?
Here it is useful to consider that users may generate output files that
will not be input to a C preprocessor, but some other, similar language.

Implementation-wise, there is the real issue of line length limitations
(in sed, grep, uniq, allowed text file length, the C preprocessor; 2000
bytes should be ok portably).

Ignoring that, and assuming we only care about backslash-newline like in
Eric's example, a patch like the one below would be sufficient, but
config.h would not be any more readable than if you would not use
newlines in the first place.  OK to apply?  AFAICS it's a strict
improvement over what we have now.  OTOH I'm not sure what to do with
the XFAILing `Define a newline' test we have now in tests/torture.at.

Getting the multi-line values through the whole machinery and at the
same time allowing values of arbitrary length (thus the need to either
retain backslash-newlines or insert some after certain lengths) or even
preserving readability of config.h (thus the need to retain the original
backslash-newlines) is more work.  Extrapolating from the AC_SUBST work,
several weeks.  @DEFS@ would be another step ('make' implementations
have ugly length limits too), but I would not see that as a priority,
as it can be worked around using AC_CONFIG_HEADERS.

Cheers, and thanks for the report,
Ralf

2007-09-18  Ralf Wildenhues  <address@hidden>

        * lib/autoconf/status.m4 (_AC_OUTPUT_HEADER, AC_OUTPUT_MAKE_DEFS):
        Remove backslash-newline combinations from define values.
        * doc/autoconf.texi (Defining Symbols): Adjust.
        * NEWS: Update.
        * tests/torture.at (#define header templates): Extend test.
        Suggestion by Eric Lemings.

Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.439
diff -u -r1.439 NEWS
--- NEWS        15 Sep 2007 12:41:08 -0000      1.439
+++ NEWS        18 Sep 2007 19:28:15 -0000
@@ -34,6 +34,9 @@
    if found, and it works to link against a file of the same name in
    the source tree, even if both trees coincide.
 
+** AC_DEFINE and AC_DEFINE_UNQUOTED now handle multi-line values, i.e.,
+   backslash-newline combinations are handled correctly.
+
 ** AC_INIT no longer alters $@; regression introduced in 2.60.
 
 ** AC_USE_SYSTEM_EXTENSIONS now defines _ALL_SOURCE for Interix platforms.
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1176
diff -u -r1.1176 autoconf.texi
--- doc/autoconf.texi   15 Sep 2007 12:41:08 -0000      1.1176
+++ doc/autoconf.texi   18 Sep 2007 19:28:28 -0000
@@ -8493,10 +8493,11 @@
 backslash-newlines, universal character names, or address@hidden
 characters.
 
address@hidden should not contain literal newlines, and if you are not
-using @code{AC_CONFIG_HEADERS} it should not contain any @samp{#}
-characters, as @command{make} tends to eat them.  To use a shell variable,
-use @code{AC_DEFINE_UNQUOTED} instead.
address@hidden may contain backslash-escaped newlines; they may be removed
+in the generated header file.  If you are not using
address@hidden, @var{value} should not contain any @samp{#}
+characters, as @command{make} tends to eat them.  To use a shell
+variable, use @code{AC_DEFINE_UNQUOTED} instead.
 @var{description} is only useful if you are using
 @code{AC_CONFIG_HEADERS}.  In this case, @var{description} is put into
 the generated @file{config.h.in} as the comment before the macro define.
Index: lib/autoconf/status.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/status.m4,v
retrieving revision 1.138
diff -u -r1.138 status.m4
--- lib/autoconf/status.m4      13 Sep 2007 21:51:19 -0000      1.138
+++ lib/autoconf/status.m4      18 Sep 2007 19:28:28 -0000
@@ -724,7 +724,13 @@
 dnl The first use of ac_dA has a space prepended, so that the second
 dnl use does not match the initial 's' of $ac_dA.
 [
-uniq confdefs.h |
+sed ':mline
+     /\\$/{
+     N
+     s,\\\n,,
+     b mline
+   }' confdefs.h |
+  uniq |
   sed -n '
        t rset
        :rset
@@ -1611,6 +1617,12 @@
 # take arguments), then branch to the quote section.  Otherwise,
 # look for a macro that doesn't take arguments.
 ac_script='
+:mline
+/\\$/{
+ N
+ s,\\\n,,
+ b mline
+}
 t clear
 :clear
 s/^[    ]*#[    ]*define[       ][      ]*\([^  (][^    (]*([^)]*)\)[   
]*\(.*\)/-D\1=\2/g
Index: tests/torture.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/torture.at,v
retrieving revision 1.85
diff -u -r1.85 torture.at
--- tests/torture.at    18 Aug 2007 09:07:21 -0000      1.85
+++ tests/torture.at    18 Sep 2007 19:28:28 -0000
@@ -333,6 +333,12 @@
 AC_DEFINE(a, A)
 AC_DEFINE(aaa, AAA)
 AC_DEFINE(aa, AA)
+
+# backslash-newline combinations
+AC_DEFINE(multiline, line1\
+line2\
+line3 \
+line4)
 AC_CONFIG_FILES(defs)
 
 # Things included in confdefs.h, but which make no sense in
@@ -366,6 +372,7 @@
 #undef a
 #undef aa
 #undef aaa
+#undef multiline
 ]])
 
 AT_CHECK_AUTOCONF
@@ -383,12 +390,13 @@
 #define a A
 #define aa AA
 #define aaa AAA
+#define multiline line1line2line3 line4
 ]])
 AT_CHECK([cat config.h], 0, expout)
 
 # Check the value of DEFS.
 AT_DATA([expout],
-[[-DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" 
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -Dfoo=toto -Dbar=tata -Dbaz=titi 
-Dfubar=tutu -Da=A -Daaa=AAA -Daa=AA
+[[-DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" 
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -Dfoo=toto -Dbar=tata -Dbaz=titi 
-Dfubar=tutu -Da=A -Daaa=AAA -Daa=AA -Dmultiline=line1line2line3\ line4
 ]])
 
 # Because we strip trailing spaces in `testsuite' we can't leave one in




reply via email to

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