bugmake - Bugs: bug #19236, Imported variable with trailing...

 
 

bug #19236: Imported variable with trailing backslash messes up make's line parsing in nested evaluations

Submitted by:  Christoph Schulz <kristovschulz>
Submitted on:  Thu 08 Mar 2007 07:44:14 AM 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.

 

Thu 08 Mar 2007 01:38:07 PM UTC, comment #1:

I agree this is unpleasant; however I don't see anything make can do about it. Eval works by first expanding its argument(s), then evaluating the result. In your example, after the expansion of $(Y) make sees:

ifeq (1,1)
B := X\
endif

and there's no possible way that the eval can know that this backslash was originally contained in the variable A, rather than being written directly by you.

The only solution to this is for YOU to be more cautious about when you allow variables to expand. If you defer the expansion of A so that it's done by the eval itself instead of being done up front before eval is invoked, then you'll get the behavior you want; change the definition of Y as follows:

define Y
ifeq (1,1)
B := $$(A)
endif
endef

By using $$(A), it won't expand during the expansion of Y, and eval will see this:

ifeq (1,1)
B := $(A)
endif

with no backslash... THEN when eval evaluates this IT will expand A and set B to the right value (X\). For your "real life" example this would translate to:

define $(COMP)_CUSTOM_WX_TARGET
ifneq ($(filter bcb%,$(TOOLSET)),)
$(1): export PATH := $(BCCDIR)bin;$$(PATH)
endif
endef

Although, as a general rule, I find it best to defer expansion of ALL variables other than those that require it (typically as part of a call), so the above might be more safely written:

define $(COMP)_CUSTOM_WX_TARGET
ifneq ($$(filter bcb%,$$(TOOLSET)),)
$(1): export PATH := $$(BCCDIR)bin;$$(PATH)
endif
endef

I'm closing this for now but if anyone has any ideas on how to make this work better please add a note or bring it up on the mailing lists.

Paul D. Smith <psmith>
Project Administrator
Thu 08 Mar 2007 07:44:14 AM UTC, original submission:

Consider following Makefile:

backslash := $(strip \)
A := X$(backslash)
define Y
ifeq (1,1)
B := $(A)
endif
endef
$(eval $(Y))

If B contains a value with a trailing backslash then make aborts with the following error:

Makefile:8: *** missing `endif'. Stop.

Somehow the trailing backslash of the variable A is considered a line continuation character within the nested evaluation, such that make misses the terminating "endif".

Background: The original problem was a PATH with a trailing backslash imported from the environment. Within an "eval"uated "define" statement I used something like:

define $(COMP)_CUSTOM_WX_TARGET
ifneq ($(filter bcb%,$(TOOLSET)),)
$(1): export PATH := $(BCCDIR)bin;$(PATH)
endif
endef

This did not work and bailed out with the error mentioned above, as my PATH had a trailing backslash (this happened under MS Windows, but the problem with the trailing backslash can be reproduced on any platform).

Christoph Schulz <kristovschulz>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #12147:  Makefile added by kristovschulz (106B - application/octet-stream - The makefile that exhibits the bug)

 

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

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 08 Mar 2007 01:38:07 PM UTCpsmithStatusNone=>Not A Bug
      Open/ClosedOpen=>Closed
    Thu 08 Mar 2007 07:44:14 AM UTCkristovschulzAttached File-=>Added Makefile, #12147

    Back to the top


    Powered by Savane 3.1-cleanup1