The m4 Preprocessor
Creating a configuration file with m4(1) is simplicity itself. The m4(1) program is a macro preprocessor that produces a sendmail configuration file by processing a file of m4 commands. Files of m4 commands traditionally have names that end in the characters .m4 (the same as files used for building the sendmail binary). For building a configuration file, the convention is to name a file of m4 commands with an ending of .mc (for macro configuration). The m4 process reads that file and gathers definitions of macros, then replaces those macros with their values and outputs a sendmail configuration file.
With m4, macros are defined (given values) like this:
define(macro, value)Here, the macro is a symbolic name that
you will use later. Legal names must begin with an underscore or
letter and can contain letters, digits, and underscores. The
value can be any arbitrary text. A comma
separates the two, and that comma can be followed by optional
whitespace.
There must be no space between the define and the
left parenthesis. The definition ends with the right parenthesis.
To illustrate, consider this one-line m4 source file named /tmp/x:
input text to be converted ↓ define(A,B)A ↑ the m4 definition
When m4 is run to process this file, the output
produced shows that A (the
input) is redefined to become
B:
% m4 /tmp/x
Bm4 Is Greedy
The m4 program is greedy. That is, if a macro is already defined, its value will replace its name in the second declaration. Consider this input ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access