autoconf-patches
[Top][All Lists]
Advanced

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

AS_INIT_GENERATED [was: AS_VAR_ARITH]


From: Eric Blake
Subject: AS_INIT_GENERATED [was: AS_VAR_ARITH]
Date: Tue, 28 Oct 2008 22:47:35 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Paolo Bonzini <bonzini <at> gnu.org> writes:

> > We probably ought to change the API of AS_INIT_GENERATED to actually take 
the 
> > filename of the child script, so that we can swap between quoted and 
unquoted 
> > here-docs at will, rather than the current interface where 
AS_INIT_GENERATED is 
> > only a snippet that must occur in a quoted heredoc.  That way, we can also 
> > subsume the recommendation about starting the child script with #!$SHELL 
rather 
> > than #!/bin/sh.  We haven't released an autoconf version with 
AS_INIT_GENERATED 
> > yet, so we are still free to improve this API.
> 
> This should be done first.
> 

How does this look?  Should we output a Copyright comment at the head of the 
child script (right now, config.status has a copyright notice embedded down in 
the argument parsing, but nothing in the first few lines of the file).


From: Eric Blake <address@hidden>
Date: Tue, 28 Oct 2008 16:37:54 -0600
Subject: [PATCH] Alter signature of AS_INIT_GENERATED.

* lib/m4sugar/m4sh.m4 (AS_INIT_GENERATED): Add parameters, and
manage here-doc and chmod in place.  This also allows future
changes for optimizing the child via diversion/m4_wrap magic.
* lib/autoconf/status.m4 (_AC_OUTPUT_CONFIG_STATUS): Update
caller.
* doc/autoconf.texi (Initialization Macros) <AS_INIT_GENERATED>:
Update the documentation.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog              |   11 ++++++++
 doc/autoconf.texi      |   60 ++++++++++++++++++++++-------------------------
 lib/autoconf/status.m4 |   17 ++++---------
 lib/m4sugar/m4sh.m4    |   34 ++++++++++++++++++++------
 4 files changed, 70 insertions(+), 52 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fb5bfde..56b775b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2008-10-28  Eric Blake  <address@hidden>
 
+       Alter signature of AS_INIT_GENERATED.
+       * lib/m4sugar/m4sh.m4 (AS_INIT_GENERATED): Add parameters, and
+       manage here-doc and chmod in place.  This also allows future
+       changes for optimizing the child via diversion/m4_wrap magic.
+       * lib/autoconf/status.m4 (_AC_OUTPUT_CONFIG_STATUS): Update
+       caller.
+       * doc/autoconf.texi (Initialization Macros) <AS_INIT_GENERATED>:
+       Update the documentation.
+
+2008-10-28  Eric Blake  <address@hidden>
+
        Use _m4_stack_reverse in m4_set.
        * lib/m4sugar/m4sugar.m4 (_m4_set_contents_1)
        (_m4_set_contents_2): Rewrite to share _m4_stack_reverse
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index d315ebb..4291bf9 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -12157,7 +12157,7 @@ Polymorphic Variables
 @asindex{VAR_COPY}
 Emit shell code to assign the contents of the polymorphic shell variable
 @var{source} to the polymorphic shell variable @var{dest}.  For example,
-executing this m4sh snippet will output @samp{bar hi}:
+executing this M4sh snippet will output @samp{bar hi}:
 
 @example
 foo=bar bar=hi
@@ -12197,7 +12197,7 @@ Polymorphic Variables
 @asindex{VAR_POPDEF}
 @cindex composing variable names
 @cindex variable names, composing
-A common m4sh idiom involves composing shell variable names from an m4
+A common M4sh idiom involves composing shell variable names from an m4
 argument (for example, writing a macro that uses a cache variable).
 @var{value} can be an arbitrary string, which will be transliterated
 into a valid shell name by @code{AS_TR_SH}.  In order to access the
@@ -12286,38 +12286,34 @@ Initialization Macros
 script.  Finally, it changes the current diversion to @code{BODY}.
 @end defmac
 
address@hidden AS_INIT_GENERATED
address@hidden AS_INIT_GENERATED (@var{file}, @ovar{comment})
 @asindex{INIT_GENERATED}
-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.
-In particular, a line containing @code{#!$SHELL} must have already been
-emitted to the child script; you should not use @code{#!/bin/sh}, or the
-child script will not use the more modern shell that the parent script
-might have detected.  Likewise, the child script starts life without a
-log file open, so you must temporarily disable any attempts to use the
-log file until after emitting code to open a log within the child.
-Currently, the suggested idiom for writing a M4sh
-shell script from within another script is:
-
address@hidden
+Emit shell code to start the creation of a subsidiary shell script in
address@hidden, including changing @var{file} to be executable.  This macro
+populates the child script with information learned from the parent
+(thus, the emitted code is equivalent in effect, but more efficient,
+than the code output by @code{AS_INIT}, @code{AS_BOURNE_COMPATIBLE}, and
address@hidden).  If present, @var{comment} is output near the
+beginning of the child, prior to the shell initialization code.  The
+parent script should check the exit status after this macro, in case
address@hidden could not be properly created (for example, if the disk was
+full).  If successfully created, the parent script can then proceed to
+append additional M4sh constructs into the child script.
+
+Note that the child script starts life without a log file open, so you
+must temporarily disable any attempts to use the log file until after
+emitting code to open a log within the child.  Currently, the suggested
+idiom for writing a M4sh shell script from within another script is:
+
address@hidden
+AS_INIT_GENERATED(address@hidden, [[# My child script.
+]]) || @{ AS_ECHO(["Failed to create child script"]); AS_EXIT; @}
 m4_pushdef([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__
+cat >> "@var{file}" <<\__EOF__
+# Code to initialize AS_MESSAGE_LOG_FD
 m4_popdef([AS_MESSAGE_LOG_FD])dnl
+# Additional code
+__EOF__
 @end example
 
 This, however, may change in the future as the M4sh interface is
@@ -15473,7 +15469,7 @@ Limitations of Builtins
 The portable solution is then simple: when you want to @samp{exit 42},
 run @samp{(exit 42); exit 42}, the first @command{exit} being used to
 set the exit status to 42 for Zsh, and the second to trigger the trap
-and pass 42 as exit status for Bash.  In m4sh, this is covered by using
+and pass 42 as exit status for Bash.  In M4sh, this is covered by using
 @code{AS_EXIT}.
 
 The shell in address@hidden 4.0 has the following bug: @samp{$?} is
diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4
index 54758b1..9ee4b2a 100644
--- a/lib/autoconf/status.m4
+++ b/lib/autoconf/status.m4
@@ -1319,25 +1319,19 @@ fi
 m4_define([_AC_OUTPUT_CONFIG_STATUS],
 [AC_MSG_NOTICE([creating $CONFIG_STATUS])
 dnl AS_MESSAGE_LOG_FD is not available yet:
-m4_pushdef([AS_MESSAGE_LOG_FD])dnl
-cat >$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-#! $SHELL
-# Generated by $as_me.
-# Run this file to recreate the current configuration.
+m4_pushdef([AS_MESSAGE_LOG_FD])]dnl
+[AS_INIT_GENERATED([$CONFIG_STATUS],
+[# Run this file to recreate the current configuration.
 # Compiler output produced by configure, useful for debugging
 # configure, is in config.log if it exists.
 
 debug=false
 ac_cs_recheck=false
 ac_cs_silent=false
-SHELL=\${CONFIG_SHELL-$SHELL}
-_ACEOF
+]) || ac_write_fail=1
 
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-AS_INIT_GENERATED
-exec AS_MESSAGE_FD>&1
-
-# Save the log message, to keep $[0] and so on meaningful, and to
+[#] Save the log message, to keep $[0] and so on meaningful, and to
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
@@ -1576,7 +1570,6 @@ m4_ifdef([_AC_SEEN_CONFIG(ANY)], [_AC_OUTPUT_MAIN_LOOP])[]
dnl
 
 AS_EXIT(0)
 _ACEOF
-chmod +x $CONFIG_STATUS
 ])# _AC_OUTPUT_CONFIG_STATUS
 
 # _AC_OUTPUT_MAIN_LOOP
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 7ba1adf..dff8263 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -1828,16 +1828,34 @@ m4_define([AS_VAR_TEST_SET],
 ## -------------------- ##
 
 
-# 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.
+# AS_INIT_GENERATED(FILE, [COMMENT])
+# ----------------------------------
+# Generate a child script FILE with all initialization necessary to
+# reuse the environment learned by the parent script, and make the
+# file executable.  If COMMENT is supplied, it is inserted after the
+# `#!' sequence but before initialization text begins.  After this
+# macro, additional text can be appended to FILE to form the body of
+# the child script.  The macro ends with non-zero status if the
+# file could not be fully written (such as if the disk is full).
 m4_defun([AS_INIT_GENERATED],
 [m4_require([AS_PREPARE])]dnl
-[_AS_SHELL_SANITIZE
-_AS_PREPARE])
+[m4_pushdef([AS_MESSAGE_LOG_FD])]dnl
+[as_write_fail=0
+cat >$1 <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+$2
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ASEOF
+cat >>$1 <<\_ASEOF || as_write_fail=1
+_AS_SHELL_SANITIZE
+_AS_PREPARE
+exec AS_MESSAGE_FD>&1
+m4_text_box([Main body of $1 script.])
+_ASEOF
+test $as_write_fail = 0 && chmod +x $1[]dnl
+_m4_popdef([AS_MESSAGE_LOG_FD])])# AS_INIT_GENERATED
+
 
 # AS_INIT
 # -------
-- 
1.6.0.2







reply via email to

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