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: Paul Smith
Subject: Re: A weird behaivor of GNU make, please help check it
Date: Tue, 22 Feb 2011 16:33:08 -0500

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]