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

 
 

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

Submitted by:  Robert Bogomip <bobbogo>
Submitted on:  Wed 28 Nov 2007 04:43:37 PM UTC  
 
Severity: 3 - NormalItem Group: Bug
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: 3.81Operating System: Any
Fixed Release: NoneTriage Status: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission 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>
Project 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>
Project 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:

This runs fine:

However, try adding a command-line definition

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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 28 Nov 2007 07:14:43 PM UTCpsmithStatusNone=>Not A Bug
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1