Git likes to set mtime of files to the point where the working
directory is checked out, rather than the point where the last content
of the file was committed.  But Automake likes to populate the
generated doc/version.texi based on the mtime of doc/m4.texi.  Any
setup that uses a git checkout of m4 to build a new tarball will thus
get different contents in the manual if checked out on a different
date, breaking reproducible builds unless we take measures to
guarantee that the mtime matches the time of the last commit.

* configure.ac (st_touch): New code.
* THANKS: Update.
Suggested by Simon Josefsson, after a report by Santiago Vila:
https://lists.gnu.org/archive/html/bug-m4/2025-04/msg00052.html
---
 THANKS       |  1 +
 configure.ac | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/THANKS b/THANKS
index 9cfe3c5a..835bfa2a 100644
--- a/THANKS
+++ b/THANKS
@@ -124,6 +124,7 @@ Santiago Vila           sanv...@debian.org
 Scott Bartram           deneb!scottb
 Scott McCreary          scott...@gmail.com
 Sergey Poznyakoff       g...@gnu.org.ua
+Simon Josefsson         si...@josefsson.org
 Simon Leinen            si...@lia.di.epfl.ch
 Skip Montanaro          s...@automatrix.com
 Stepan Kasal            ka...@ucw.cz
diff --git a/configure.ac b/configure.ac
index db7c1395..4e6140ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,6 +127,20 @@ if test "$gl_gcc_warnings" = yes; then
   ])
 fi

+# Git tends to change the mtime of files according to when you clone or
+# checkout a different commit, rather than the time the commit was created.
+# But for reproducible builds, we want the generated doc/version.texi to
+# reflect the timestamp of the commit, not when git was used.
+AC_MSG_CHECKING([for timestamps of last git commit])
+st_touch=skipped
+if test -e "$srcdir"/.git && command -v git > /dev/null; then
+  if st_touch=$(env TZ=UTC0 git log -1 --format=%cd \
+             --date=format-local:%Y%m%d%H%M.%S); then
+    env TZ=UTC0 touch -m -t "$st_touch" "$srcdir"/doc/$PACKAGE.texi
+  fi
+fi
+AC_MSG_RESULT(touch $st_touch)
+
 # Tandem/NSK is broken - it has 'long long int' but not
 # 'unsigned long long int', which confuses assumptions made by gnulib.
 # Simply pretend that neither type exists if both do not work.
-- 
2.49.0


_______________________________________________
M4-patches mailing list
M4-patches@gnu.org
https://lists.gnu.org/mailman/listinfo/m4-patches

Reply via email to