Support SOURCE_DATE_EPOCH for reproducible builds

See https://reproducible-builds.org/docs/source-date-epoch/

Fixes #286
This commit is contained in:
Rangi
2020-12-16 11:08:18 -05:00
committed by Eldred Habert
parent 063a22ddf9
commit ad6f17cd93
4 changed files with 21 additions and 6 deletions

View File

@@ -218,7 +218,7 @@ static char *make_escape(const char *str)
}
/* Short options */
static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
static const char *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
/* Variables for the long-only options */
static int depType; /* Variants of `-M` */
@@ -283,6 +283,16 @@ int main(int argc, char *argv[])
char *tzMainfile;
time_t now = time(NULL);
char *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
/*
* Support SOURCE_DATE_EPOCH for reproducible builds
* https://reproducible-builds.org/docs/source-date-epoch/
*/
if (sourceDateEpoch)
now = (time_t)strtoul(sourceDateEpoch, NULL, 0);
dependfile = NULL;
/* Initial number of allocated elements in array */
@@ -481,7 +491,7 @@ int main(int argc, char *argv[])
nTotalLines = 0;
nIFDepth = 0;
sym_Init();
sym_Init(now);
sym_SetExportAll(exportall);
opt_ParseDefines();