From b79d3e0f07495b4a113f1ad95ae08c19664ea5ac Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Sun, 23 Apr 2017 12:49:40 -0400 Subject: [PATCH] Add support for SOURCE_DATE_EPOCH environment variable (Issue #193) --- CHANGES.md | 2 ++ doc/mxml.man | 2 +- mxmldoc.c | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d82b4d1..9d6c3de 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ (Issue #184) - The configure script now properly supports cross-compilation (Issue #188) - The mxmldoc utility now supports generation of EPUB files (Issue #189) +- The mxmldoc utility now supports the `SOURCE_DATE_EPOCH` environment + variable for reproducible builds (Issue #193) - The mxmldoc utility now supports Markdown (Issue #194) diff --git a/doc/mxml.man b/doc/mxml.man index d523307..6bcd2c0 100644 --- a/doc/mxml.man +++ b/doc/mxml.man @@ -1,4 +1,4 @@ -.TH mxml 3 "Mini-XML API" "04/21/17" "Mini-XML API" +.TH mxml 3 "Mini-XML API" "04/23/17" "Mini-XML API" .SH NAME mxml \- Mini-XML API .SH INCLUDE FILE diff --git a/mxmldoc.c b/mxmldoc.c index 7f475ef..4abe707 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -5604,6 +5604,7 @@ write_man(const char *man_name, /* I - Name of manpage */ *parent; /* Parent class */ int inscope; /* Variable/method scope */ char prefix; /* Prefix character */ + const char *source_date_epoch; /* SOURCE_DATE_EPOCH environment variable */ time_t curtime; /* Current time */ struct tm *curdate; /* Current date */ char buffer[1024]; /* String buffer */ @@ -5617,9 +5618,15 @@ write_man(const char *man_name, /* I - Name of manpage */ /* * Standard man page... + * + * Get the current date, using the SOURCE_DATE_EPOCH environment variable, if + * present, for the number of seconds since the epoch - this enables + * reproducible builds (Issue #193). */ - curtime = time(NULL); + if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL || (curtime = (time_t)strtol(source_date_epoch, NULL, 10)) <= 0) + curtime = time(NULL); + curdate = localtime(&curtime); strftime(buffer, sizeof(buffer), "%x", curdate);