Subject: [bug#61240] improve high-res file timestamp in Automake

From: Paul Eggert <[email-masked]>
Date: Thu, 2 Feb 2023 14:24:59 -0800

I installed the attached to port a FileUtils.pm patch back from Autoconf 
into Automake. I wish Perl supported file timestamps with nanosecond 
resolution, but apparently not, so this is the best we could do easily.

Although this bumps the required Perl version from 5.6 (2000) to 5.10 
(2007), I don't think that's a problem nowadays.

From 4e3744a15c4d8bdb46c11ead2fb56c5f591b714b Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Thu, 2 Feb 2023 14:13:24 -0800
Subject: [PATCH 1/2] maint: require perl 5.010 or later

This is needed for better treatment of high-res timestamps.
---
 NEWS                           | 6 +++++-
 bin/aclocal.in                 | 2 +-
 bin/automake.in                | 2 +-
 configure.ac                   | 5 ++---
 lib/Automake/ChannelDefs.pm    | 2 +-
 lib/Automake/Channels.pm       | 2 +-
 lib/Automake/Condition.pm      | 2 +-
 lib/Automake/Config.in         | 2 +-
 lib/Automake/Configure_ac.pm   | 2 +-
 lib/Automake/DisjConditions.pm | 2 +-
 lib/Automake/FileUtils.pm      | 2 +-
 lib/Automake/General.pm        | 2 +-
 lib/Automake/Getopt.pm         | 2 +-
 lib/Automake/Item.pm           | 2 +-
 lib/Automake/ItemDef.pm        | 2 +-
 lib/Automake/Language.pm       | 2 +-
 lib/Automake/Location.pm       | 2 +-
 lib/Automake/Options.pm        | 2 +-
 lib/Automake/Rule.pm           | 2 +-
 lib/Automake/RuleDef.pm        | 2 +-
 lib/Automake/VarDef.pm         | 2 +-
 lib/Automake/Variable.pm       | 2 +-
 lib/Automake/Version.pm        | 2 +-
 lib/Automake/Wrap.pm           | 2 +-
 lib/Automake/XFile.pm          | 2 +-
 25 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/NEWS b/NEWS
index 8cba8b3fe..cb325642f 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,10 @@ please see NEWS-2.0 and start following the advice there now.
 
 New in 1.17:
 
+* Version requirements:
+
+  - Perl 5.10 (2007) or greater is required.
+
 * New features added
 
   - RANLIB may be overridden on a per-target basis.
@@ -36,7 +40,7 @@ New in 1.17:
     and -Q is not used, since its support and behavior varies.
 
   - Emacs Lisp compilations respects silent make output.
-  
+
   - distcleancheck ignores "silly rename" files (.nfs* .smb* .__afs*)
     that can show up on network file systems.
 
diff --git a/bin/aclocal.in b/bin/aclocal.in
index f04cb30d8..34c253048 100644
--- a/bin/aclocal.in
+++ b/bin/aclocal.in
@@ -19,7 +19,7 @@
 # Written by Tom Tromey <[email-masked]>, and
 # Alexandre Duret-Lutz <[email-masked]>.
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/bin/automake.in b/bin/automake.in
index 139d5ad93..afd296afa 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -22,7 +22,7 @@
 
 package Automake;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/configure.ac b/configure.ac
index dcf2d9556..bf72023e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,10 +73,9 @@ if test -z "$PERL"; then
 fi
 # Save details about the selected perl interpreter in config.log.
 AM_RUN_LOG([$PERL --version])
-$PERL -e 'require 5.006;' || {
+$PERL -e 'require 5.010;' || {
    AC_MSG_ERROR(
-[perl 5.6 or better is required; perl 5.8.2 or better
-is recommended.  If you have several perl versions
+[perl 5.10 (2007) or better is required.  If you have several perl versions
 installed, select the one Automake should use using
   ./configure PERL=/path/to/perl])
 }
diff --git a/lib/Automake/ChannelDefs.pm b/lib/Automake/ChannelDefs.pm
index 1c436645e..bfe5ba548 100644
--- a/lib/Automake/ChannelDefs.pm
+++ b/lib/Automake/ChannelDefs.pm
@@ -44,7 +44,7 @@ shorthand function to output on specific channels.
 
 =cut
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Channels.pm b/lib/Automake/Channels.pm
index b4563d36e..5a36c93af 100644
--- a/lib/Automake/Channels.pm
+++ b/lib/Automake/Channels.pm
@@ -66,7 +66,7 @@ etc.) that can also be overridden on a per-message basis.
 
 =cut
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Condition.pm b/lib/Automake/Condition.pm
index 31ac81d80..d1e6811e8 100644
--- a/lib/Automake/Condition.pm
+++ b/lib/Automake/Condition.pm
@@ -15,7 +15,7 @@
 
 package Automake::Condition;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Config.in b/lib/Automake/Config.in
index 4fc918b58..3cc094d15 100644
--- a/lib/Automake/Config.in
+++ b/lib/Automake/Config.in
@@ -17,7 +17,7 @@
 
 package Automake::Config;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Configure_ac.pm b/lib/Automake/Configure_ac.pm
index efd428e2a..d4751ee26 100644
--- a/lib/Automake/Configure_ac.pm
+++ b/lib/Automake/Configure_ac.pm
@@ -20,7 +20,7 @@
 
 package Automake::Configure_ac;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/DisjConditions.pm b/lib/Automake/DisjConditions.pm
index 16540e7da..7612f607c 100644
--- a/lib/Automake/DisjConditions.pm
+++ b/lib/Automake/DisjConditions.pm
@@ -15,7 +15,7 @@
 
 package Automake::DisjConditions;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/FileUtils.pm b/lib/Automake/FileUtils.pm
index 848ff22d1..bd173032b 100644
--- a/lib/Automake/FileUtils.pm
+++ b/lib/Automake/FileUtils.pm
@@ -34,7 +34,7 @@ This perl module provides various general purpose file handling functions.
 
 =cut
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/General.pm b/lib/Automake/General.pm
index 4c1d0630f..4b977505d 100644
--- a/lib/Automake/General.pm
+++ b/lib/Automake/General.pm
@@ -15,7 +15,7 @@
 
 package Automake::General;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Getopt.pm b/lib/Automake/Getopt.pm
index 67958fd62..3b37d64a3 100644
--- a/lib/Automake/Getopt.pm
+++ b/lib/Automake/Getopt.pm
@@ -30,7 +30,7 @@ line options in conformance to the GNU Coding standards.
 
 =cut
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Item.pm b/lib/Automake/Item.pm
index a2637c6e1..a2e6c1420 100644
--- a/lib/Automake/Item.pm
+++ b/lib/Automake/Item.pm
@@ -15,7 +15,7 @@
 
 package Automake::Item;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/ItemDef.pm b/lib/Automake/ItemDef.pm
index 3e958a8ff..ca9bbb1eb 100644
--- a/lib/Automake/ItemDef.pm
+++ b/lib/Automake/ItemDef.pm
@@ -15,7 +15,7 @@
 
 package Automake::ItemDef;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Language.pm b/lib/Automake/Language.pm
index 8cd866dde..12a29bee4 100644
--- a/lib/Automake/Language.pm
+++ b/lib/Automake/Language.pm
@@ -15,7 +15,7 @@
 
 package Automake::Language;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Location.pm b/lib/Automake/Location.pm
index 21d08f7d2..77b059937 100644
--- a/lib/Automake/Location.pm
+++ b/lib/Automake/Location.pm
@@ -15,7 +15,7 @@
 
 package Automake::Location;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index 69fc2ecb5..aee183169 100644
--- a/lib/Automake/Options.pm
+++ b/lib/Automake/Options.pm
@@ -15,7 +15,7 @@
 
 package Automake::Options;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Rule.pm b/lib/Automake/Rule.pm
index 9f72d2728..6a622e639 100644
--- a/lib/Automake/Rule.pm
+++ b/lib/Automake/Rule.pm
@@ -15,7 +15,7 @@
 
 package Automake::Rule;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/RuleDef.pm b/lib/Automake/RuleDef.pm
index 1ae8b6332..e5b3a1b92 100644
--- a/lib/Automake/RuleDef.pm
+++ b/lib/Automake/RuleDef.pm
@@ -15,7 +15,7 @@
 
 package Automake::RuleDef;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/VarDef.pm b/lib/Automake/VarDef.pm
index 9f09411cc..3e139326e 100644
--- a/lib/Automake/VarDef.pm
+++ b/lib/Automake/VarDef.pm
@@ -15,7 +15,7 @@
 
 package Automake::VarDef;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm
index 2c118314e..cc6b12fe0 100644
--- a/lib/Automake/Variable.pm
+++ b/lib/Automake/Variable.pm
@@ -15,7 +15,7 @@
 
 package Automake::Variable;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Version.pm b/lib/Automake/Version.pm
index 369a229e8..02146a500 100644
--- a/lib/Automake/Version.pm
+++ b/lib/Automake/Version.pm
@@ -15,7 +15,7 @@
 
 package Automake::Version;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/Wrap.pm b/lib/Automake/Wrap.pm
index 9233798bd..73a624757 100644
--- a/lib/Automake/Wrap.pm
+++ b/lib/Automake/Wrap.pm
@@ -15,7 +15,7 @@
 
 package Automake::Wrap;
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
diff --git a/lib/Automake/XFile.pm b/lib/Automake/XFile.pm
index 05e8b32a2..fb256c97b 100644
--- a/lib/Automake/XFile.pm
+++ b/lib/Automake/XFile.pm
@@ -69,7 +69,7 @@ and C<getlines> methods to translate C<\r\n> to C<\n>.
 
 =cut
 
-use 5.006;
+use 5.010;
 use strict;
 use warnings FATAL => 'all';
 
-- 
2.39.1

From 01bf65daf6f6627b56fbe78fc436fd877ccd3537 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Thu, 2 Feb 2023 14:17:52 -0800
Subject: [PATCH 2/2] Use higher-resolution file timestamps
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/Automake/FileUtils.pm (mtime):
Return higher-resolution file timestamps.
This isn’t perfect, but it’s better than what we had.
Code change taken from Autoconf to partially fix a race
<https://bugs.gentoo.org/show_bug.cgi?id=782985>.
---
 lib/Automake/FileUtils.pm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/Automake/FileUtils.pm b/lib/Automake/FileUtils.pm
index bd173032b..6e9796a98 100644
--- a/lib/Automake/FileUtils.pm
+++ b/lib/Automake/FileUtils.pm
@@ -39,7 +39,7 @@ use strict;
 use warnings FATAL => 'all';
 
 use Exporter;
-use File::stat;
+use Time::HiRes qw(stat);
 use IO::File;
 
 use Automake::Channels;
@@ -115,10 +115,16 @@ sub mtime ($)
   return 0
     if $file eq '-' || ! -f $file;
 
-  my $stat = stat ($file)
+  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
+    $atime,$mtime,$ctime,$blksize,$blocks) = stat ($file)
     or fatal "cannot stat $file: $!";
 
-  return $stat->mtime;
+  # Unfortunately Time::HiRes converts timestamps to floating-point, and the
+  # rounding error can be hundreds of nanoseconds for circa-2023 timestamps.
+  # Perhaps some day Perl will support accurate file timestamps.
+  # For now, do the best we can without going outside Perl.
+
+  return $mtime;
 }

-- 
2.39.1