make: Wildcard Examples

1 
1 4.4.1 Wildcard Examples
1 -----------------------
1 
1 Wildcards can be used in the recipe of a rule, where they are expanded
1 by the shell.  For example, here is a rule to delete all the object
1 files:
1 
1      clean:
1              rm -f *.o
1 
1    Wildcards are also useful in the prerequisites of a rule.  With the
1 following rule in the makefile, 'make print' will print all the '.c'
1 files that have changed since the last time you printed them:
1 
1      print: *.c
1              lpr -p $?
1              touch print
1 
11 This rule uses 'print' as an empty target file; see ⇒Empty Target
 Files to Record Events Empty Targets.  (The automatic variable '$?' is
11 used to print only those files that have changed; see ⇒Automatic
 Variables.)
1 
1    Wildcard expansion does not happen when you define a variable.  Thus,
1 if you write this:
1 
1      objects = *.o
1 
1 then the value of the variable 'objects' is the actual string '*.o'.
1 However, if you use the value of 'objects' in a target or prerequisite,
1 wildcard expansion will take place there.  If you use the value of
1 'objects' in a recipe, the shell may perform wildcard expansion when the
1 recipe runs.  To set 'objects' to the expansion, instead use:
1 
1      objects := $(wildcard *.o)
1 
1 ⇒Wildcard Function.
1