Monday, July 09, 2007

GNU-Make: Variables from the Environment

Variables from the Environment
Variables in make can come from the environment in which make is run.
Every environment variable that make sees when it starts up is
transformed into a make variable with the same name and value. But an
explicit assignment in the makefile, or with a command argument,
overrides the environment. (If the `-e' flag is specified, then values
from the environment override assignments in the makefile. See section
Summary of Options. But this is not recommended practice.)

Thus, by setting the variable CFLAGS in your environment, you can cause
all C compilations in most makefiles to use the compiler switches you
prefer. This is safe for variables with standard or conventional
meanings because you know that no makefile will use them for other
things. (But this is not totally reliable; some makefiles set CFLAGS
explicitly and therefore are not affected by the value in the

When make is invoked recursively, variables defined in the outer
invocation can be passed to inner invocations through the environment
(see section Recursive Use of make). By default, only variables that
came from the environment or the command line are passed to recursive
invocations. You can use the export directive to pass other variables.
See section Communicating Variables to a Sub-make, for full details.

No comments:

Blog Archive