On Fri, 1 Jun 2018, John Calcote wrote:

I recently ran across some sample code in section 19.4 of the Autoconf
manual (modified slightly to reduce example):

$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
       autom4te --language=autotest -I '$(srcdir)' -o $@.tmp $@.at
       mv $@.tmp $@

This question isn't about autotest, but rather about the two commands in
this rule - why generate the output into $@.tmp and then mv $@.tmp into $@?
Is there some power mv has over autom4te that allows it better access to
the target under some conditions?

A reason to do such a thing is to avoid leaving a partial/corrupt output file in place due to the command writing it encountering an error. The assumption is the the 'mv' command would not be executed if the previous command encountered an error.

Another reason would be in a multi-processing environment (e.g. parallel compile) where the file content (or its timestamp) might be consumed before it is ready. The 'mv' is an atomic operation so once the file is in its final location, it is assured to be completely written.

Bob
--
Bob Friesenhahn
bfrie...@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/

_______________________________________________
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf

Reply via email to