Dave Dopson
Dave Dopson

Reputation: 42716

Suppress "Clock skew" warning for future-times in Makefile

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) $@

.PHONY: $(PROJECTS)
$(PROJECTS): 
     # 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'.
make: warning:  Clock skew detected.  Your build may be incomplete.

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

Upvotes: 1

Views: 3214

Answers (3)

asheidan
asheidan

Reputation: 139

Most versions of touch I have come across can do some date time maths which allows for setting the timestamp of a file directly via the --date option.

That and the fact that variables assigned with := are only "evaluated once" makes this a bit easier to read.

HOUR_AGO := .make/hour_ago
__UGLY := $(shell mkdir -p .make && touch --date='1hour ago' $(HOUR_AGO))
# The preceding line will be executed once

.make/proj_%: .make/hour_ago | .make
    $(MAKE) -s $(*F)
    @touch $@

.make:
    mkdir -p $@

I'm using something very similar to this to periodically refresh login tokens.

Never would have thought of it if it wasn't for Dave's answer though.


The directory is created by specifying it as a order-only-prerequisite

Upvotes: 1

Dave Dopson
Dave Dopson

Reputation: 42716

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
externals: $(PROJECTS:%=.make/proj_%)
.make/proj_%: $(HOUR_AGO_FILE)
     $(MAKE) -s $(*F)
     @touch $@

Upvotes: 0

Rob Kielty
Rob Kielty

Reputation: 8172

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

Upvotes: 0

Related Questions