Subject: bug#77805: new snapshot available: m4-1.4.19.60-6ebfc.tar.xz

From: Karl Berry <[email-masked]>
Date: Sun, 18 May 2025 16:25:10 -0600

Does anyone have a BSD system (any flavor) I could get access to?

Alternatively, attached is my unreleased version of mdate-sh which tries
to handle SOURCE_DATE_EPOCH. It seems to work ok with GNU date. I copied
the BSD date command (date -u -r ...) from
https://reproducible-builds.org/docs/source-date-epoch/ but have no way
to test. E.g.:
  SOURCE_DATE_EPOCH=123456 ./mdate-sh /tmp
should output
  2 January 1970

I also don't know if there are other date commands that must be
supported, or if it's worth falling back to Perl, or what.

Suggestions, advice, testing?

Here's the important part of the diff:

--- a/lib/mdate-sh
+++ b/lib/mdate-sh
@@ -80,6 +83,38 @@ export LC_TIME
 TZ=UTC0
 export TZ
 
+# https://reproducible-builds.org/docs/source-date-epoch/
+if test -n "$SOURCE_DATE_EPOCH"; then
+  date_fmt="+%d %B %Y"
+  result=`date -u --date="@$SOURCE_DATE_EPOCH" "$date_fmt" 2>/dev/null`
+  if test -z "$result"; then
+    result=`date -u -r "$SOURCE_DATE_EPOCH" "$date_fmt" 2>/dev/null`
+    if test -z "$result"; then
+      # Another possibility would be to use
+      #   perl -e 'print scalar gmtime($SOURCE_DATE_EPOCH)'
+      # and cut the fields out of the output, but seems plausible that
+      # Perl won't always be available.
+      echo "$0: SOURCE_DATE_EPOCH was set, but can't convert: $SOURCE_DATE_EPOCH" >&2
+      exit 1
+    fi
+  fi
+  #
+  # Remove leading spaces and zeros. We don't want to get into the
+  # various date options to control this. (Not quoting $result here
+  # isn't important, just another way to omit leading spaces.)
+  result=`echo $result | sed 's/^[ 0]*//'`
+  if test -z "$result"; then
+    echo "$0: SOURCE_DATE_EPOCH was set, but converted to empty: $SOURCE_DATE_EPOCH" >&2
+    exit 1
+  fi
+  #
+  # Hopefully ok.
+  echo $result
+  exit 0
+fi
+# end of SOURCE_DATE_EPOCH support, rest is about the normal case of
+# using the mtime of the specified file.
+
 # GNU ls changes its time format in response to the TIME_STYLE
 # variable.  Since we cannot assume 'unset' works, revert this
 # variable to its documented default.