Environment variables
Environment variables are read and added to the
macro definitions each time make executes.
Precedence
is a prime consideration in doing this properly.
The following describes make's interaction with
the environment.
A macro,
MAKEFLAGS,
is maintained by make.
The macro is defined as the collection of
all input flag arguments into a string (without minus signs).
The macro is exported and
thus accessible to recursive invocations of make.
Command line flags and assignments in the makefile
update
MAKEFLAGS.
Thus, to describe how the environment
interacts with make,
the
MAKEFLAGS
macro (environment variable) must be considered.
When executed, make assigns macro definitions in the following
order:
-
Read the
MAKEFLAGS
environment variable.
If it is not present or null, the internal make
variable
MAKEFLAGS
is set to the null string.
Otherwise, each letter in
MAKEFLAGS
is assumed to
be an input flag argument and is processed as such.
(The only exceptions are the -f, -p, and -r
flags.)
-
Read the internal list of macro definitions.
-
Read the environment.
The environment variables are treated as macro
definitions and marked as exported (in
the shell sense).
-
Read the makefile(s).
The assignments in the makefile(s)
override the environment.
This order is chosen
so that when a makefile is read and executed,
you know what to expect.
That is, you
get what is seen unless the -e flag is used.
The -e is the input flag argument, which
tells make to have the environment override
the makefile assignments.
Thus, if make -e
is entered, the variables in the environment override
the definitions in the makefile.
Also
MAKEFLAGS
overrides the environment if assigned.
This is useful for further invocations of make
from the current makefile.
It may
be clearer to list the precedence of assignments.
Thus, in order from least binding to most binding,
the precedence of assignments is as follows:
-
internal definitions
-
environment
-
makefile(s)
-
command line
The -e flag has the effect of rearranging the order to:
-
internal definitions
-
makefile(s)
-
environment
-
command line
This order is general enough to allow
a programmer to define a makefile or set of makefiles
whose parameters are dynamically definable.
Next topic:
Suggestions and warnings
Previous topic:
The make command
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004