about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2017-03-18 02:12:42 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2017-03-18 02:12:42 +0000
commita0a2e113c59a01a599cbb91752a5ba344b6f92e8 (patch)
treec7acc253da2d62df6878906665207db366546f91
parent42f622dfcc42fb36828f2b6e9ba1127ca65739dd (diff)
downloadnetpbm-mirror-a0a2e113c59a01a599cbb91752a5ba344b6f92e8.tar.gz
netpbm-mirror-a0a2e113c59a01a599cbb91752a5ba344b6f92e8.tar.xz
netpbm-mirror-a0a2e113c59a01a599cbb91752a5ba344b6f92e8.zip
Use SOURCE_DATE_EPOCH
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2918 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rwxr-xr-xbuildtools/stamp-date19
-rw-r--r--doc/HISTORY6
-rw-r--r--doc/INSTALL29
-rw-r--r--lib/libpm.c46
4 files changed, 91 insertions, 9 deletions
diff --git a/buildtools/stamp-date b/buildtools/stamp-date
index 32839e94..902c82e4 100755
--- a/buildtools/stamp-date
+++ b/buildtools/stamp-date
@@ -8,16 +8,25 @@
 # copyright notice and this permission notice appear in supporting
 # documentation.  This software is provided "as is" without express or
 # implied warranty.
-#
-DATE=$(date)
+
+# SOURCE_DATE_EPOCH is an environment variable as described here:
+# https://reproducible-builds.org/specs/source-date-epoch/ on 2017.03.16.
+
+SOURCE_DATE_OR_NONE=${SOURCE_DATE_EPOCH:-NONE}
+
+BUILD_DATETIME=$(date +%s)
+
 LOGNAME_OR_UNKNOWN=${LOGNAME:-UNKNOWN}
 USER=${USER:-$LOGNAME_OR_UNKNOWN}
 if [ "$USER" = "UNKNOWN" ]; then
-    USER=`whoami`
+    USER=$(whoami)
 fi
 
-echo "/* This file tells the package when it was compiled */"
+echo "/* This file tells some facts about the building of the package */"
 echo "/* DO NOT EDIT - THIS FILE IS MAINTAINED AUTOMATICALLY */"
 echo "/* Created by the program 'stamp-date'  */"
-echo "#define COMPILE_TIME \"$DATE\""
+if [ "$SOURCE_DATE_OR_NONE" != "NONE" ]; then
+  echo "#define SOURCE_DATETIME $SOURCE_DATE_OR_NONE"
+fi
+echo "#define BUILD_DATETIME $BUILD_DATETIME"
 echo "#define COMPILED_BY \"$USER\""
diff --git a/doc/HISTORY b/doc/HISTORY
index 77ddfbd2..b5e853a5 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -13,6 +13,12 @@ not yet  BJH  Release 10.78.00
               pnmtotiff: Fail with -miniswhite or -minisblack on color image
               rather than produce an invalid TIFF.
 
+              --version global option: with SOURCE_DATE_EPOCH environment
+              variable, display source code datetime instead of build
+              datetime.  And when displaying build datetime, do it in the
+              local time of the process running the command instead of the
+              process that did the build.
+
               tifftopnm: Fix memory corruption when image is more pixels than
               can be represented as a C unsigned integer.  Broken in Netpbm
               10.11 (October 2002).
diff --git a/doc/INSTALL b/doc/INSTALL
index f0b3e87b..a71e5179 100644
--- a/doc/INSTALL
+++ b/doc/INSTALL
@@ -109,6 +109,35 @@ If you use the 'configure' program, be sure to edit config.mk _after_ you
 run 'configure', since 'configure' generates config.mk.
 
 
+COMPILED-IN BUILD DATETIME
+--------------------------
+
+By default, the Netpbm build system builds the datetime that you built it
+into libnetpbm, so the --version global command line option can display it.
+It's actually just when you began building from a clean build tree; if you
+modify code and rebuild, the build datetime does not change.
+
+This is problematic for any of various reasons you might want to compare two
+versions of libnetpbm, or anything of which it is part, for equality.  Two
+libnetpbms that are identical except that they were built at different times
+would compare as different.
+
+Furthermore, as version information, the modification datetime of the source
+code is often more useful than the build datetime.
+
+For these reasons, it is possible to change this timestamping behavior by
+setting the environment variable 'SOURCE_DATA_EPOCH'.  That is supposed to be
+the POSIX datetime value (decimal number of seconds since 1969, excluding leap
+seconds) for when the source code was last modified.  When you set this,
+before doing 'make' for the first time in a clean build tree, the resulting
+libnetpbm contains that information and not build datetime information, and
+the --version global option causes a different message.
+
+The name and meaning of the environment variable is taken from a standard
+described at https://reproducible-builds.org/specs/source-date-epoch/ on March
+16, 2017.
+
+
 AUTOMATING THE BUILD
 --------------------
 
diff --git a/lib/libpm.c b/lib/libpm.c
index d5bad7a4..2e2097ec 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -517,13 +517,51 @@ pm_init(const char * const progname,
 
 
 
+static const char *
+dtMsg(time_t const dateTime) {
+/*----------------------------------------------------------------------------
+   Text for the version message to indicate datetime 'dateTime'.
+-----------------------------------------------------------------------------*/
+    struct tm * const brokenTimeP = localtime(&dateTime);
+
+    char buffer[100];
+    
+    strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", brokenTimeP);
+
+    return pm_strdup(buffer);
+}
+
+
+
 static void
 showVersion(void) {
-    pm_message( "Using libnetpbm from Netpbm Version: %s", NETPBM_VERSION );
-#if defined(COMPILE_TIME) && defined(COMPILED_BY)
-    pm_message( "Compiled %s by user \"%s\"",
-                COMPILE_TIME, COMPILED_BY );
+
+    pm_message("Using libnetpbm from Netpbm Version: %s", NETPBM_VERSION);
+
+    /* SOURCE_DATETIME is defined when the user wants a reproducible build,
+       so wants the source code modification datetime instead of the build
+       datetime in the object code.
+    */
+#if defined(SOURCE_DATETIME)
+    {
+        const char * const sourceDtMsg = dtMsg(SOURCE_DATETIME);
+        pm_message("Built from source dated %s", sourceDtMsg);
+        pm_strfree(sourceDtMsg);
+    }
+#else
+  #if defined(BUILD_DATETIME)
+    {
+        const char * const buildDtMsg = dtMsg(BUILD_DATETIME);
+        pm_message("Built at %s", buildDtMsg);
+        pm_strfree(buildDtMsg);
+    }
+  #endif
 #endif
+
+#if defined(COMPILED_BY)
+    pm_message("Built by %s", COMPILED_BY);
+#endif
+
 #ifdef BSD
     pm_message( "BSD defined" );
 #endif /*BSD*/