Imake invokes cpp with any -I or -D flags passed on the command line and passes the name of a file containing the following 3 lines:
#define IMAKE_TEMPLATE "Imake.tmpl"
#define INCLUDE_IMAKEFILE <Imakefile>
#include IMAKE_TEMPLATE
where
Imake.tmpl and Imakefile may be overridden by the -T and -f command options, respectively.The IMAKE_TEMPLATE typically reads in a file containing machine-dependent parameters (specified as cpp symbols), a site-specific parameters file, a file defining variables, a file containing cpp macro functions for generating make rules, and finally the Imakefile (specified by INCLUDE_IMAKEFILE) in the current directory. The Imakefile uses the macro functions to indicate what targets should be built; imake takes care of generating the appropriate rules.
Imake configuration files contain two types of variables, imake variables and make variables. The imake variables are interpreted by cpp when imake is run. By convention they are mixed case. The make variables are written into the Makefile for later interpretation by make. By convention make variables are upper case.
The rules file (usually named Imake.rules in the configuration directory) contains a variety of cpp macro functions that are configured according to the current platform. Imake replaces any occurrences of the string ``@@'' with a newline to allow macros that generate more than one line of make rules. For example, the macro
#define program_target(program, objlist) @@\
program: objlist @@\
$(CC) -o $@ objlist $(LDFLAGS)
when called with program_target(foo, foo1.o foo2.o) will expand to
foo: foo1.o foo2.o
$(CC) -o $@ foo1.o foo2.o $(LDFLAGS)
Imake also replaces any occurrences of the word ``XCOMM'' with the character ``#'' to permit placing comments in the Makefile without causing ``invalid directive'' errors from the preprocessor.
Some complex imake macros require generated make variables local to each invocation of the macro, often because their value depends on parameters passed to the macro. Such variables can be created by using an imake variable of the form XVARdefn, where n is a single digit. A unique make variable will be substituted. Later occurrences of the variable XVARusen will be replaced by the variable created by the corresponding XVARdefn.
On systems whose cpp reduces multiple tabs and spaces to a single space, imake attempts to put back any necessary tabs (make is very picky about the difference between tabs and spaces). For this reason, colons (:) in command lines must be preceded by a backslash (\).