From def566fbfa1c1a5dfe02a074efc54a7bc99d50b4 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 19 Jul 2018 12:31:26 -0700
Subject: [PROPOSED] Append backlinks, dataform to tzdata.zi version

Problem reported privately by Lester Caine.
* Makefile (tzdata.zi): Pass backlinks, dataform to zishrink.awk.
* NEWS: Mention this.
* zishrink.awk (BEGIN): Append this info to version comment.
---
 Makefile     | 10 ++++++++--
 NEWS         |  6 ++++++
 zishrink.awk | 15 +++++++++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 94b6423..272e4cc 100644
--- a/Makefile
+++ b/Makefile
@@ -571,14 +571,20 @@ version:	$(VERSION_DEPS)
 		printf '%s\n' "$$V" >$@.out
 		mv $@.out $@
 
-# These files can be tailored by setting BACKWARD, PACKRATDATA, etc.
+# These files can be tailored by setting BACKWARD and PACKRATDATA.
 vanguard.zi main.zi rearguard.zi: $(DSTDATA_ZI_DEPS)
 		$(AWK) -v DATAFORM=`expr $@ : '\(.*\).zi'` -f ziguard.awk \
 		  $(TDATA) $(PACKRATDATA) >$@.out
 		mv $@.out $@
+# This file has a version comment that attempts to capture any tailoring
+# via BACKWARD, DATAFORM, and PACKRATDATA.
 tzdata.zi:	$(DATAFORM).zi version
 		version=`sed 1q version` && \
-		  LC_ALL=C $(AWK) -v version="$$version" -f zishrink.awk \
+		  LC_ALL=C $(AWK) \
+		    -v backlinks='$(BACKWARD) $(PACKRATDATA)' \
+		    -v dataform='$(DATAFORM)' \
+		    -v version="$$version" \
+		    -f zishrink.awk \
 		    $(DATAFORM).zi >$@.out
 		mv $@.out $@
 
diff --git a/NEWS b/NEWS
index 4afc21f..bdf3cfe 100644
--- a/NEWS
+++ b/NEWS
@@ -92,6 +92,12 @@ Unreleased, experimental changes
     tzdata.zi is now more stable from release to release.  (Problem
     noted by Tom Lane.)  It is also a bit shorter.
 
+    tzdata.zi's version comment now contains information about which
+    data format was selected, and whether backward, backzone and
+    pacificnew were used.  (Problem noted by Lester Caine.)  If the
+    Makefile defaults were used, no information is appended to the
+    version comment, for backward compatibility.
+
 
 Release 2018e - 2018-05-01 23:42:51 -0700
 
diff --git a/zishrink.awk b/zishrink.awk
index e3b4504..1cc4c9d 100644
--- a/zishrink.awk
+++ b/zishrink.awk
@@ -267,6 +267,21 @@ function output_saved_lines(i)
 }
 
 BEGIN {
+  if (dataform != "main") {
+    version = version "," dataform
+  }
+  not_backward = ",!backward"
+  nback = split(backlinks, back)
+  for (i = 1; i <= nback; i++) {
+    if (back[i] != "-") {
+      if (back[i] == "backward") {
+	not_backward = ""
+      } else {
+	version = version "," back[i]
+      }
+    }
+  }
+  version = version not_backward
   print "# version", version
   print "# This zic input file is in the public domain."
   prehash_rule_names()
-- 
2.7.4

