[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a question about $(call function
From: |
Philip Guenther |
Subject: |
Re: a question about $(call function |
Date: |
Wed, 15 Jun 2011 00:50:29 -0700 |
On Tue, Jun 14, 2011 at 12:08 AM, ali hagigat <address@hidden> wrote:
>>philip:
>> This is incorrect. 'call' is a builtin function; $(call var1) is an
>> invocation of a function that return 'kk', which is *not* a built in
>> function.
>
> The manual says:
> "If variable is the name of a builtin
> function, the builtin function is always invoked "
>
> If the purpose of the manual is that variable is exactly the name of
> the built in function like "call" as you said, then we have some thing
> like the following:
> $(call call,pp)
Yes, exactly!
$ cat Makefile
origin = $1 is from mars
origin2 = $1 is from mars
all:
echo $(call origin,CC)
echo $(call origin2,CC)
$ make
echo default
default
echo CC is from mars
CC is from mars
$
Despite 'origin' and 'origin2' and the $(call) usages being identical
other than the names, the former called the builtin instead of the
variable/function defined in the Makefile, while the latter called the
one defined in the Makefile.
That's all that that chunk in the documentation is saying.
> In this example our variable is the name of a built in function but
> how it wants to be expanded?
Hmm, that sentence doesn't follow english grammar rules. I *think*
you mean to say "how _does_ it want to be expanded", or maybe "what
does it mean for it to be expanded".
The answer, either way, is that the 'expansion' of text that doesn't
contain a dollar-sign is the unchanged text. I.e., the expansion of
"call", is "call", which is the name of a builtin function.
Note that it *MUST* make sense to expand plain text that doesn't
contain dollar-signs, as make does that all the time as part of
commands in rules. Consider this rule:
program: $(OBJS)
@echo linking...
@$(CC) -o $@ $(OBJS) $(LIBS)
When it expands the first line of the commands for that rule, there's
no dollar-signs, so it's simply unaltered.
> as the manual said!! If i accept your
> word the manual does not make sense.
I disagree.
> When i read the manual i thought that the meaning of this sentence of
> the manual:
> "If variable is the name of a builtin function "
> is that the variable expands and the result is a function like:
> $(call $(call kk),pp)
I don't think that understanding is consistent with the interpretation
of the descriptions of other functions.
>> Because on the immediately preceding Makefile line you set 'kk' to
>> 'aba', so $(call kk,pp) expands to 'aba'.
>
> I did not set kk to aba!! kk has a separate defintion:
> kk=$(1)00 , which never executes and my question is that why it is
> never considered?
Read your example again and interpret the lines in order:
>>> kk=$(1)00
EXPAND 'kk' to get 'kk'
SET VARIABLE 'kk' to '$(1)00'
That 'EXPANDS' bit is specified/described in the docs in section3.9
How `make' Reads a Makefile, where it says that the left side of an
assignment has IMMEDIATE expansion.
>>> aba=$(1)11
EXPAND 'aba' to get 'aba'
SET VARIABLE 'aba' to '$(1)11'
>>> var1=kk
EXPAND 'var1' to get 'var1'
SET VARIABLE 'var1' to 'kk'
>>> $(call var1)=aba
EXPAND '$(call var1)' to get 'kk'
SET VARIABLE 'kk' to 'aba'
> Lets move step by step, when we have var2=$(call $(call var1),pp).
> What is the first expansion? is it:
> var2=$(call kk,pp)
> or
> var2=$(call aba, pp)
Neither: since this assignment uses '=' and not ':=', it is a
recursively expanded variable and the value is not expanded at all at
the point of this statement.
However, when $(var2) is expanded during the processing of the
commands for the 'all' target, the first step is to expand '$(call
var1)' to 'kk', because 'var1' is currently set to 'kk'. So, it goes:
$(warning var2=$(var2))
EXPAND 'var2' to '$(call $(call var1),pp)':
$(warning var2=$(call $(call var1),pp))
EXPAND '$(call var1)' to 'kk':
$(warning var2=$(call kk,pp))
EXPAND '$(call kk,pp)' to 'aba' (because that's what 'kk' was set
to by the '$(call var1)=aba' line above)
$(warning var2=aba)
EXPAND '$(warning var2=aba)' to '' with side-effect of writing
'var2=aba' to the make output
> In any case , none of the two functions of aba or kk are called? Why?
The function 'kk' is called, but you changed it's value.
Philip Guenther