Skip to content

Commit

Permalink
Allow to override build date with SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bmwiedemann committed Jan 22, 2025
1 parent 1827713 commit bd93270
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit bd93270

Please sign in to comment.