title: makefile: implicit rules: same target different prerequisites
body: <p>I have the following makefile:</p>
  <pre><code>all: DIR/0/a.txt DIR/1/b.txt DIR/2/c.txt DIR/3/abc.txt
  
  DIR/%/abc.txt: DIR/%/def.xtx # rule #1
      mkdir -p $(@D)
      touch $@
  
  DIR/%.txt: # rule #2
      mkdir -p $(@D)
      touch $@
  
  DIR/%.xtx:
      touch $@
  </code></pre>
  <p>I want to generate <code>DIR/%/def.xtx</code> whenever <code>DIR/%/abc.txt</code> is generated; otherwise generate only <code>DIR/%.txt</code>.</p>
  <p>Using the makefile above with GNU Make 3.81 however, only <code>DIR/3/abc.txt</code> gets generated and <code>DIR/%/def.xtx</code> is not generated.</p>
  <p>Following the &quot;Implicit rule search algorithm&quot; in the GNU make user manual we get:</p>
  <blockquote>
  <p>(1) Split t into a directory part, called d, and the rest, called n. For example, if t is ‘src/foo.o’, then d is ‘src/’ and n is ‘foo.o’.</p>
  </blockquote>
  <p>For <code>DIR/3/abc.txt</code>, <code>d = DIR/3</code> and <code>n = abc.txt</code>.</p>
  <blockquote>
  <p>(2) Make a list of all the pattern rules one of whose targets matches t or n. If the target pattern contains a slash, it is matched against t; otherwise, against n.</p>
  </blockquote>
  <p>Rules #1 and #2 match.</p>
  <blockquote>
  <p>(3) If any rule in that list is not a match-anything rule, then remove all nonterminal match-anything rules from the list.</p>
  </blockquote>
  <p>NOT SURE: no rule is removed from the list.</p>
  <blockquote>
  <p>(4) Remove from the list all rules with no recipe.</p>
  </blockquote>
  <p>No rule is removed.</p>
  <blockquote>
  <p>(5) For each pattern rule in the list:</p>
  <p>(5.a) Find the stem s, which is the nonempty part of t or n matched by the ‘%’ in the target pattern.</p>
  </blockquote>
  <p>For rule #1, <code>s = 3</code>.
  For rule #2, <code>s = 3/abc</code></p>
  <blockquote>
  <p>(5.b) Compute the prerequisite names by substituting s for ‘%’; if the target pattern does not contain a slash, append d to the front of each prerequisite name.</p>
  </blockquote>
  <p>For rule #1, it becomes: <code>DIR/3/abc.txt: DIR/3/def.xtx</code>
  Rule #2 has no prerequisites.</p>
  <blockquote>
  <p>(5.c) Test whether all the prerequisites exist or ought to exist. (If a file name is mentioned in the makefile as a target or as an explicit prerequisite, then we say it ought to exist.)</p>
  </blockquote>
  <p>NOT SURE: <code>DIR/3/def.xtx</code> is mentioned by the rule <code>DIR/%.xtx:</code>.</p>
  <p>After this long long long explanation, my opinion is that I am probably wrong in (5.c).</p>