3

To debug a complex XSLT transformation I broke it into several parts: first I build %.1.xml, then I use it to build %.2.xml, and finally I build %.3.xml. It all works fine, but if I ask Make to build the last one, then Make invariably deletes the intermediate %.1.xml and %.2.xml, and I'd rather keep them. I've tried to mark all .xml files as .PRECIOUS so:

.PRECIOUS: %.xml

but this didn't seem to work. (I also tried to use %.1.xml and %.2.xml, but this didn't work either. I then tried to mark them as .SECONDARY 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.

What am I missing?

GNU Make 4.1.

Update: the Makefile, >> stands for TAB:

sample-%.1.xml: sample-%.0.xml job.1.xslt job.xslt
   >>   xsltproc $(filter %.1.xslt,$^) $(filter %.xml,$^) > $@
sample-%.2.xml: sample-%.1.xml job.2.xslt job.xslt
   >>   xsltproc $(filter %.2.xslt,$^) $(filter %.xml,$^) > $@
sample-%.3.xml: sample-%.2.xml job.3.xslt job.xslt
   >>   xsltproc $(filter %.3.xslt,$^) $(filter %.xml,$^) > $@
.SECONDARY: %.xml   # or .PRECIOUS: %.xml

It works fine, rebuilds everything or builds intermediate files as required, but when asked to build .3.xml and .1.xml and .2.xml do not exist, it builds them and then deletes at the end. If .1.xml exists, but .2.xml doesn't, it will rebuild all and delete .2.xml. It's not a show-stopper, of course, but I want to understand :)

Eugeniu Rosca
  • 5,177
  • 16
  • 45
Mikhail Edoshin
  • 2,639
  • 16
  • 25

1 Answers1

5

I managed to reproduce this issue, but only when using target names based on patterns! Sadly, neither .SECONDARY, nor .PRECIOUS worked when trying to aggregate more targets in a pattern (they work as expected if the target names are just plain strings!).

I found a workaround though (source). When .SECONDARY: is used with no associated targets, this actually converts ALL the intermediate targets to .SECONDARY and that solved the problem.

Community
  • 1
  • 1
Eugeniu Rosca
  • 5,177
  • 16
  • 45
  • There is some logic to it: the left side has no pattern to match the right side, hence it ignores it. I guess a wildcard would also work. – Mikhail Edoshin Jun 25 '15 at 19:21