Override __DATE__ from SOURCE_DATE_EPOCH if set

For deterministic/reproducible builds (where the same source and
toolchain can be verified to produce the same binary, allowing
maliciously substituted binaries to be detected) it is desirable to
take the software's idea of the build date from the build system;
otherwise, the real-time clock at the time of building affects the
result, making it non-reproducible.

SOURCE_DATE_EPOCH is a distribution-neutral specification for how
to do that. It is meant to be set by meta-build systems such as
dpkg or RPM, using a date/time that is already part of the source code,
for example the date of the latest git commit, the date in
the package's debian/changelog, or the date in the RPM spec file.

See https://reproducible-builds.org/specs/source-date-epoch/ for the
specification of SOURCE_DATE_EPOCH, or https://reproducible-builds.org/
for more information on reproducible builds in general.
This commit is contained in:
Simon McVittie 2016-06-30 10:05:40 +01:00
parent 6d38cc8609
commit c00707d449
4 changed files with 14 additions and 3 deletions

View file

@ -165,6 +165,13 @@ CFLAGS += -DOSTYPE=\"$(OSTYPE)\" -DARCH=\"$(ARCH)\"
# ----------
# https://reproducible-builds.org/specs/source-date-epoch/
ifdef SOURCE_DATE_EPOCH
CFLAGS += -DBUILD_DATE=\"$(shell date --utc --date="@${SOURCE_DATE_EPOCH}" +"%b %_d %Y" | sed -e 's/ /\\ /g')\"
endif
# ----------
# Systemwide installation
ifeq ($(WITH_SYSTEMWIDE),yes)
CFLAGS += -DSYSTEMWIDE

View file

@ -44,6 +44,10 @@
#error ARCH should be defined by the build system
#endif
#ifndef BUILD_DATE
#define BUILD_DATE __DATE__
#endif
#ifdef _WIN32
#define CFGDIR "YamagiQ2"
#else

View file

@ -241,7 +241,7 @@ Qcommon_Init(int argc, char **argv)
dedicated = Cvar_Get("dedicated", "0", CVAR_NOSET);
#endif
s = va("%s %s %s %s", YQ2VERSION, ARCH, __DATE__, OSTYPE);
s = va("%s %s %s %s", YQ2VERSION, ARCH, BUILD_DATE, OSTYPE);
Cvar_Get("version", s, CVAR_SERVERINFO | CVAR_NOSET);
if (dedicated->value)

View file

@ -207,7 +207,7 @@ void
InitGame(void)
{
gi.dprintf("Game is starting up.\n");
gi.dprintf("Game is %s built on %s.\n", GAMEVERSION, __DATE__);
gi.dprintf("Game is %s built on %s.\n", GAMEVERSION, BUILD_DATE);
gun_x = gi.cvar("gun_x", "0", 0);
gun_y = gi.cvar("gun_y", "0", 0);
@ -223,7 +223,7 @@ InitGame(void)
/* latched vars */
sv_cheats = gi.cvar("cheats", "0", CVAR_SERVERINFO | CVAR_LATCH);
gi.cvar("gamename", GAMEVERSION, CVAR_SERVERINFO | CVAR_LATCH);
gi.cvar("gamedate", __DATE__, CVAR_SERVERINFO | CVAR_LATCH);
gi.cvar("gamedate", BUILD_DATE, CVAR_SERVERINFO | CVAR_LATCH);
maxclients = gi.cvar("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH);
maxspectators = gi.cvar("maxspectators", "4", CVAR_SERVERINFO);
deathmatch = gi.cvar("deathmatch", "0", CVAR_LATCH);