make: Implicit Rule Search

1 
1 10.8 Implicit Rule Search Algorithm
1 ===================================
1 
1 Here is the procedure 'make' uses for searching for an implicit rule for
1 a target T.  This procedure is followed for each double-colon rule with
1 no recipe, for each target of ordinary rules none of which have a
1 recipe, and for each prerequisite that is not the target of any rule.
1 It is also followed recursively for prerequisites that come from
1 implicit rules, in the search for a chain of rules.
1 
1    Suffix rules are not mentioned in this algorithm because suffix rules
1 are converted to equivalent pattern rules once the makefiles have been
1 read in.
1 
1    For an archive member target of the form 'ARCHIVE(MEMBER)', the
1 following algorithm is run twice, first using the entire target name T,
1 and second using '(MEMBER)' as the target T if the first run found no
1 rule.
1 
1   1. Split T into a directory part, called D, and the rest, called N.
1      For example, if T is 'src/foo.o', then D is 'src/' and N is
1      'foo.o'.
1 
1   2. Make a list of all the pattern rules one of whose targets matches T
1      or N.  If the target pattern contains a slash, it is matched
1      against T; otherwise, against N.
1 
1   3. If any rule in that list is _not_ a match-anything rule, then
1      remove all non-terminal match-anything rules from the list.
1 
1   4. Remove from the list all rules with no recipe.
1 
1   5. For each pattern rule in the list:
1 
1        a. Find the stem S, which is the nonempty part of T or N matched
1           by the '%' in the target pattern.
1 
1        b. Compute the prerequisite names by substituting S for '%'; if
1           the target pattern does not contain a slash, append D to the
1           front of each prerequisite name.
1 
1        c. Test whether all the prerequisites exist or ought to exist.
1           (If a file name is mentioned in the makefile as a target or as
1           an explicit prerequisite, then we say it ought to exist.)
1 
1           If all prerequisites exist or ought to exist, or there are no
1           prerequisites, then this rule applies.
1 
1   6. If no pattern rule has been found so far, try harder.  For each
1      pattern rule in the list:
1 
1        a. If the rule is terminal, ignore it and go on to the next rule.
1 
1        b. Compute the prerequisite names as before.
1 
1        c. Test whether all the prerequisites exist or ought to exist.
1 
1        d. For each prerequisite that does not exist, follow this
1           algorithm recursively to see if the prerequisite can be made
1           by an implicit rule.
1 
1        e. If all prerequisites exist, ought to exist, or can be made by
1           implicit rules, then this rule applies.
1 
1   7. If no implicit rule applies, the rule for '.DEFAULT', if any,
1      applies.  In that case, give T the same recipe that '.DEFAULT' has.
1      Otherwise, there is no recipe for T.
1 
1    Once a rule that applies has been found, for each target pattern of
1 the rule other than the one that matched T or N, the '%' in the pattern
1 is replaced with S and the resultant file name is stored until the
1 recipe to remake the target file T is executed.  After the recipe is
1 executed, each of these stored file names are entered into the data base
1 and marked as having been updated and having the same update status as
1 the file T.
1 
1    When the recipe of a pattern rule is executed for T, the automatic
11 variables are set corresponding to the target and prerequisites.  ⇒
 Automatic Variables.
1