+dnl mtime_uptodate file-a file-b: returns success iff file-a's modification
+dnl time is at least as new as file-b's.
+m4_divert_push([PREPARE_TESTS])dnl
+mtime_uptodate () {
+ cat >mtime-uptodate.mk <<EOF
+$1: $2
+ false
+EOF
+ $MAKE -f mtime-uptodate.mk >/dev/null 2>&1 || return 1
+}
+m4_divert_pop([PREPARE_TESTS])
+
+dnl TEST_MTIME_DELAY
+dnl
+dnl Delay script execution such that file modifications done prior to the
+dnl delay will have older timestamps than file modifications performed after
+dnl the delay.
+dnl
+dnl Some filesystems have insufficient timestamp resolution (or maybe
+dnl computers are just too fast) to reliably distinguish between back-to-back
+dnl file modification.
+dnl
+dnl This delay is implemented by repeatingly touching files until a different
+dnl timestamp is produced.
+m4_define([TEST_MTIME_DELAY],
+[touch mtime-delay.old; touch mtime-delay.new
+while mtime_uptodate mtime-delay.old mtime-delay.new; do
+ touch mtime-delay.new
+done])
+