Skip to content

Commit bd93270

Browse files
committed
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.
1 parent 1827713 commit bd93270

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ debug: all
7474

7575
${OBJ} ${TEST_OBJ}: Makefile config.mk
7676

77+
DATE_FMT = +%Y-%m-%d
78+
ifdef SOURCE_DATE_EPOCH
79+
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)")
80+
else
81+
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
82+
endif
7783
src/dunst.o: src/dunst.c
7884
${CC} -o $@ -c $< ${CPPFLAGS} ${CFLAGS} \
79-
-D_CCDATE="$(shell date '+%Y-%m-%d')" -D_CFLAGS="$(filter-out $(filter -I%,${INCS}),${CFLAGS})" -D_LDFLAGS="${LDFLAGS}"
85+
-D_CCDATE="${BUILD_DATE}" -D_CFLAGS="$(filter-out $(filter -I%,${INCS}),${CFLAGS})" -D_LDFLAGS="${LDFLAGS}"
8086

8187
%.o: %.c
8288
${CC} -o $@ -c $< ${CPPFLAGS} ${CFLAGS}

0 commit comments

Comments
 (0)