make: Pattern Examples
1
1 10.5.2 Pattern Rule Examples
1 ----------------------------
1
1 Here are some examples of pattern rules actually predefined in 'make'.
1 First, the rule that compiles '.c' files into '.o' files:
1
1 %.o : %.c
1 $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
1
1 defines a rule that can make any file 'X.o' from 'X.c'. The recipe uses
1 the automatic variables '$@' and '$<' to substitute the names of the
1 target file and the source file in each case where the rule applies
1 (⇒Automatic Variables).
1
1 Here is a second built-in rule:
1
1 % :: RCS/%,v
1 $(CO) $(COFLAGS) $<
1
1 defines a rule that can make any file 'X' whatsoever from a
1 corresponding file 'X,v' in the sub-directory 'RCS'. Since the target
1 is '%', this rule will apply to any file whatever, provided the
1 appropriate prerequisite file exists. The double colon makes the rule
1 "terminal", which means that its prerequisite may not be an intermediate
1 file (⇒Match-Anything Pattern Rules Match-Anything Rules.).
1
1 This pattern rule has two targets:
1
1 %.tab.c %.tab.h: %.y
1 bison -d $<
1
1 This tells 'make' that the recipe 'bison -d X.y' will make both
1 'X.tab.c' and 'X.tab.h'. If the file 'foo' depends on the files
1 'parse.tab.o' and 'scan.o' and the file 'scan.o' depends on the file
1 'parse.tab.h', when 'parse.y' is changed, the recipe 'bison -d parse.y'
1 will be executed only once, and the prerequisites of both 'parse.tab.o'
1 and 'scan.o' will be satisfied. (Presumably the file 'parse.tab.o' will
1 be recompiled from 'parse.tab.c' and the file 'scan.o' from 'scan.c',
1 while 'foo' is linked from 'parse.tab.o', 'scan.o', and its other
1 prerequisites, and it will execute happily ever after.)
1