Skip to content

Commit

Permalink
q3rcc: Allow to override build date
Browse files Browse the repository at this point in the history
Allow to override __DATE__ and __TIME__ with SOURCE_DATE_EPOCH
in order 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 behavior is what gcc already does.
  • Loading branch information
bmwiedemann authored and timangus committed Jul 11, 2019
1 parent 350b8f9 commit a96f32e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion code/tools/lcc/cpp/cpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ int ifdepth;
int ifsatisfied[NIF];
int skipping;

time_t reproducible_time()
{
char *source_date_epoch;
time_t t;
if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
(t = (time_t)strtol(source_date_epoch, NULL, 10)) <= 0)
return time(NULL);
return t;
}

int
main(int argc, char **argv)
Expand All @@ -28,7 +37,7 @@ main(int argc, char **argv)
char ebuf[BUFSIZ];

setbuf(stderr, ebuf);
t = time(NULL);
t = reproducible_time();
curtime = ctime(&t);
maketokenrow(3, &tr);
expandlex();
Expand Down

0 comments on commit a96f32e

Please sign in to comment.