views:

34

answers:

1

I would like to have a Makefile target that gets rebuilt only if the target file is older than some time interval.

As an example, say that I have some way of generating a key that is valid for one day, but generating it takes a non-trivial amount of time. I could just regenerate it each time I needed it:

.PHONY: key
key:
    sleep 5 && echo generated > key
foo: key
    echo foo
bar: key
    echo bar

But, over the course of the day, I might type make foo or make bar quite a few times. Waiting each time is annoying, and I would rather just eat this cost once per day.

+3  A: 

Have the generated file depend on some dummy file like key-timestamp, then have a cron job touch that file every day.

Jonathan Feinberg
While I believe this would work, it would require extra setup on the part of every developer who wanted to compile this code. If the cron entry wasn't setup, then the build would start failing whenever the key expired.
Shepmaster