Issues using .SECONDARY and .PRECIOUS to prevent deletion of intermediate files

Brian Vandenberg <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs
Organization http://groups.google.com
Message-ID <ec59814d-d1c7-4a46-a534-f9c57d50bc5a@d17g2000prl.googlegroups.com>
The documentation for .secondary gives the impression you can
use .SECONDARY with no targets to prevent make from deleting
intermediate files, but this approach has side-effects that can
prevent things from building.

As an example: I have a fairly large build with a large number of
headers used that are generated from Fortran code.  The tool used to
generate the Fortran code is built within the same code-base.  I added
targets of the form:

%.h : %.inc ${THE_TOOL}
  ${THE_TOOL} ${<}

The headers actually get symlinked to a separate location within the
build -- please, I don't need comments on this architecture, I'm
already pushing to eliminate that from the build.  So, the symlinks
themselves are the targets being built, whereas the header is an
intermediate target.

${THE_TOOL} gets treated as an intermediate target when I
use .SECONDARY without any dependencies specified, which seems to have
some odd side effects.  If I specify a given symlink as a primary
target, it induces the tool to build without problem, then the rule to
generate the header to be symlinked is kicked off -- everything is
fine.

However, when I run the full build, it delays building the tool quite
a bit, but the fact it isn't built yet doesn't prevent the recipe that
uses the tool from executing.  I've traced it through the debug output
with '-d', and there isn't enough info for me to draw a conclusion
other than what I've outlined already.

Instead of using .SECONDARY, I tried using .PRECIOUS with:

.PRECIOUS: %.cc

... where some .cc files are generated dynamically.  However, the
target building them is specified as:

/some/fully/qualified/path/something%.cc: whatever.cc

.PRECIOUS only matches if the target name matches -- it isn't using
the % to do pattern matching.

This differs in behavior from other areas where patterns are allowed.
As an example:

%_blah.o : SOME_VARIABLE = whatever

... will work, in spite of the fact the target that actually builds it
is given as:

%.o : %.cc

Comments?  Questions?  Suggestions?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.