diff options
author | Yaroslav Tykhiy <ytykhiy@gmail.com> | 2008-03-05 20:11:04 +0000 |
---|---|---|
committer | Yaroslav Tykhiy <ytykhiy@gmail.com> | 2008-03-05 20:11:04 +0000 |
commit | 0c352199787a2042eacfe1e10d0fdd37c3fb5dcb (patch) | |
tree | 4609d400c4fc65fc29466c452a6a7f3c3a4b18c8 /usr.bin | |
parent | 4fa8db5df0570eeed83991123bc383eca69854fb (diff) | |
download | src-0c352199787a2042eacfe1e10d0fdd37c3fb5dcb.tar.gz src-0c352199787a2042eacfe1e10d0fdd37c3fb5dcb.zip |
Don't forget to set MAKEFLAGS in the childs' environment
from the .MAKEFLAGS global variable even if it's empty or
unset. This means setting MAKEFLAGS to just an empty string
in the latter case.
If not doing so, make(1) behaved inconsistently WRT MAKEFLAGS.
In particular, it would let a `-f foo' option down to sub-makes
if .MAKEFLAGS was unset. E.g.,
env MAKEFLAGS="-f mymakefile" make
would pass `-f mymakefile' down to sub-makes via their environment
(unless mymakefile added something to .MAKEFLAGS).
But any additional options appearing would change this behaviour to
not passing `-f mymakefile' to sub-makes, as in:
env MAKEFLAGS="-f mymakefile" make -D DUMMY
or
env MAKEFLAGS="-f mymakefile -D DUMMY" make
(unless mymakefile cleared .MAKEFLAGS).
Also make(1) would leave MAKEFLAGS at its initial value if the
makefile set .MAKEFLAGS to an empty value. I.e., it was impossible
to override MAKEFLAGS with an empty value. (Note well that makefiles
are not to touch MAKEFLAGS directly, they alter .MAKEFLAGS instead.
So make(1) can filter out things such as -f when copying MAKEFLAGS
to .MAKEFLAGS at startup. Direct modifications to MAKEFLAGS just go
nowhere.)
While the original intentions of the BSD make authors are somewhat
unclear here, the bug proves that NOT passing -f options down is
the settled behaviour because the opposite behaviour is totally
unreliable in the presence of any other options. In addition, not
passing down -f's found in the environment is consistent with doing
so WRT the command line.
Update the manpage accordingly and make the whole description of
MAKEFLAGS and .MAKEFLAGS more consistent as this change indeed
brings more consistency into the reliable behaviour of make(1).
Submitted by: ru (main.c)
Tested with: make world
Notes
Notes:
svn path=/head/; revision=176839
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/main.c | 2 | ||||
-rw-r--r-- | usr.bin/make/make.1 | 64 |
2 files changed, 35 insertions, 31 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 9fde44128d1f..a296b2bd2a05 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1188,6 +1188,8 @@ main(int argc, char **argv) /* Install all the flags into the MAKE envariable. */ if (((p = Var_Value(".MAKEFLAGS", VAR_GLOBAL)) != NULL) && *p) setenv("MAKEFLAGS", p, 1); + else + setenv("MAKEFLAGS", "", 1); /* * For compatibility, look at the directories in the VPATH variable diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index 1d522914c35c..f17ab88b0b27 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -32,7 +32,7 @@ .\" @(#)make.1 8.8 (Berkeley) 6/13/95 .\" $FreeBSD$ .\" -.Dd March 4, 2008 +.Dd March 5, 2008 .Dt MAKE 1 .Os .Sh NAME @@ -648,7 +648,7 @@ last word in this variable. .It Ev MAKEFLAGS The environment variable .Ev MAKEFLAGS -may contain anything that +may initially contain anything that may be specified on .Nm Ns 's command line, @@ -668,6 +668,29 @@ are appended to the .Va .MAKEFLAGS variable. .Pp +Whenever +.Nm +executes a program, it sets +.Ev MAKEFLAGS +in the program's environment to the current value of the +.Va .MAKEFLAGS +global variable. +Thus, if +.Ev MAKEFLAGS +in +.Nm Ns 's +environment contains any +.Fl f +options, they will not be pushed down to child programs automatically. +The +.Nm +utility effectively filters out +.Fl f +options from the environment and command line although it +passes the rest of its options down to sub-makes via +.Ev MAKEFLAGS +by default. +.Pp When passing macro definitions and flag arguments in the .Ev MAKEFLAGS environment variable, @@ -694,9 +717,15 @@ global variable, the makefile can alter the contents of the environment variable made available for all programs which .Nm executes. -(This includes adding +This includes adding .Fl f -option(s).) +option(s). +The current value of +.Va .MAKEFLAGS +is just copied verbatim to +.Ev MAKEFLAGS +in the environment of child programs. +.Pp Note that any options entered to .Va .MAKEFLAGS neither affect the current instance of @@ -718,33 +747,6 @@ children. Compare with the .Ic .MAKEFLAGS special target below. -.Pp -To sum up what was said on -.Fl f : -It can appear in -.Ev MAKEFLAGS -and affect the current -.Nm -only if inherited from -.Nm Ns 's -initial environment. -At the same time, a -.Fl f -option from -.Nm Ns 's -command line -does affect -.Nm , -but it is never transferred to -.Va .MAKEFLAGS -or pushed down to child programs such as sub-makes. -Finally, -.Fl f -can appear in -.Va .MAKEFLAGS -only if added by the makefile itself; -it will affect sub-makes only, via -.Ev MAKEFLAGS . .It Va MFLAGS This variable is provided for backward compatibility and contains all the options from the |