help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A weird behaivor of GNU make, please help check it


From: 陈军(Chen Jun, NLSCAN)
Subject: Re: A weird behaivor of GNU make, please help check it
Date: Wed, 23 Feb 2011 10:30:19 +0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.16) Gecko/20101125 Thunderbird/3.0.11


Thank you Paul. $(eval ) is tricky and your explanation here is great!

On 2011-02-23 05:33, Paul Smith wrote:
On Tue, 2011-02-22 at 22:24 +0800, address@hidden wrote:
=======================
define _gmi_prcp_GenCopyRuleL0
#  $(info You catch me!)
   $2: $1
        @echo "PI_precopy for $2 ..."
endef

all:
        @echo "all.$(eval $(call _gmi_prcp_GenCopyRuleL0,ttt,yyy))"
=======================

It outputs:

===========
You catch me!
t.mk:8: *** prerequisites cannot be defined in command scripts.  Stop.
===========
This behaviors are not weird if you grok the expansion rules make uses.
Your recipe contains this:

         $(eval $(call _gmi_prcp_GenCopyRuleL0,ttt,yyy))

The way this works is that first the $(call ...) is evaluated.  This
expands the variable $(_gmi_prcp_GenCopyRuleLO) with the variable $(1)
set to ttt and the variable $(2) set to yyy.  This expansion happens
using simple, normal variable evaluation.

Once that is complete, then the result of that expansion is given to
$(eval ...) which evaluates it as makefile syntax.

With that in mind:

Two questions:
1. Since the $(info ) line is commented out, why "You catch me!" is
output?
Because that function is expanded during the first part, the $(call ...)
function, which doesn't know anything about makefile syntax, comments,
etc.  It just expands the value.

2. Since $(eval ) return empty string, why it can cause "prerequisites
cannot be defined in command scripts" error? What does this error mean?
Because this is being evaluated inside a recipe.  There is no way to add
new make rules, or new prerequisites to existing rules, from inside a
recipe (this is discussed in the manual).

The returned value of eval is not relevant here: what is relevant is
that while eval is working it sees that you are trying to create a new
rule, and that is not allowed in this context.








reply via email to

[Prev in Thread] Current Thread [Next in Thread]