help-make
[Top][All Lists]
Advanced

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

Re: 6.2 The Two Flavors of Variables


From: ali hagigat
Subject: Re: 6.2 The Two Flavors of Variables
Date: Sat, 26 Feb 2011 07:14:21 +0330

I appreciate much Mr.Smith for the explanation. I wonder if you could
give an example of using recursion of variables regarding to $(call
...)
Regards

On Thu, Feb 24, 2011 at 1:05 AM, Paul Smith <address@hidden> wrote:
> On Wed, 2011-02-23 at 11:54 +0330, ali hagigat wrote:
>> CFLAGS = $(CFLAGS) -O
>>
>> Why it causes an infinite loop? The first time $(CFLAGS) is null so
>> the right side will be expanded to "null -O". There will be no second
>> time as null is a final value and CFLAGS becomes -O
>
> Your statement "the first time $(CFLAGS) is null" indicates that you've
> missing the critical aspect of recursive variables.
>
> The right-hand side is NOT EXPANDED when the variable is assigned, at
> all.  It's not expanded until the variable is referenced later on.  When
> make reads that line above it doesn't expand $(CFLAGS), so its value at
> that time (presumably null, yes) is irrelevant.
>
> After that line, the CFLAGS variable has the value '$(CFLAGS) -O'.
>
> The error happens later on, when someone else uses $(CFLAGS), for
> example:
>
>        foo.o: foo.c
>                $(CC) -o $@ -c $(CFLAGS) $<
>
> Now make wants to expand $(CFLAGS) and it sees that the value of that
> variable is '$(CFLAGS) -O'.  So it then tries to expand that, and sees
> that $(CFLAGS) expands to '$(CFLAGS) -O'.  And so on until you run out
> of memory.
>
> However, GNU make actually has a maximum number of times it will allow
> recursive expansion before it throws an error.  It used to fail on the
> first recursion but it turns out that recursion can actually be useful
> in conjunction with $(call ...) etc.
>
> --
> -------------------------------------------------------------------------------
>  Paul D. Smith <address@hidden>          Find some GNU make tips at:
>  http://www.gnu.org                      http://make.mad-scientist.net
>  "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
>
>



reply via email to

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