bugmake - Bugs: bug #21661, Make expands command-line variable...

 
 

bug #21661: Make expands command-line variable defnitions after/during every command invocation

Submitter:  Robert Bogomip <bobbogo>
Submitted:  Wed 28 Nov 2007 04:43:37 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  3.81 Operating System:  Any
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 29 Nov 2007 09:09:40 AM UTC, comment #6: 

Aha, that explains everything. You are right of course, it's not a regression (as I found out after digging out 3.79.1 and 3.80), so appologgies for any aspersions cast.

Using something like "~" for the variable name on the cammand line is a decent work around for this effect. Thankyou.

Robert Bogomip <bobbogo>
Wed 28 Nov 2007 07:25:20 PM UTC, comment #5: 

Ah, now it's clear what the confusion is.  This happens because make puts command line variable settings into the environment to be exported to the subshell.  And, of course, before make can invoke a subshell it has to expand all the variables that are to be exported.

See http://www.gnu.org/software/make/manual/html_node/Variables_002fRecursion.html#Variables_002fRecursion

You can avoid this by adding an explicit "unexport var" to your makefile.

Paul D. Smith <psmith>
Group administrator
Wed 28 Nov 2007 07:18:05 PM UTC, comment #4: 


> If you put "var=value" in your makefile, then the left hand side of the variable will be re-expanded every time the variable "var" is referenced.


Fine, but I have not _referenced_ var anywhere. Why then is it being expanded?

Robert Bogomip <bobbogo>
Wed 28 Nov 2007 07:14:43 PM UTC, comment #3: 

Dave is correct: this is exactly how make should behave; it's not a regression (because all versions of make have always behaved this way); it's not even a bug.  Setting a variable on the command line using "var=value" is conceptually exactly the same as having that same assignment appear at the end of the last makefile make reads in (because the value on the command line takes precedence over values set in the makefile).

If you put "var=value" in your makefile, then the left hand side of the variable will be re-expanded every time the variable "var" is referenced.

As Dave suggests, you should review the difference between simple variables and recursive variables, and/or the difference between immediate and deferred expansion.  You can read about these topics in the "How make Reads a Makefile" section of the manual, here: http://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html#Reading-Makefiles

Paul D. Smith <psmith>
Group administrator
Wed 28 Nov 2007 07:07:08 PM UTC, comment #2: 

I set $var on the command-line. Note that it is not mentioned anywhere inside the Makefile, and yet it (or its expression) seems to be being expanded whenever the Makefile runs a command --- any and all commands.

Expected behaviour? (Regression methinks.)

Robert Bogomip <bobbogo>
Wed 28 Nov 2007 04:53:20 PM UTC, comment #1: 

As far as I can see, this is the expected and as-intended behaviour.  Try

make 'var:=$(warning hello)'

instead, and refresh your memory on the difference between immediate and deferred expansion.

Dave Korn <davek>
Wed 28 Nov 2007 04:43:37 PM UTC, original submission:  

(Eh, what? I don't really know how to rationalise this.) It seems that something like "var=def" specified on the command line will be evaluated after each rule is run. Consider:


$ cat Makefile
tgts := 1 2 3 4 5
.PHONY: all ${tgts}
all: ${tgts}
all ${tgts}:
        echo 'Commands for [$@]'


This runs fine:


$ make
echo 'Commands for [1]'
Commands for [1]
echo 'Commands for [2]'
Commands for [2]
echo 'Commands for [3]'
Commands for [3]
echo 'Commands for [4]'
Commands for [4]
echo 'Commands for [5]'
Commands for [5]
echo 'Commands for [all]'


However, try adding a command-line definition


$ make 'var=$(warning hello)'
echo 'Commands for [1]'
make: hello
Commands for [1]
echo 'Commands for [2]'
make: hello
Commands for [2]
echo 'Commands for [3]'
make: hello
Commands for [3]
echo 'Commands for [4]'
make: hello
Commands for [4]
echo 'Commands for [5]'
make: hello
Commands for [5]
echo 'Commands for [all]'
make: hello
Commands for [all]


Make seems to be expanding the expression "var=$(warning hello)". This is very annoying --- it precludes doing something like 'fixme=$(error urk)' on the command-line.

Present in make-3.81-10.fc8.x86_64 on Fedora 8, the system make on MacOS 10.5.1, and the current cygwin make (all 3.81).

Robert Bogomip <bobbogo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by davek (Posted a comment)
  • -email is unavailable- added by bobbogo (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-11-28 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code