Description: Make the build reproducible
Author: Chris Lamb <lamby@debian.org>
Last-Update: 2020-05-15
Bug-Debian: https://bugs.debian.org/960667

--- tree-puzzle-5.3~rc16+dfsg.orig/src/puzzle1.c
+++ tree-puzzle-5.3~rc16+dfsg/src/puzzle1.c
@@ -3204,7 +3204,9 @@ void initeps(FILE *ofp)
 		fprintf(ofp, "%%%%Creator: %s (version %s%s)\n", PACKAGE, VERSION, ALPHA);
 #	endif
 	fprintf(ofp, "%%%%Title: Likelihood Mapping Analysis\n");
-	fprintf(ofp, "%%%%CreationDate: %s", asctime(localtime(&Starttime)) );
+	if (getenv("SOURCE_DATE_EPOCH") == NULL) {
+		fprintf(ofp, "%%%%CreationDate: %s", asctime(localtime(&Starttime)) );
+	}
 	fprintf(ofp, "%%%%DocumentFonts: Helvetica\n");
 	fprintf(ofp, "%%%%DocumentNeededFonts: Helvetica\n");
 	fprintf(ofp, "%%%%EndComments\n");
@@ -3826,6 +3828,10 @@ void timestamp(FILE* ofp)
 	timespan = difftime(Stoptime, Starttime);
 	cpuspan  = ((double) (Stopcpu - Startcpu) / CLOCKS_PER_SEC);
 	fprintf(ofp, "\n\nTIME STAMP\n\n");
+	if (getenv("SOURCE_DATE_EPOCH") != NULL) {
+		fprintf(ofp, "Date and time: (reproducible build)");
+		return;
+	}
 	fprintf(ofp, "Date and time: %s", asctime(localtime(&Starttime)) );
 	fprintf(ofp, "Runtime (excl. input) : %.0f seconds (= %.1f minutes = %.1f hours)\n",
 		timespan, timespan/60., timespan/3600.);
@@ -8924,33 +8930,35 @@ fprintf(stderr, "PPP1: %d (%s:%d)\n", PP
 		fprintftimespan(stdout, PStepStoptime, Stoptime, Starttime, "Pstep -> end");
 #	endif /* DEBUG_PRINTTIMES */
 
-	/* runtime message */
-	fprintf(STDOUT,
-		"The parameter estimation took %.2f seconds (= %.2f minutes = %.2f hours)\n",
-			difftime(PEstStoptime, PEstStarttime), difftime(PEstStoptime, PEstStarttime)/60.,
-			difftime(PEstStoptime, PEstStarttime)/3600.);
-	if (puzzlemode == QUARTPUZ && typ_optn == TREERECON_OPTN) {
+	if (getenv("SOURCE_DATE_EPOCH") == NULL) {
+		/* runtime message */
 		fprintf(STDOUT,
-			"The ML step took              %.2f seconds (= %.2f minutes = %.2f hours)\n",
-				difftime(MLstepStoptime, MLstepStarttime), difftime(MLstepStoptime, MLstepStarttime)/60.,
-				difftime(MLstepStoptime, MLstepStarttime)/3600.);
-		fprintf(STDOUT,
-			"The puzzling step took        %.2f seconds (= %.2f minutes = %.2f hours)\n",
-				difftime(PStepStoptime, PStepStarttime), difftime(PStepStoptime, PStepStarttime)/60.,
-				difftime(PStepStoptime, PStepStarttime)/3600.);
-	}
-	fprintf(STDOUT, 
-		"The computation took %.2f seconds (= %.2f minutes = %.2f hours)\n",
-			difftime(Stoptime, Starttime), difftime(Stoptime, Starttime)/60.,
-			difftime(Stoptime, Starttime)/3600.);
-	fprintf(STDOUT, 
-		"     including input %.2f seconds (= %.2f minutes = %.2f hours)\n",
-			fulltime, fulltime/60., fulltime/3600.);
+			"The parameter estimation took %.2f seconds (= %.2f minutes = %.2f hours)\n",
+				difftime(PEstStoptime, PEstStarttime), difftime(PEstStoptime, PEstStarttime)/60.,
+				difftime(PEstStoptime, PEstStarttime)/3600.);
+		if (puzzlemode == QUARTPUZ && typ_optn == TREERECON_OPTN) {
+			fprintf(STDOUT,
+				"The ML step took              %.2f seconds (= %.2f minutes = %.2f hours)\n",
+					difftime(MLstepStoptime, MLstepStarttime), difftime(MLstepStoptime, MLstepStarttime)/60.,
+					difftime(MLstepStoptime, MLstepStarttime)/3600.);
+			fprintf(STDOUT,
+				"The puzzling step took        %.2f seconds (= %.2f minutes = %.2f hours)\n",
+					difftime(PStepStoptime, PStepStarttime), difftime(PStepStoptime, PStepStarttime)/60.,
+					difftime(PStepStoptime, PStepStarttime)/3600.);
+		}
+		fprintf(STDOUT, 
+			"The computation took %.2f seconds (= %.2f minutes = %.2f hours)\n",
+				difftime(Stoptime, Starttime), difftime(Stoptime, Starttime)/60.,
+				difftime(Stoptime, Starttime)/3600.);
+		fprintf(STDOUT, 
+			"     including input %.2f seconds (= %.2f minutes = %.2f hours)\n",
+				fulltime, fulltime/60., fulltime/3600.);
 #ifdef TIMEDEBUG
-	fprintf(STDOUT, 
-		"and %.0f seconds CPU time (= %.2f minutes = %.2f hours)\n\n",
-			fullcpu, fullcpu/60., fullcpu/3600.);
+		fprintf(STDOUT, 
+			"and %.0f seconds CPU time (= %.2f minutes = %.2f hours)\n\n",
+				fullcpu, fullcpu/60., fullcpu/3600.);
 #endif /* TIMEDEBUG */
+	}
 
 	/* free memory */
 	memcleanup();
