Skeen
Skeen

Reputation: 4722

GNU Make, building unnecessary dependencies

In my makefile I have a rule alike this;

res/resource.me: res/lengthy_dependency
   ... code that builds resources.me assuming lengthy_dependency is present ...

res/lengthy_dependency:
   ... Download 10GB data and stuff ...

This is all nice and dandy, however when running res/resource.me while it is built and res/lengthy_dependency is removed to save space. I get the lengthy_dependency running, instead of the "nothing to be done for res/resource.me".

If I comment out the body of res/lengthy_dependency, and keep everything else static; I do get the "nothing to be done for res/resource.me".

Why does the details of how to build res/lengthy_dependency affect if it's built or not?

Note: res/lengthy_dependency doesn't have any sub-dependencies. Edit: It seems any body in res/lengthy_dependency triggers a rebuild of it.

Upvotes: 0

Views: 77

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126175

This is (more or less) what the .SECONDARY special target is for. If you add rule making something dependent on .SECONDARY it will only be rebuilt if specifically asked for or needed for a non-existant target:

.SECONDARY: res/lengthy_dependency

Now res/lengthy_dependency will only be downloaded if you specifically ask for it on the command line, or if something that depends on it needs to be rebuilt for some other reason.

Upvotes: 1

Related Questions