1 https://gcc.gnu.org/ml/gcc-patches/2015-06/msg02210.html
3 diff --git a/libcpp/macro.c b/libcpp/macro.c
4 index 1e0a0b5..a52e3cb 100644
7 @@ -349,14 +349,38 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
8 slow on some systems. */
11 + char *source_date_epoch;
13 - /* (time_t) -1 is a legitimate value for "number of seconds
14 - since the Epoch", so we have to do a little dance to
15 - distinguish that from a genuine error. */
18 - if (tt != (time_t)-1 || errno == 0)
19 - tb = localtime (&tt);
20 + /* Allow the date and time to be set externally by an exported
21 + environment variable to enable reproducible builds. */
22 + source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
23 + if (source_date_epoch)
26 + tt = (time_t) strtol (source_date_epoch, NULL, 10);
31 + cpp_error (pfile, CPP_DL_ERROR,
32 + "SOURCE_DATE_EPOCH=\"%s\" is not a valid date",
36 + cpp_error (pfile, CPP_DL_ERROR,
37 + "SOURCE_DATE_EPOCH=\"%s\" is not a valid number",
42 + /* (time_t) -1 is a legitimate value for "number of seconds
43 + since the Epoch", so we have to do a little dance to
44 + distinguish that from a genuine error. */
47 + if (tt != (time_t)-1 || errno == 0)
48 + tb = localtime (&tt);