Chapter 5: Writing Recipes in Rules 43
we will get output like this:
hello world
If you like, you can also use target-specific variables (see Section 6.11 [Target-specific
Variable Values], page 71) to obtain a tighter correspondence between the variable and the
recipe that uses it.
5.1.2 Using Variables in Recipes
The other way in which make processes recipes is by expanding any variable references in
them (see Section 6.1 [Reference], page 59). This occurs after make has finished reading
all the makefiles and the target is determined to be out of date; so, the recipes for targets
which are not rebuilt are never expanded.
Variable and function references in recipes have identical syntax and semantics to ref-
erences elsewhere in the makefile. They also have the same quoting rules: if you want a
dollar sign to appear in your recipe, you must double it (‘$$’). For shells like the default
shell, that use dollar signs to introduce variables, it’s important to keep clear in your mind
whether the variable you want to reference is a make variable (use a single dollar sign) or a
shell variable (use two dollar signs). For example:
LIST = one two three
all:
for i in $(LIST); do \
echo $$i; \
done
results in the following command being passed to the shell:
for i in one two three; do \
echo $i; \
done
which generates the expected result:
one
two
three
5.2 Recipe Echoing
Normally make prints each line of the recipe before it is executed. We call this echoing
because it gives the appearance that you are typing the lines yourself.
When a line starts with ‘@’, the echoing of that line is suppressed. The ‘@’ is discarded
before the line is passed to the shell. Typically you would use this for a command whose
only effect is to print something, such as an echo command to indicate progress through
the makefile:
@echo About to make distribution files
When make is given the flag ‘-n’ or ‘--just-print’ it only echoes most recipes, without
executing them. See Section 9.7 [Summary of Options], page 104. In this case even the
recipe lines starting with ‘@’ are printed. This flag is useful for finding out which recipes
make thinks are necessary without actually doing them.
Comentários a estes Manuais