autoconf-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 3/3] add and document AS_INIT_GENERATED


From: Paolo Bonzini
Subject: Re: [PATCH 3/3] add and document AS_INIT_GENERATED
Date: Mon, 13 Oct 2008 15:00:37 +0200
User-agent: Thunderbird 2.0.0.17 (Macintosh/20080914)

> Also, there is the matter that if AS_MESSAGE_LOG_FD is currently defined,
> it must either be temporarily suppressed in m4 so that any AS_MESSAGE
> usage to the child script does not attempt to access a non-existent log,
> or else reopened in shell immediately after AS_INIT_GENERATED.  This is
> probably worth a mention in the manual.

I see... maybe we should provide AS_STATE_PUSH and AS_STATE_POP macros
that do all the required macro resetting, in case in the future other
macros have to be renamed like that.

>> +# AS_INIT_GENERATED
>> +# -----------------
>> +# Emit m4sh initialization code in a suitable form for a here document.
> 
> s/a here document/a quoted here document/
> 
>> +# Does not emit the `#!' sequence, which should be generated with
>> +# `#! $SHELL'.
> 
> Again, I'd be more comfortable also mentioning the SHELL= line, and the
> prefix lines occur in an unquoted here-doc.

I just added a reference to the manual in m4sh.m4.

>> +m4_defun([AS_INIT_GENERATED],
>> +[m4_require([AS_PREPARE])dnl
> 
> Why is the m4_require needed?  Just because the child script is given all
> m4sh features still doesn't explain why we have to blindly enable all m4sh
> features in the parent; isn't an as-needed preparation in the parent
> script still possible?

No.  Say the parent requires feature Z, which adds a suggested test.
The child, instead, requires everything, including feature Y which in
turn adds a required test; so the child requires Y and suggests Z.

Now, suppose that there is a shell on the system that supports {Z} and
one that supports {Y}, but not one that includes {Y,Z}.  Since the child
does not run AS_CLEANUP, it does not have the loop to choose a better
shell; so the child must use the second of the two available shells.
But if you do not do that m4_require here, the parent will provide {Z}
instead.

This is not likely, but neither is it only hypothetical: just replace Z
with $LINENO and Y with shell functions.

I tested the attached patch with "make pdf" too and checked that there
are no overfull hboxes.

Paolo
2008-10-13  Paolo Bonzini  <address@hidden>

        * lib/m4sugar/m4sh.m4 (AS_INIT_GENERATED): New.
        * lib/autoconf/status.m4 (_AC_OUTPUT_CONFIG_STATUS): Use it.
        * doc/autoconf.texi (Initialization macros): Document it.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index d9d82aa..67dbd8b 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -11943,6 +11943,38 @@ generated from, and code to sanitize the environment 
for the rest of the
 script.  Finally, it changes the current diversion to @code{BODY}.
 @end defmac
 
address@hidden AS_INIT_GENERATED
address@hidden
+Initialize the M4sh environment.  This macro emits again all the
+code that is generated by @code{AS_INIT}, including the expansion of
address@hidden and @code{AS_SHELL_SANITIZE}.  It is meant
+to be used in a quoted here document when generating other shell scripts.
+
+Note that @code{AS_INIT_GENERATED} does not emit the entire prolog,
+including the @code{#! /bin/sh} line.  Currently, the suggested idiom
+for writing a M4sh shell script within another script is:
+
address@hidden
+m4_rename([AS_MESSAGE_LOG_FD], [save_AS_MESSAGE_LOG_FD])dnl
+cat > "@var{file}" <<__EOF__
+#! $SHELL
+# Generated by $as_me.
+# ...
+
address@hidden@}
+__EOF__
+
+cat >>"@var{file}" <<\__EOF__
+AS_INIT_GENERATED
+# ...
+__EOF__
+m4_rename([save_AS_MESSAGE_LOG_FD], [AS_MESSAGE_LOG_FD])dnl
address@hidden example
+
+This, however, may change in the future until the M4sh interface is
+stabilized further.
address@hidden defmac
+
 @defmac AS_LINENO_PREPARE
 @asindex{LINENO_PREPARE}
 @evindex LINENO
diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index ddc5f47..6d622b9 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -1332,11 +1332,7 @@ SHELL=\${CONFIG_SHELL-$SHELL}
 _ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-AS_SHELL_SANITIZE
-dnl Watch out, this is directly the initializations, do not use
-dnl AS_PREPARE, otherwise you'd get it output in the initialization
-dnl of configure, not config.status.
-_AS_PREPARE
+AS_INIT_GENERATED
 exec AS_MESSAGE_FD>&1
 
 # Save the log message, to keep $[0] and so on meaningful, and to
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index aa5669b..8d4b07c 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -1688,6 +1688,17 @@ m4_define([AS_VAR_POPDEF],
 ## ----------------- ##
 
 
+# AS_INIT_GENERATED
+# -----------------
+# Emit m4sh initialization code in a suitable form for a quoted
+# here document.  Does not emit the `#!' sequence, which should be
+# generated with `#! $SHELL'; see the manual or autoconf/status.m4
+# for more detail.
+m4_defun([AS_INIT_GENERATED],
+[m4_require([AS_PREPARE])dnl
+AS_SHELL_SANITIZE
+_AS_PREPARE])
+
 # AS_INIT
 # -------
 # Initialize m4sh.

reply via email to

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