help-make
[Top][All Lists]
Advanced

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

variable expansion (immediate vs deferred)


From: chandan
Subject: variable expansion (immediate vs deferred)
Date: Thu, 24 Jan 2008 05:11:02 -0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050716)

Consider the following makefile:

########################
LIST := one two three

all : $(LIST)
      @echo $^;
      @for i in $(LIST); do \
              echo -n "$$i "; \
      done
      @echo;

.PHONY : $(LIST)
one:

two:

three:

LIST := four five six
#########################

The output would be:
$ make
one two three
four five six

The GNU Make manual (section 3.9) has the following ....
******************************************************************
A rule is always expanded the same way, regardless of the form:
  immediate : immediate ; deferred
  deffered
******************************************************************
and this ...
******************************************************************
We say that expansion is deffered if expansion is not performed
immediately. Expansion of deffered construct is not performed
until either the construct appears later in an immediate context,
or until  the second phase.
******************************************************************

In the above makefile $(LIST) appears in the prerequiste list of both
"all" and ".PHONY" which happen to be expanded in an immediate
context. The output shows that $(LIST) (within commands section) is
expanded in the second phase i.e target-update phase (even though
$(LIST) appears later in an immediate context).

Quoting from section 5.1.2 of GNU Make manual ...
******************************************************************
The other ways in which make processes commands is by expanding
any variable references in them. This occurs after make has finished
reading all the makefiles and the target is determined to be out of date;
*******************************************************************
Considering this statement the output is correct.

Can anybody clear this ambiguity.




reply via email to

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