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, [email protected] 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.






_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to