make: Match-Anything Rules
1
1 10.5.5 Match-Anything Pattern Rules
1 -----------------------------------
1
1 When a pattern rule's target is just '%', it matches any file name
1 whatever. We call these rules "match-anything" rules. They are very
1 useful, but it can take a lot of time for 'make' to think about them,
1 because it must consider every such rule for each file name listed
1 either as a target or as a prerequisite.
1
1 Suppose the makefile mentions 'foo.c'. For this target, 'make' would
1 have to consider making it by linking an object file 'foo.c.o', or by C
1 compilation-and-linking in one step from 'foo.c.c', or by Pascal
1 compilation-and-linking from 'foo.c.p', and many other possibilities.
1
1 We know these possibilities are ridiculous since 'foo.c' is a C
1 source file, not an executable. If 'make' did consider these
1 possibilities, it would ultimately reject them, because files such as
1 'foo.c.o' and 'foo.c.p' would not exist. But these possibilities are so
1 numerous that 'make' would run very slowly if it had to consider them.
1
1 To gain speed, we have put various constraints on the way 'make'
1 considers match-anything rules. There are two different constraints
1 that can be applied, and each time you define a match-anything rule you
1 must choose one or the other for that rule.
1
1 One choice is to mark the match-anything rule as "terminal" by
1 defining it with a double colon. When a rule is terminal, it does not
1 apply unless its prerequisites actually exist. Prerequisites that could
1 be made with other implicit rules are not good enough. In other words,
1 no further chaining is allowed beyond a terminal rule.
1
1 For example, the built-in implicit rules for extracting sources from
1 RCS and SCCS files are terminal; as a result, if the file 'foo.c,v' does
1 not exist, 'make' will not even consider trying to make it as an
1 intermediate file from 'foo.c,v.o' or from 'RCS/SCCS/s.foo.c,v'. RCS
1 and SCCS files are generally ultimate source files, which should not be
1 remade from any other files; therefore, 'make' can save time by not
1 looking for ways to remake them.
1
1 If you do not mark the match-anything rule as terminal, then it is
1 non-terminal. A non-terminal match-anything rule cannot apply to a file
1 name that indicates a specific type of data. A file name indicates a
1 specific type of data if some non-match-anything implicit rule target
1 matches it.
1
1 For example, the file name 'foo.c' matches the target for the pattern
1 rule '%.c : %.y' (the rule to run Yacc). Regardless of whether this
1 rule is actually applicable (which happens only if there is a file
1 'foo.y'), the fact that its target matches is enough to prevent
1 consideration of any non-terminal match-anything rules for the file
1 'foo.c'. Thus, 'make' will not even consider trying to make 'foo.c' as
1 an executable file from 'foo.c.o', 'foo.c.c', 'foo.c.p', etc.
1
1 The motivation for this constraint is that non-terminal
1 match-anything rules are used for making files containing specific types
1 of data (such as executable files) and a file name with a recognized
1 suffix indicates some other specific type of data (such as a C source
1 file).
1
1 Special built-in dummy pattern rules are provided solely to recognize
1 certain file names so that non-terminal match-anything rules will not be
1 considered. These dummy rules have no prerequisites and no recipes, and
1 they are ignored for all other purposes. For example, the built-in
1 implicit rule
1
1 %.p :
1
1 exists to make sure that Pascal source files such as 'foo.p' match a
1 specific target pattern and thereby prevent time from being wasted
1 looking for 'foo.p.o' or 'foo.p.c'.
1
1 Dummy pattern rules such as the one for '%.p' are made for every
11 suffix listed as valid for use in suffix rules (⇒Old-Fashioned
Suffix Rules Suffix Rules.).
1