Next: Bugs, Previous: History, Up: Preliminaries
m4
The format of the m4
command is:
m4
[option...] [file...]
All options begin with `-', or if long option names are used, with `--'. A long option name need not be written completely, any unambiguous prefix is sufficient. Unless POSIXLY_CORRECT is set in the environment, options may be intermixed with files. The argument -- is a marker to denote the end of options.
With short options, options that do not take arguments may be combined into a single command line argument with subsequent options, options with mandatory arguments may be provided either as a single command line argument or as two arguments, and options with optional arguments must be provided as a single argument. In other words, without POSIXLY_CORRECT, m4 -QPDfoo -d a -d+f is equivalent to m4 -Q -P -D foo -d -d+f -- a, although the latter form is considered canonical. (With POSIXLY_CORRECT, it is equivalent to m4 -Q -P -D foo -d -- a ./-d+f).
With long options, options with mandatory arguments may be provided with
an equal sign (`=') in a single argument, or as two arguments, and
options with optional arguments must be provided as a single argument.
In other words, m4 --def foo --debug a is equivalent to
m4 --define=foo --debug= -- a, although the latter form is
considered canonical (not to mention more robust, in case a future
version of m4
introduces an option named --default).
m4
understands the following options, grouped by functionality.
Several options control the overall operation of m4
:
--help
m4
without reading any input files.
--version
m4
without reading any input files.
-E
--fatal-warnings
m4
once the first warning has been
issued, considering all of them to be fatal.
-i
--interactive
-e
m4
interactive. This means that all
output will be unbuffered, and interrupts will be ignored. The
spelling -e exists for compatibility with other m4
implementations, and issues a warning because it may be withdrawn in a
future version of GNU M4.
-P
--prefix-builtins
-Q
--quiet
--silent
-W
REGEXP--word-regexp=
REGEXPm4
implementations (see Changeword).
Several options allow m4
to behave more like a preprocessor.
Macro definitions and deletions can be made on the command line, the
search path can be altered, and the output file can track where the
input came from. These features occur with the following options:
-D
NAME[=
VALUE]--define=
NAME[=
VALUE]-I
DIRECTORY--include=
DIRECTORYm4
search DIRECTORY for included files that are not
found in the current working directory. See Search Path, for more
details. This option may be given more than once.
-s
--synclines
m4
is used as a
front end to a compiler. Source file name and line number information
is conveyed by directives of the form `#line linenum
"file"', which are inserted as needed into the middle of the
output. Such directives mean that the following line originated or was
expanded from the contents of input file file at line
linenum. The `"file"' part is often omitted when
the file name did not change from the previous directive.
Synchronization directives are always given on complete lines by
themselves. When a synchronization discrepancy occurs in the middle of
an output line, the associated synchronization directive is delayed
until the beginning of the next generated line.
-U
NAME--undefine=
NAMEThere are some limits within m4
that can be tuned. For
compatibility, m4
also accepts some options that control limits
in other implementations, but which are automatically unbounded (limited
only by your hardware constraints) in GNU m4
.
-G
--traditional
-H
NUM--hashsize=
NUM-L
NUM--nesting-limit=
NUMThe precise effect of this option might be more correctly associated
with textual nesting than dynamic recursion. It has been useful
when some complex m4
input was generated by mechanical means.
Most users would never need this option. If shown to be obtrusive,
this option (which is still experimental) might well disappear.
This option does not have the ability to break endless
rescanning loops, since these do not necessarily consume much memory
or stack space. Through clever usage of rescanning loops, one can
request complex, time-consuming computations from m4
with useful
results. Putting limitations in this area would break m4
power.
There are many pathological cases: `define(`a', `a')a' is
only the simplest example (but see Compatibility). Expecting GNU
m4
to detect these would be a little like expecting a compiler
system to detect and diagnose endless loops: it is a quite hard
problem in general, if not undecidable!
-B
NUM-S
NUM-T
NUMm4
, but
do nothing in this implementation. They may disappear in future
releases, and issue a warning to that effect.
-N
NUM--diversions=
NUMm4
, and were controlling the number of
possible diversions which could be used at the same time. They do nothing,
because there is no fixed limit anymore. They may disappear in future
releases, and issue a warning to that effect.
GNU m4
comes with a feature of freezing internal state
(see Frozen files). This can be used to speed up m4
execution when reusing a common initialization script.
-F
FILE--freeze-state=
FILE-R
FILE--reload-state=
FILEFinally, there are several options for aiding in debugging m4
scripts.
-d
[FLAGS]--debug
[=
FLAGS]--debugfile=
FILE-o
FILE--error-output=
FILEdumpdef
output, debug messages, and trace output to the
named FILE. Warnings, error messages, and errprint
output
are still printed to standard error. If unspecified, debug output goes
to standard error; if empty, debug output is discarded. See Debug Output, for more details. The spellings -o and
--error-output are misleading and inconsistent with other
GNU tools; for now they are silently accepted as synonyms of
--debugfile, but in a future version of M4, using them will
cause a warning to be issued.
-l
NUM--arglength=
NUM-t
NAME--trace=
NAMEThe remaining arguments on the command line are taken to be input file names. If no names are present, the standard input is read. A file name of - is taken to mean the standard input. It is conventional, but not required, for input files to end in `.m4'.
The input files are read in the sequence given. Standard input can be read more than once, so the file name - may appear multiple times on the command line; this makes a difference when input is from a terminal or other special file type. It is an error if an input file ends in the middle of argument collection, a comment, or a quoted string.
If none of the input files invoked m4exit
(see M4exit), the
exit status of m4
will be 0 for success, 1 for general failure
(such as problems with reading an input file), and 63 for version
mismatch (see Using frozen files).
If you need to read a file whose name starts with a -, you can specify it as `./-file', or use -- to mark the end of options.