6.9 Variables from the Environment
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
and therefore are not affected by the value in the environment.)
make is invoked recursively, variables defined in the
outer invocation can be passed to inner invocations through the
environment (see section Recursive Use of
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.
Other use of variables from the environment is not recommended. It is not
wise for makefiles to depend for their functioning on environment variables
set up outside their control, since this would cause different users to get
different results from the same makefile. This is against the whole
purpose of most makefiles.
Such problems would be especially likely with the variable
which is normally present in the environment to specify the user's choice
of interactive shell. It would be very undesirable for this choice to
make ignores the environment value of
SHELL (except on MS-DOS and MS-Windows, where
usually not set. See section Special handling of SHELL on MS-DOS.)