bugmake - Bugs: bug #8744, Variables in commands evaluated at...

 
 

bug #8744: Variables in commands evaluated at bad time

Submitted by:  None
Submitted on:  Thu 29 Apr 2004 07:13:28 PM UTC  
 
Severity: 3 - NormalItem Group: Bug
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: 3.80Operating 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.

 

Fri 30 Apr 2004 05:26:01 AM UTC, comment #1:

A very common mistake when starting with make is to treat it like a procedural language, like C or Pascal or even Java. Make is not a procedural language: it's more like a declarative language.

Anyway, the rules governing where and when variables are expanded have been the behavior of every make since make was invented ~30 years ago. Further, this behavior is specified by the POSIX standard for make, and further clearly specified in the GNU make manual. Changing it is right out of the question: virtually every makefile in existence would break in subtle ways.

As for adding new syntax, I'm not sure about that. The syntax is definitely difficult to come up with since it has to be backward-compatible. Also right now make treats the entire command script as basically a constant string during makefile parsing and doesn't try to expand the variables in the string until/unless that script is actually invoked; changing this would have to be done carefully.

One possible idea: to force a particular value for the rule you can use target-specific variables; these override any settings of the variable in the "global" namespace:

all: stuff := appropriate stuff
all:
@echo $(stuff)

stuff := inappropriate stuff

Paul D. Smith <psmith>
Project Administrator
Thu 29 Apr 2004 07:13:28 PM UTC, original submission:

Apparently variables in commands aren't evaluated until after all Makefiles have been completely input. For example, the Makefile:

stuff:=appropriate stuff
all:
@echo $(stuff)

stuff:=inappropriate stuff

prints "inappropriate stuff", when the intention of the Makefile writer was clearly that it print "appropriate stuff". I propose two possible fixes:

1. For any variable mentioned in a command, its value should be recorded at the time of the rule.

2. Add some new syntax that specifies when the variables in a command should be evaluated.

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #1270:  Makefile added by None (74B - application/octet-stream - Makefile that demonstrates the problem)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

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 3 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Fri 30 Apr 2004 05:26:01 AM UTCpsmithStatusNone=>Not A Bug
  Open/ClosedOpen=>Closed
Thu 29 Apr 2004 07:13:28 PM UTCNoneAttached File-=>Added Makefile, #1255

Back to the top


Powered by Savane 3.1-cleanup1