70 GNU make
not. However, if you are using the flavor (see Section 8.11 [Flavor Function], page 95) and
origin (see Section 8.10 [Origin Function], page 94) functions, there is a difference between
a variable that was never set and a variable with an empty value. In such situations you
may want to use the undefine directive to make a variable appear as if it was never set.
For example:
foo := foo
bar = bar
undefine foo
undefine bar
$(info $(origin foo))
$(info $(flavor bar))
This example will print “undefined” for both variables.
If you want to undefine a command-line variable definition, you can use the override
directive together with undefine, similar to how this is done for variable definitions:
override undefine CFLAGS
6.10 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. However, 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 9.7 [Summary of Options],
page 104. But this is not recommended practice.)
Thus, by setting the variable CFLAGS in your environment, you can cause all C compi-
lations 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. (Note this is not totally reliable; some makefiles set CFLAGS explicitly and
therefore are not affected by the value in the environment.)
When make runs a recipe, variables defined in the makefile are placed into the environ-
ment of each shell. This allows you to pass values to sub-make invocations (see Section 5.7
[Recursive Use of make], page 50). By default, only variables that came from the environ-
ment or the command line are passed to recursive invocations. You can use the export
directive to pass other variables. See Section 5.7.2 [Communicating Variables to a Sub-
make], page 52, 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 SHELL, 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 affect make; so, make handles the SHELL environment variable
in a special way; see Section 5.3.2 [Choosing the Shell], page 45.
Comentarios a estos manuales