Date: Thu, 1 Jul 2004 09:10:23 GMT From: Ruslan Ermilov <ru@FreeBSD.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/68534: make(1) - ${.MAKEFLAGS} does not contain cmd line args Message-ID: <200407010910.i619ANXx093843@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/68534; it has been noted by GNATS. From: Ruslan Ermilov <ru@FreeBSD.org> To: John E Hein <jhein@timing.com> Cc: bug-followup@FreeBSD.org Subject: Re: bin/68534: make(1) - ${.MAKEFLAGS} does not contain cmd line args Date: Thu, 1 Jul 2004 12:05:57 +0300 On Thu, Jul 01, 2004 at 01:30:10AM +0000, John E Hein wrote: > > This is interesting env var precedence weirdness... > > $ cat Makefile > FOO?=0 > X?=0 > .PHONY: x > x: > @echo MAKEFLAGS: ${MAKEFLAGS} > @echo .MAKEFLAGS: ${.MAKEFLAGS} > @echo FOO: ${FOO} > .if $X != 1 > make X=1 > .endif > > $ env FOO=1 MAKEFLAGS=FOO=3 make FOO=2 > MAKEFLAGS: FOO=3 > .MAKEFLAGS: > FOO: 2 > As documented, MAKEFLAGS value (FOO=3) is parsed just like if it were a part of the command line, so this is equivalent to ``env FOO=1 make FOO=3 FOO=2'', so `2' is printed. > make X=1 > MAKEFLAGS: FOO=3 > .MAKEFLAGS: > FOO: 3 > Now, we just call ``make'' with FOO=2 and MAKEFLAGS=FOO=3 in environment. New make parses MAKEFLAGS, so this becomes equivalent to ``env FOO=2 make FOO=3'', so `3' is printed. > $ env FOO=1 make FOO=2 > MAKEFLAGS: > .MAKEFLAGS: > FOO: 2 > Here, `2' is printed, and FOO is entered into environment with value 2. > make X=1 > MAKEFLAGS: > .MAKEFLAGS: > FOO: 2 > Here, ${FOO} is fetched from the environment with value 2. > In the first case FOO=3 is inserted in the environment by make via > MAKEFLAGS. > Not quite. What's in environment is FOO=2 and MAKEFLAGS=FOO=3 (see above). > In the second case FOO=1 is inserted in the environment in a more > generic way. > And then FOO=2 causes FOO in environment to be reset to `2'. > Why does FOO=2 (the cmd line variable) override FOO in the environment > in the first case, but not the second? I'm going to have a look in > the source. > I don't quite understand what you're asking, but I hope my explanations answer this. ;) > And finally... > > $ env FOO=1 make -E FOO FOO=2 > MAKEFLAGS: -E FOO > .MAKEFLAGS: -E FOO > FOO: 2 > Here, you say to prefer environment variable FOO over global FOO (there's no global FOO, FOO?=0). Then, FOO=2 is parsed and FOO in environment is re-assigned the value of 2, and it's what gets printed. > make X=1 > MAKEFLAGS: -E FOO > .MAKEFLAGS: -E FOO > FOO: 2 > Here, we just print FOO from environment, which is `2'. > Whoa, wait a second. There's some stuff from the command line > in MAKEFLAGS now. > Like I said in another email, only variable=value is not saved in MAKEFLAGS. Cheers, -- Ruslan Ermilov ru@FreeBSD.org FreeBSD committer
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200407010910.i619ANXx093843>