make: Reference
1
1 6.1 Basics of Variable References
1 =================================
1
1 To substitute a variable's value, write a dollar sign followed by the
1 name of the variable in parentheses or braces: either '$(foo)' or
1 '${foo}' is a valid reference to the variable 'foo'. This special
1 significance of '$' is why you must write '$$' to have the effect of a
1 single dollar sign in a file name or recipe.
1
1 Variable references can be used in any context: targets,
1 prerequisites, recipes, most directives, and new variable values. Here
1 is an example of a common case, where a variable holds the names of all
1 the object files in a program:
1
1 objects = program.o foo.o utils.o
1 program : $(objects)
1 cc -o program $(objects)
1
1 $(objects) : defs.h
1
1 Variable references work by strict textual substitution. Thus, the
1 rule
1
1 foo = c
1 prog.o : prog.$(foo)
1 $(foo)$(foo) -$(foo) prog.$(foo)
1
1 could be used to compile a C program 'prog.c'. Since spaces before the
1 variable value are ignored in variable assignments, the value of 'foo'
1 is precisely 'c'. (Don't actually write your makefiles this way!)
1
1 A dollar sign followed by a character other than a dollar sign,
1 open-parenthesis or open-brace treats that single character as the
1 variable name. Thus, you could reference the variable 'x' with '$x'.
1 However, this practice is strongly discouraged, except in the case of
1 the automatic variables (⇒Automatic Variables).
1