make: Environment

1 
1 6.10 Variables from the Environment
1 ===================================
1 
1 Variables in 'make' can come from the environment in which 'make' is
1 run.  Every environment variable that 'make' sees when it starts up is
1 transformed into a 'make' variable with the same name and value.
1 However, an explicit assignment in the makefile, or with a command
1 argument, overrides the environment.  (If the '-e' flag is specified,
1 then values from the environment override assignments in the makefile.
1 ⇒Summary of Options Options Summary.  But this is not recommended
1 practice.)
1 
1    Thus, by setting the variable 'CFLAGS' in your environment, you can
1 cause all C compilations in most makefiles to use the compiler switches
1 you prefer.  This is safe for variables with standard or conventional
1 meanings because you know that no makefile will use them for other
1 things.  (Note this is not totally reliable; some makefiles set 'CFLAGS'
1 explicitly and therefore are not affected by the value in the
1 environment.)
1 
1    When 'make' runs a recipe, variables defined in the makefile are
1 placed into the environment of each shell.  This allows you to pass
11 values to sub-'make' invocations (⇒Recursive Use of 'make'
 Recursion.).  By default, only variables that came from the environment
1 or the command line are passed to recursive invocations.  You can use
11 the 'export' directive to pass other variables.  ⇒Communicating
 Variables to a Sub-'make' Variables/Recursion, for full details.
1 
1    Other use of variables from the environment is not recommended.  It
1 is not wise for makefiles to depend for their functioning on environment
1 variables set up outside their control, since this would cause different
1 users to get different results from the same makefile.  This is against
1 the whole purpose of most makefiles.
1 
1    Such problems would be especially likely with the variable 'SHELL',
1 which is normally present in the environment to specify the user's
1 choice of interactive shell.  It would be very undesirable for this
1 choice to affect 'make'; so, 'make' handles the 'SHELL' environment
1 variable in a special way; see ⇒Choosing the Shell.
1