File 0004-Allow-SOURCE_DATE_EPOCH-to-override-RPMTAG_BUILDTIME.patch of Package rpm

From 686ff4634d69999740c93eea761b09c3fb17c2f6 Mon Sep 17 00:00:00 2001
From: Nicolas Vigier <boklm@torproject.org>
Date: Thu, 3 Dec 2015 12:57:22 +0100
Subject: [PATCH 4/4] Allow SOURCE_DATE_EPOCH to override RPMTAG_BUILDTIME

SOURCE_DATE_EPOCH environment variable is a distribution-agnostic
standard for build systems to exchange a timestamp.

SOURCE_DATE_EPOCH specification is available at:
https://reproducible-builds.org/specs/source-date-epoch

Signed-off-by: Dhiru Kholia <dhiru@openwall.com>
(cherry picked from commit b8a54d6a1e9bb6140b6b47e23dc707e4b967537e)
---
 build/pack.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git build/pack.c build/pack.c
index 094419e..8305b42 100644
--- build/pack.c
+++ build/pack.c
@@ -154,9 +154,23 @@ exit:
 static rpm_time_t * getBuildTime(void)
 {
     static rpm_time_t buildTime[1];
+    char *srcdate;
+    time_t epoch;
+    char *endptr;
+
+    if (buildTime[0] == 0) {
+        srcdate = getenv("SOURCE_DATE_EPOCH");
+        if (srcdate) {
+            errno = 0;
+            epoch = strtol(srcdate, &endptr, 10);
+            if (srcdate == endptr || *endptr || errno != 0)
+                rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n"));
+            else
+                buildTime[0] = (int32_t) epoch;
+        } else
+            buildTime[0] = (int32_t) time(NULL);
+    }
 
-    if (buildTime[0] == 0)
-	buildTime[0] = (int32_t) time(NULL);
     return buildTime;
 }
 
-- 
2.10.2