From bd93270a1ef0eaaff86256e1daf0f6db831aed68 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Wed, 22 Jan 2025 05:53:18 +0100 Subject: [PATCH] Allow to override build date with SOURCE_DATE_EPOCH to make builds reproducible. See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable. This date call works with different flavors of date (GNU, BSD, other). This patch was done while working on reproducible builds for openSUSE. --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index eb25f1dc8..cd7c0c38e 100644 --- a/Makefile +++ b/Makefile @@ -74,9 +74,15 @@ debug: all ${OBJ} ${TEST_OBJ}: Makefile config.mk +DATE_FMT = +%Y-%m-%d +ifdef SOURCE_DATE_EPOCH + BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)") +else + BUILD_DATE ?= $(shell date "$(DATE_FMT)") +endif src/dunst.o: src/dunst.c ${CC} -o $@ -c $< ${CPPFLAGS} ${CFLAGS} \ - -D_CCDATE="$(shell date '+%Y-%m-%d')" -D_CFLAGS="$(filter-out $(filter -I%,${INCS}),${CFLAGS})" -D_LDFLAGS="${LDFLAGS}" + -D_CCDATE="${BUILD_DATE}" -D_CFLAGS="$(filter-out $(filter -I%,${INCS}),${CFLAGS})" -D_LDFLAGS="${LDFLAGS}" %.o: %.c ${CC} -o $@ -c $< ${CPPFLAGS} ${CFLAGS}