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

 
 

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

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

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>
Group 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 Files:
   
   
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
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by kristovschulz (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-03-08 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2007-03-08 kristovschulz Attached File- Added Makefile, #12147

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code