bugmake - Bugs: bug #1733, included variables undefined when...


bug #1733: included variables undefined when one included makefile depends on another

Submitter:  Invalid User ID <#12730>
Submitted:  Sat 16 Nov 2002 04:00:35 PM UTC
Severity:  1 - Wish Item Group:  Enhancement
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  3.79.1 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup

Fri 09 Jan 2004 08:34:51 PM UTC, comment #3: 

I had a similar problem, and was able to work around it by putting the include for the dependent files inside an ifdef, like this for your example:

-include include1
ifdef A
-include include2

Haven't had time to check the code, but this apparently tricks make into thinking it has processed all the included makefiles after the first one, so it restarts itself, gets the value of A from include1, realizes it needs to process the code inside the ifdef, and subsequently includes include2. With this structure, there don't appear to be any cases in which A or B end up undefined.

Paul Cannon <paulcannon>
Mon 18 Nov 2002 03:58:42 PM UTC, comment #2: 

I'm marking this as an enhancement request.  I'm not sure about making this change; first it could be much more inefficient by causing lots of extra fork/exec operations, and this would be an incompatible change.

Also, with the eval function introduced in 3.80 you can put something like $(eval include include1) into the rule to emulate this (although note that you may need bug 1517 fixed (see the patch on that bug report) before you can do this.

But I'm leaving this open for now, while I think about it :).

Paul D. Smith <psmith>
Group administrator
Sun 17 Nov 2002 05:52:17 PM UTC, comment #1: 

Paul Smith explained to me on the help-make mailing list that this results from the way Make works: read all includes, rebuild all includes, restart make. So in effect the "previous version" of include1 is used when building include2, because Make is not restarted until ALL includes have been rebuilt.

That makes this bug a requested feature enhancement rather than an outright bug.

Here is my requested feature: Make should restart itself before invoking any rule that has a makefile as a preqrequisite and that makefile has already been rebuilt.

Any other means of making sure the "current version" of the rebuilt makefile gets used would also be acceptable.

Invalid User ID <#12730>
Sat 16 Nov 2002 04:00:35 PM UTC, original submission:  

The attached make script when run should print out "B=hello" but it only prints "B=" because the value $(B) is undefined.

There appears to be a bug when including multiple make files where one depends on another. Variables set in the prerequisite makefile are undefined when executing the commands that generate a dependent makefile.

With the attached makefile the following commands will cause make to change behavior and print the right value:

     make include1
     rm include2
     make include2

in this case because 'include1' is already generated before make first runs the value of $(B) winds up being defined in the commands for include2.

Invalid User ID <#12730>


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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


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
2002-11-18 psmith Severity3 - Normal None
    Item GroupBug None

Back to the top

Powered by Savane 3.13-758e.
Corresponding source code