make: Pattern-specific

1 
1 6.12 Pattern-specific Variable Values
1 =====================================
1 
11 In addition to target-specific variable values (⇒Target-specific
 Variable Values Target-specific.), GNU 'make' supports pattern-specific
1 variable values.  In this form, the variable is defined for any target
1 that matches the pattern specified.
1 
1    Set a pattern-specific variable value like this:
1 
1      PATTERN ... : VARIABLE-ASSIGNMENT
1    where PATTERN is a %-pattern.  As with target-specific variable
1 values, multiple PATTERN values create a pattern-specific variable value
1 for each pattern individually.  The VARIABLE-ASSIGNMENT can be any valid
1 form of assignment.  Any command line variable setting will take
1 precedence, unless 'override' is specified.
1 
1    For example:
1 
1      %.o : CFLAGS = -O
1 
1 will assign 'CFLAGS' the value of '-O' for all targets matching the
1 pattern '%.o'.
1 
1    If a target matches more than one pattern, the matching
1 pattern-specific variables with longer stems are interpreted first.
1 This results in more specific variables taking precedence over the more
1 generic ones, for example:
1 
1      %.o: %.c
1              $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
1 
1      lib/%.o: CFLAGS := -fPIC -g
1      %.o: CFLAGS := -g
1 
1      all: foo.o lib/bar.o
1 
1    In this example the first definition of the 'CFLAGS' variable will be
1 used to update 'lib/bar.o' even though the second one also applies to
1 this target.  Pattern-specific variables which result in the same stem
1 length are considered in the order in which they were defined in the
1 makefile.
1 
1    Pattern-specific variables are searched after any target-specific
1 variables defined explicitly for that target, and before target-specific
1 variables defined for the parent target.
1