From: Eric Blake Date: Tue, 28 Oct 2008 22:37:54 +0000 (-0600) Subject: Alter signature of AS_INIT_GENERATED. X-Git-Tag: v2.63b~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7abb73425a0fc9dbe5787b991be21969c6722deb;p=thirdparty%2Fautoconf.git 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) : Update the documentation. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index d457f9923..b115e0a47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-10-29 Eric Blake + + 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) : + Update the documentation. + 2008-10-29 Eric Blake Use _m4_stack_reverse in m4_set. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index f2a79237b..1a2f748ff 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -12162,7 +12162,7 @@ echo "(2+$bar)*4 == $foo" @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 @@ -12202,7 +12202,7 @@ in @var{var} is being expanded. @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 @@ -12291,38 +12291,34 @@ 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 -@defmac AS_INIT_GENERATED +@defmac 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 -@code{AS_BOURNE_COMPATIBLE} 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: - -@example +Emit shell code to start the creation of a subsidiary shell script in +@var{file}, 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 +@code{AS_SHELL_SANITIZE}). 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 +@var{file} 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: + +@example +AS_INIT_GENERATED([@var{file}], [[# 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. -# ... - -SHELL=\$@{CONFIG_SHELL-$SHELL@} -__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 @@ -15478,7 +15474,7 @@ $ @kbd{bash trap.sh} 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 Free@acronym{BSD} 4.0 has the following bug: @samp{$?} is diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4 index 54758b111..9ee4b2ac0 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 9463c61e7..187920c17 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 # -------