title: Makefile rule to keep intermediate files
body: <p>To debug a complex XSLT transformation I broke it into several parts: first I build <code>%.1.xml</code>, then I use it to build <code>%.2.xml</code>, and finally I build <code>%.3.xml</code>. It all works fine, but if I ask Make to build the last one, then Make invariably deletes the intermediate <code>%.1.xml</code> and <code>%.2.xml</code>, and I'd rather keep them. I've tried to mark all <code>.xml</code> files as <code>.PRECIOUS</code> so:</p>
  
  <pre><code>.PRECIOUS: %.xml
  </code></pre>
  
  <p>but this didn't seem to work. (I also tried to use <code>%.1.xml</code> and <code>%.2.xml</code>, but this didn't work either. I then tried to mark them as <code>.SECONDARY</code> in the same manner and with the same negative result. The only way it doesn't delete the intermediate files is when the files already exist; in this case it only rebuilds them. But if the files do not exist, it always deletes them.</p>
  
  <p>What am I missing?</p>
  
  <p>GNU Make 4.1.</p>
  
  <p><strong>Update:</strong> the Makefile, <code>&gt;&gt;</code> stands for <code>TAB</code>:</p>
  
  <pre><code>sample-%.1.xml: sample-%.0.xml job.1.xslt job.xslt
     &gt;&gt;   xsltproc $(filter %.1.xslt,$^) $(filter %.xml,$^) &gt; $@
  sample-%.2.xml: sample-%.1.xml job.2.xslt job.xslt
     &gt;&gt;   xsltproc $(filter %.2.xslt,$^) $(filter %.xml,$^) &gt; $@
  sample-%.3.xml: sample-%.2.xml job.3.xslt job.xslt
     &gt;&gt;   xsltproc $(filter %.3.xslt,$^) $(filter %.xml,$^) &gt; $@
  .SECONDARY: %.xml   # or .PRECIOUS: %.xml
  </code></pre>
  
  <p>It works fine, rebuilds everything or builds intermediate files as required, but when asked to build <code>.3.xml</code> and <code>.1.xml</code> and <code>.2.xml</code> do not exist, it builds them and then deletes at the end. If <code>.1.xml</code> exists, but <code>.2.xml</code> doesn't, it will rebuild all and delete <code>.2.xml</code>. It's not a show-stopper, of course, but I want to understand :)</p>