bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exported vs command line variables


From: David Boyce
Subject: Re: exported vs command line variables
Date: Fri, 23 Sep 2016 16:09:45 -0700

In that case there does seem to be at least one bug here. In reference to the sentence:

"Macros defined by the MAKEFLAGS environment variable and macros defined in the makefile(s) shall not be added to the environment of make if they are not already in its environment."

And building on Eddy Welbourne's example:

% cat Makefile
WURGLE = 11
MAKEFLAGS = WURGLE=$(WURGLE)

all:; env | grep ^WUR ||:

% make
env | grep ^WUR ||:
WURGLE=11

It appears that macros added to MAKEFLAGS do end up in the environment.

BTW another workaround for this behavior, in addition to inserting non-alphanumeric characters into variable names, is to use "unexport FOO" in the receiving makefile. I'd been experimenting with the MAKEFLAGS technique too which is how I discovered the non-POSIX behavior above.

David

On Fri, Sep 23, 2016 at 2:52 PM, Philip Guenther <address@hidden> wrote:
On Fri, Sep 23, 2016 at 11:23 AM, Paul Smith <address@hidden> wrote:
> On Fri, 2016-09-23 at 05:52 -0700, David Boyce wrote:
>> I still think that's a good plan, except that now I find out it ends
>> up exporting anyway. I'm sure it's too late to change now but is
>> there a reason for this (unfortunate IMHO) behavior?
>
> I can't tell you: this behavior has existed since the very first import
> of GNU make code into source code control, back in 1991.

...and in System III in 1980:
http://minnie.tuhs.org/cgi-bin/utree.pl?file=SysIII/usr/src/cmd/make

Looks like BSD picked it up in 4.4 around 1993 with the switch to pmake:
http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/src/usr.bin/make


POSIX specifies this behavior in the "Macros" subsection of the
EXTENDED DESCRIPTION section for 'make'.  About a page and half in is
this paragraph:
    Before the makefile(s) are read, all of the make utility command
line macro definitions (except the
    MAKEFLAGS macro or the SHELL macro) shall be added to the
environment of make. Other
+   implementation-defined variables may also be added to the
environment of make. Macros
+  defined by the MAKEFLAGS environment variable and macros defined in
the makefile(s) shall
+   not be added to the environment of make if they are not already in
its environment. With the
+   exception of SHELL (see below), it is unspecified whether macros
defined in these ways update
    the value of an environment variable that already exists in the
environment of make.

(That's from the 2013 draft update; the '+' lines were modified from
the original 2008 version of the standard, but that doesn't affect the
first sentence.)


Philip Guenther


reply via email to

[Prev in Thread] Current Thread [Next in Thread]