Source: gretl
Version: 2016b-3
Severity: wishlist
Tags: patch
User: reproducible-bui...@lists.alioth.debian.org
Usertags: timestamps
X-Debbugs-Cc: reproducible-bui...@lists.alioth.debian.org

Hi,

Whilst working on the "reproducible builds" effort [0], we
noticed that gretl could not be built reproducibly.

Patch attached. It can probably be sent upstream.

 [0] https://wiki.debian.org/ReproducibleBuilds


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
--- a/debian/patches/reproducible_build.patch   1970-01-01 02:00:00.000000000 
+0200
--- b/debian/patches/reproducible_build.patch   2016-07-13 23:08:07.738744702 
+0200
@@ -0,0 +1,43 @@
+--- gretl-2016b.orig/builddate.c
++++ gretl-2016b/builddate.c
+@@ -2,11 +2,40 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <time.h>
++#include <errno.h>
++#include <limits.h>
+ 
+ void current_ymd (int *y, int *m, int *d)
+ {
+     time_t t = time(NULL);
+     struct tm *lt = localtime(&t);
++    char *endptr;
++    char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
++    unsigned long long epoch;
++
++    if (source_date_epoch) {
++        errno = 0;
++        epoch = strtoull(source_date_epoch, &endptr, 10);
++        if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
++                || (errno != 0 && epoch == 0)) {
++            fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: 
strtoull: %s\n", strerror(errno));
++            exit(EXIT_FAILURE);
++        }
++        if (endptr == source_date_epoch) {
++            fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: No 
digits were found: %s\n", endptr);
++            exit(EXIT_FAILURE);
++        }
++        if (*endptr != '\0') {
++            fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: 
Trailing garbage: %s\n", endptr);
++            exit(EXIT_FAILURE);
++        }
++        if (epoch > ULONG_MAX) {
++            fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: value 
must be smaller than or equal to: %lu but was found to be: %llu \n", ULONG_MAX, 
epoch);
++            exit(EXIT_FAILURE);
++        }
++        t = epoch;
++        lt = gmtime(&t);
++    }
+ 
+     *y = lt->tm_year + 1900;
+     *m = lt->tm_mon + 1;
--- a/debian/patches/series     1970-01-01 02:00:00.000000000 +0200
--- b/debian/patches/series     2016-07-13 23:08:04.154727493 +0200
@@ -0,0 +1 @@
+reproducible_build.patch

Reply via email to