From 20911acc49bc194ac42aba1be946a778b36c48cb Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Thu, 23 Jul 2026 13:57:01 +0000 Subject: [PATCH] build: honor SOURCE_DATE_EPOCH for the build date; graceful git fallback MAGIC_BUILDDATE now derives from SOURCE_DATE_EPOCH (UTC) when it is set, falling back to the current local time otherwise. This makes the date baked into buildinfo.o reproducible for the appimage/npm tarballs (cf. npm/pack.sh, which already normalizes mtimes). Also add `2>/dev/null` to the MAGIC_COMMIT git call so a source tarball or a non-work-tree ${MAGICSRC} yields an empty commit rather than a git error. Only buildinfo.o consumes these (see the prior commit), so the shell still runs at defs.mak parse time but affects just that one unit's define. Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/defs.mak.in | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/defs.mak.in b/scripts/defs.mak.in index c186c80c..9c74b950 100755 --- a/scripts/defs.mak.in +++ b/scripts/defs.mak.in @@ -121,8 +121,15 @@ TCL_LIB_DIR = @TCL_LIB_DIR@ MAGIC_VERSION ?= $(shell cat ${MAGICSRC}/VERSION | cut -d. -f1-2) MAGIC_REVISION ?= $(shell cat ${MAGICSRC}/VERSION | cut -d. -f3) -MAGIC_COMMIT ?= $(shell git -C ${MAGICSRC} rev-parse HEAD) -MAGIC_BUILDDATE ?= $(shell date | tr -d '\r\n') +# git may be absent (source tarball) or ${MAGICSRC} not a work-tree: fall back to +# empty rather than emitting an error. +MAGIC_COMMIT ?= $(shell git -C ${MAGICSRC} rev-parse HEAD 2>/dev/null) +# Honor SOURCE_DATE_EPOCH (reproducible builds -- appimage/npm tarballs) when set, +# else the current time. UTC so the stamp does not depend on the builder's zone. +MAGIC_BUILDDATE ?= $(shell if [ -n "$$SOURCE_DATE_EPOCH" ]; then \ + date -u -d "@$$SOURCE_DATE_EPOCH" 2>/dev/null \ + || date -u -r "$$SOURCE_DATE_EPOCH" 2>/dev/null; \ + else date; fi | tr -d '\r\n') # This allow inheritence of the values from toplevel Makefile export MAGIC_VERSION