Next: , Previous: Polymorphic Variables, Up: Programming in M4sh


9.3 Initialization Macros

— Macro: AS_BOURNE_COMPATIBLE

Set up the shell to be more compatible with the Bourne shell as standardized by Posix, if possible. This may involve setting environment variables, or setting options, or similar implementation-specific actions. This macro is deprecated, since AS_INIT already invokes it.

— Macro: AS_INIT

Initialize the M4sh environment. This macro calls m4_init, then outputs the #! /bin/sh line, a notice about where the output was generated from, and code to sanitize the environment for the rest of the script. Among other initializations, this sets SHELL to the shell chosen to run the script (see CONFIG_SHELL), and LC_ALL to ensure the C locale. Finally, it changes the current diversion to BODY.

— Macro: AS_INIT_GENERATED (file, [comment])

Emit shell code to start the creation of a subsidiary shell script in file, including changing 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 AS_INIT, AS_BOURNE_COMPATIBLE, and AS_SHELL_SANITIZE). If present, comment is output near the beginning of the child, prior to the shell initialization code, and is subject to parameter expansion, command substitution, and backslash quote removal. The parent script should check the exit status after this macro, in case 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 if the parent script uses logging (see AS_MESSAGE_LOG_FD), you must temporarily disable any attempts to use the log file until after emitting code to open a log within the child. On the other hand, if the parent script has AS_MESSAGE_FD redirected somewhere besides ‘1’, then the child script already has code that copies stdout to that descriptor. Currently, the suggested idiom for writing a M4sh shell script from within another script is:

          AS_INIT_GENERATED([file], [[# My child script.
          ]]) || { AS_ECHO(["Failed to create child script"]); AS_EXIT; }
          m4_pushdef([AS_MESSAGE_LOG_FD])dnl
          cat >> "file" <<\__EOF__
          # Code to initialize AS_MESSAGE_LOG_FD
          m4_popdef([AS_MESSAGE_LOG_FD])dnl
          # Additional code
          __EOF__

This, however, may change in the future as the M4sh interface is stabilized further.

Also, be aware that use of LINENO within the child script may report line numbers relative to their location in the parent script, even when using AS_LINENO_PREPARE, if the parent script was unable to locate a shell with working LINENO support.

— Macro: AS_LINENO_PREPARE

Find a shell that supports the special variable LINENO, which contains the number of the currently executing line. This macro is automatically invoked by AC_INIT in configure scripts.

— Macro: AS_ME_PREPARE

Set up variable as_me to be the basename of the currently executing script. This macro is automatically invoked by AC_INIT in configure scripts.

— Macro: AS_SHELL_SANITIZE

Initialize the shell suitably for configure scripts. This has the effect of AS_BOURNE_COMPATIBLE, and sets some other environment variables for predictable results from configuration tests. For example, it sets LC_ALL to change to the default C locale. See Special Shell Variables. This macro is deprecated, since AS_INIT already invokes it.