make: Variables in Recipes

1 
1 5.1.2 Using Variables in Recipes
1 --------------------------------
1 
1 The other way in which 'make' processes recipes is by expanding any
11 variable references in them (⇒Basics of Variable References
 Reference.).  This occurs after make has finished reading all the
1 makefiles and the target is determined to be out of date; so, the
1 recipes for targets which are not rebuilt are never expanded.
1 
1    Variable and function references in recipes have identical syntax and
1 semantics to references elsewhere in the makefile.  They also have the
1 same quoting rules: if you want a dollar sign to appear in your recipe,
1 you must double it ('$$').  For shells like the default shell, that use
1 dollar signs to introduce variables, it's important to keep clear in
1 your mind whether the variable you want to reference is a 'make'
1 variable (use a single dollar sign) or a shell variable (use two dollar
1 signs).  For example:
1 
1      LIST = one two three
1      all:
1              for i in $(LIST); do \
1                  echo $$i; \
1              done
1 
1 results in the following command being passed to the shell:
1 
1      for i in one two three; do \
1          echo $i; \
1      done
1 
1 which generates the expected result:
1 
1      one
1      two
1      three
1