bugmake - Bugs: bug #54703, Incorrection expansion of :=...

 
 

bug #54703: Incorrection expansion of := accumulator under $(eval …)

Submitter:  Vincent Belaïche <vincentb1>
Submitted:  Fri 21 Sep 2018 10:01:35 AM UTC
   
 
Severity:  3 - Normal Item Group:  None
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  None Operating System:  None
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 15 Apr 2022 04:19:56 PM UTC, comment #5: 

@Paul,

Sorry for the long long delay before I react to your reply « I didn't see a new attachment?», I justed missed the notification !

The proposal was in attachment (file #45105 make-patch.diff).

After double checking it, I decided to make some rewording, see (file #53093 make-patch1.diff).

Vincent Belaïche <vincentb1>
Tue 25 Sep 2018 05:53:14 PM UTC, comment #4: 

I didn't see a new attachment?

Regarding the builds, you'll need to install the Guile package before you can successfully run the autoconf stuff.  You don't need to compile GNU make with guile but to rebuild the configure script we need the package macros from the Guile package available.

It's a shame that autoconf doesn't give an error when it can't find a macro but I guess it doesn't know the difference between a macro and some shell commands.

I guess the bootstrap script could be enhanced to make sure that the guile package is installed.

Paul D. Smith <psmith>
Group administrator
Tue 25 Sep 2018 05:32:39 PM UTC, comment #3: 

Dear both,

Thank you so much for your help.

I must admit that being familiar with MSDos, M4 and TeX, I should have paid more attention to this aspect.

I was quite aware of doubling the $ when it concerned producing recipes with eval, for the shell commands to get/make the right input/output.
But I must admit that despite the example given in the documentation tackles also this point, I had not paid too much attention to using eval with building up variables content.

I have tried to capture the good words from Michael in a contribution attached. Please feel free to use it or not.

BTW, FYI, I tried to compile make.texi, but I could not because version.texi was missing, so I tried the bootstrap + configure scripts, and I got this error:

./configure: line 12435: PKG_PROG_PKG_CONFIG: command not found
./configure: line 12444: syntax error near unexpected token `guile-$v,'
./configure: line 12444: `    PKG_CHECK_EXISTS(guile-$v, guile_version=$v; have_guile=yes; break, )'

I am on Mac OS 10,13,6

Vincent Belaïche <vincentb1>
Tue 25 Sep 2018 03:59:56 PM UTC, comment #2: 

Thanks Michael.

Vincent, you'll need to escape variables in your defined variables to ensure they're not expanded until the appropriate times.  You can ask on -email is unavailable- or -email is unavailable- mailing lists for more help.

Paul D. Smith <psmith>
Group administrator
Fri 21 Sep 2018 03:50:16 PM UTC, comment #1: 

Hello.

This is not a bug.

Argument of eval is always expanded prior evalation.

Let's see how this works.

---------

ITERATIONS:=1 2 3
ACCUMULATOR:=Macron go home :

WORD_1:=Macron
WORD_2:=go
WORD_3:=home

define ACCUMULATE
WORD:=$(WORD_$(1))
ACCUMULATOR:=$(ACCUMULATOR) $(WORD)
endef

$(foreach ITERATION,$(ITERATIONS),$(eval $(call ACCUMULATE,$(ITERATION))))

---------

  • The first foreach iteration is expanded as:


WORD:=Macron
ACCUMULATOR:=Macron go home : <empty>

then evaluated

  • second iteration is expanded as:


WORD:=go
ACCUMULATOR:=Macron go home : Macron

then evaluated

  • third iteration is expanded as:


WORD:=home
ACCUMULATOR:=Macron go home : Macron go

and then evaluated.

-------

You need to delay expansion of $(WORD) in the ACCUMULATE until eval:

define ACCUMULATE
WORD:=$(WORD_$(1))
ACCUMULATOR:=$(ACCUMULATOR) $$(WORD)
endef


then, while processing assignment operator :=, eval expands the value a second time

-------

For debugging, it is handy to trace eval calls, e.g.:


trace_eval = $(info $1)$(eval $1)

$(foreach ITERATION,$(ITERATIONS),$(call trace_eval,$(call ACCUMULATE,$(ITERATION))))

Michael Builov <mbuilov>
Fri 21 Sep 2018 10:01:35 AM UTC, original submission:  

The attached make file is a minimal example of the problem.

I would expect the following output when call make on this makefile:

Macron go home : Macron go home

But instead I get this output:

Macron go home :  Macron go

Your help is most welcome…

Vincent Belaïche <vincentb1>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #53093:  make-patch1.diff added by vincentb1 (4KiB - application/octet-stream - Improved contribution)
file #45105:  make-patch.diff added by vincentb1 (3KiB - application/octet-stream)
file #45070:  toto.mak added by vincentb1 (284B - application/octet-stream)

 

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 mbuilov (Posted a comment)
  • -email is unavailable- added by vincentb1 (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-15 vincentb1 Attached File- Added make-patch1.diff, #53093
    2018-09-27 vincentb1 Attached File- Added make-patch.diff, #45105
    2018-09-25 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2018-09-21 vincentb1 Attached File- Added toto.mak, #45070

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code