Take the 2-minute tour ×

I have a Makefile that does performs a task if it hasn't happened in the last hour. It does so like this:

HOUR_FROM_NOW = $(shell perl -e '($$s,$$m,$$h,$$d,$$M)=localtime(time()+3600); printf("%02d%02d%02d%02d\n",$$M+1,$$d,$$h,$$m);')
NOW_FILE      = $(shell mkdir -p .make; touch .make/now; echo .make/now )

.PHONY: externals
externals: $(PROJECTS:%=.make/proj_%)
.make/proj_%: $(NOW_FILE)
     $(MAKE) -s $(*F)
     touch -t $(HOUR_FROM_NOW) $@

     # do stuff, specifically, clone git-repo if not exists, else pull latest

That part works great, except that I now get warnings:

make: Warning: File `.make/proj' has modification time 3.5e+03 s in the future
make: Nothing to be done for `externals'.

Anyone know how to suppress those warnings? (Or to do a periodic task in a makefile)

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

I thought and thought, and then the stupid-obvious solution hit me ...

Instead of setting timestamps in the future with HOUR_FROM_NOW, I use the real time and compare with HOUR_AGO_FILE ...

HOUR_AGO      = $(shell perl -e '($$s,$$m,$$h,$$d,$$M)=localtime(time()-3600); printf("%02d%02d%02d%02d\n",$$M+1,$$d,$$h,$$m);')
HOUR_AGO_FILE      = $(shell mkdir -p .make; touch -t $(HOUR_AGO) .make/hour_ago; echo .make/hour_ago )

.PHONY: externals
.make/proj_%: $(HOUR_AGO_FILE)
     $(MAKE) -s $(*F)
     @touch $@
share|improve this answer
the review comment I is why do you have shell start the command in the sub shell commands. usually a $() spawns a sub shell. is that make file specific? –  Rob Kielty May 24 '12 at 7:24
"shell" is a makefile function. See gnu.org/software/make/manual/make.html. It may look like Bash, but there are some significant differences. $(shell ...) runs "..." in a subshell. $(...) is simply a variable reference to a variable named "..." - whereas in bash, $() is the subshell syntax. –  Dave Dopson May 25 '12 at 4:24
That makes sense, thanks for the link. –  Rob Kielty May 25 '12 at 7:46
add comment

I suspect that the + 3600 is at fault. What happens if you remove it?

share|improve this answer
If I remove it, then it pulls changes every time I run "make". The whole point is to only pull if we haven't already pulled in the last hour... –  Dave Dopson May 24 '12 at 2:25
A pleasure, any time. –  Rob Kielty May 24 '12 at 7:33
add comment

Your Answer


