@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
@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
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
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
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="
AS_EXIT(0)
_ACEOF
-chmod +x $CONFIG_STATUS
])# _AC_OUTPUT_CONFIG_STATUS
# _AC_OUTPUT_MAIN_LOOP
## -------------------- ##
-# 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
# -------