m41
Macro language processor
Usage
m4 [-EgPs]
[-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 don't 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 the symbol name to have some value (or NULL).
-
-d flags -
Set trace flags. flags may hold the following:
- 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.
By default, trace is set to "eq".
-
-E -
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 behaviour matches GNU-m4 1.4.9 and later. -
-g -
Activate GNU-m4 compatibility mode. In this mode, translit handles simple character ranges (e.g., a-z), regular expressions mimic emacs behavior, multiple m4wrap calls are handled as a stack, the number of diversions is unlimited, empty names for macro definitions are allowed, and eval understands ‘0rbase:value’ numbers.
-
-I dirname -
Add directory dirname to the include path.
-
-o filename -
Send trace output to filename.
-
-P -
Prefix all built-in macros with ‘m4_’. For example, instead of writing
define, usem4_define. -
-s -
Output line synchronization directives, suitable for cpp(1).
-
-t macro -
Turn tracing on for macro.
-
-Uname -
Undefine the symbol name.
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
61 releases since OpenBSD 2.1; the text changed 28 times.
- 2.1–2.3
- 2.4–2.5
- 2.6
- 2.7
- 2.8
- 2.9
- 3.0–3.1
- 3.2
- 3.3
- 3.4
- 3.5
- 3.6
- 3.7–3.8
- 3.9
- 4.0
- 4.1
- 4.2–4.4
- 4.5–4.6
- 4.7
- 4.8
- 4.9–5.3
- 5.4
- 5.5
- 5.6–5.8
- 5.9–6.1
- 6.2–6.8
- 6.9–7.0
- 7.1
- 7.2–8.0
-E since OpenBSD 6.2;
-I since OpenBSD 2.6;
-P since OpenBSD 4.7;
-d since OpenBSD 3.0;
-g since OpenBSD 2.7;
-o since OpenBSD 3.3;
-s since OpenBSD 3.2;
-t since OpenBSD 3.0.