make: custom up-to-date

Boris Kolpackov boris at kolpackov.net
Thu Sep 9 10:40:39 CDT 2004


Ian Dunbar <ian_dunbar at hotmail.com> writes:
 
> On your custom up-to-date system there seems to be one small bug/feature.
> 
> If everything is up to date according to the md5 test, but changed 
> according to timestamps you can end up with this kind of situation:
> 
> >make
> md5sum a.c | cmp -s a.c.md5 -; if test $? -ne 0; then md5sum a.c > a.c.md5; 
> fi
> md5sum b.c | cmp -s b.c.md5 -; if test $? -ne 0; then md5sum b.c > b.c.md5; 
> fi
> etc....
> 
> i.e. On each make invocation, md5sum is always run for every .c file that 
> is "touched" but not "changed".

Well, that's your custom up-to-date check therefore it is run every time
the up-to-date-ness is in question.


> Also you don't get the reassuring "make: `foo' is up to date." message.

That's actually a make bug.


> One possible workaround might be, in the md5 rule, to touch the .c to be 
> the same (older) date as the .md5 as an else part of your if statement. 
> Unfortunately touch doesn't have a use-same-timestamp-as-this-other-file 
> option, so getting the timestamp information might be tricky.


Actually it does: see -r option to POSIX touch. I just rewrote the command
above like this:

md5sum $< | cmp -s $@ -; if test $$? -ne 0; then md5sum $< > $@; \
else touch -r $@ $<; fi

This is a nice optimization but we should be careful here: we are changing
timestamp of a file behind make's back which can back fire (e.g., if we have
more than one target built from a particular prerequisite, one via md5 and
the other directly).

-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://www.kolpackov.net/pipermail/notes/attachments/20040909/23891264/attachment.bin


More information about the notes mailing list