m41
Macro language processor
Usage
m4 [-EGgPs]
[-Dname
[=value]]
[-d
[[+-]
flags]]
[-I
dirname]
[-o
filename]
[-t
macro]
[-Uname]
[file ...]
Overview
The m4 utility is a macro processor that can be used as a front end to any language (e.g., C, ratfor, fortran, lex, and yacc). If no input files are given, m4 reads from the standard input, otherwise files specified on the command line are processed in the given order. Input files can be regular files, files in the m4 include paths, or a single dash (‘-’), denoting standard input. m4 writes the processed text to the standard output, unless told otherwise.
Macro calls have the form name(argument1[, argument2, ..., argumentN]).
There cannot be any space following the macro name and the open parenthesis (‘(’). If the macro name is not followed by an open parenthesis it is processed with no arguments.
Macro names consist of a leading alphabetic or underscore possibly followed by alphanumeric or underscore characters, e.g., valid macro names match the pattern “[a-zA-Z_][a-zA-Z0-9_]*”.
In arguments to macros, leading unquoted space, tab, and newline (‘\n’) characters are ignored. To quote strings, use left and right single quotes (e.g., ‘ this is a string with a leading space’). You can change the quote characters with the changequote built-in macro.
Most built-ins do not make any sense without arguments, and hence are not recognized as special when not followed by an open parenthesis.
The options are as follows:
-
-Dname[=value], --define=name[=value] -
Define the symbol name to have some value (or NULL).
-Dalone on OpenBSD. -
-d [[+|-]flags], --debug=[[+|-]flags] -
Set or unset trace flags. The trace flags are as follows:
- a
-
print macro arguments.
- c
-
print macro expansion over several lines.
- e
-
print result of macro expansion.
- f
-
print filename location.
- l
-
print line number.
- q
-
quote arguments and expansion with the current quotes.
- t
-
start with all macros traced.
- x
-
number macro expansions.
- V
-
turn on all options.
If "+" or "-" is used, the specified flags are added to or removed from the set of active trace flags, respectively; otherwise, the specified flags replace the set of active trace flags.
Specifying this option without an argument is equivalent to specifying it with the argument "aeq".
By default, trace is set to "eq".
-dalone on OpenBSD. -
-E, --fatal-warnings -
Set warnings to be fatal. When a single
-Eflag is specified, if warnings are issued, execution continues butm4will exit with a non-zero exit status. When multiple-Eflags are specified, execution will halt upon issuing the first warning andm4will exit with a non-zero exit status. This behavior matches GNU m4 1.4.9 and later.-Ealone on OpenBSD. -
-G, --traditional -
Disable GNU compatibility mode (see
Not on OpenBSD.-gbelow). -
-g, --gnu -
Enable GNU compatibility mode. In this mode,
translithandles simple character ranges (e.g., ‘a-z’), regular expressions mimic Emacs behavior, multiplem4wrapcalls are handled as a stack, the number of diversions is unlimited, empty names for macro definitions are allowed,undivertcan be used to include files, andevalunderstands ‘0rbase:value’ numbers.-galone on OpenBSD. -
-I dirname, --include=dirname -
Add directory dirname to the include path.
-Ialone on OpenBSD. -
-o filename, --error-output=filename -
Send trace output to filename.
Not on Linux.-oalone on OpenBSD. -
-P, --prefix-builtins -
Prefix all built-in macros with ‘m4_’. For example, instead of writing
define, usem4_define.-Palone on OpenBSD. -
-s, --synclines -
Output line synchronization directives, suitable for cpp(1).
-salone on OpenBSD. -
-t macro, --trace=macro -
Turn tracing on for macro.
-talone on OpenBSD. -
-Uname, --undefine=name -
Undefine the symbol name.
-Ualone on OpenBSD.
Exit status
The m4 utility exits 0 on success, and >0 if an error occurs.
But note that the m4exit macro can modify the exit status, as can the -E flag.
Releases
87 releases since FreeBSD 2.0.5-RELEASE; the text changed 54 times.
- 2.0.5
- 2.1.5–2.1.7.1
- 2.2.2–2.2.6
- 2.2.7–2.2.8
- 2.2.9
- 3.0
- 3.1–3.2
- 3.3–3.4
- 3.5–3.5.1
- 4.0–4.2
- 4.3
- 4.4–4.5
- 4.6–4.6.2
- 4.7
- 4.8
- 4.9–4.11
- 5.0
- 5.1
- 5.2–5.2.1
- 5.3–5.5
- 6.0–6.3
- 6.4
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
- 9.0
- 9.1
- 9.2
- 9.3
- 10.0
- 10.1
- 10.2
- 10.3
- 10.4
- 11.0
- 11.1
- 11.2
- 11.3
- 11.4
- 12.0
- 12.1
- 12.2
- 12.3
- 12.4
- 13.0
- 13.1–13.2
- 13.3–14.5
- 15.0–16.0
--debug since FreeBSD 13.3-RELEASE;
--define since FreeBSD 13.3-RELEASE;
--error-output since FreeBSD 13.3-RELEASE;
--fatal-warnings since FreeBSD 13.3-RELEASE;
--gnu since FreeBSD 13.3-RELEASE;
--include since FreeBSD 13.3-RELEASE;
--prefix-builtins since FreeBSD 13.3-RELEASE;
--synclines since FreeBSD 13.3-RELEASE;
--trace since FreeBSD 13.3-RELEASE;
--traditional since FreeBSD 13.3-RELEASE;
--undefine since FreeBSD 13.3-RELEASE;
-E since FreeBSD 12.1-RELEASE;
-G since FreeBSD 13.3-RELEASE;
-I since FreeBSD 4.7-RELEASE;
-P since FreeBSD 9.3-RELEASE;
-d since FreeBSD 4.7-RELEASE;
-g since FreeBSD 4.7-RELEASE;
-o since FreeBSD 9.3-RELEASE;
-s since FreeBSD 4.6-RELEASE;
-t since FreeBSD 4.7-RELEASE.