9d10c9d
From 216934c3f4884999206715db3499fc0162e1d65c Mon Sep 17 00:00:00 2001
9d10c9d
From: ellie timoney <ellie@fastmail.com>
9d10c9d
Date: Tue, 30 May 2017 17:52:04 +1000
9d10c9d
Subject: [PATCH] build: preserve release version across autoreconf
9d10c9d
9d10c9d
Administrators building from a release tarball can safely run
9d10c9d
autoreconf without the source tree forgetting its version (or
9d10c9d
worse, scavenging an unrelated version string from some git
9d10c9d
repository in an ancestor directory).
9d10c9d
---
9d10c9d
 Makefile.am          | 6 +++++-
9d10c9d
 tools/git-version.sh | 4 ++++
9d10c9d
 3 files changed, 10 insertions(+), 1 deletion(-)
9d10c9d
9d10c9d
diff --git a/Makefile.am b/Makefile.am
9d10c9d
index 9a4fa49be..e37822aac 100644
9d10c9d
--- a/Makefile.am
9d10c9d
+++ b/Makefile.am
9d10c9d
@@ -116,7 +116,8 @@ noinst_HEADERS =
9d10c9d
 noinst_LTLIBRARIES =
9d10c9d
 noinst_PROGRAMS =
9d10c9d
 EXTRA_DIST = \
9d10c9d
-	$(wildcard tools/vzic/*)
9d10c9d
+	$(wildcard tools/vzic/*) \
9d10c9d
+	VERSION
9d10c9d
 
9d10c9d
 if COM_ERR
9d10c9d
 COMPILE_ET_DEP = com_err/et/compile_et
9d10c9d
@@ -1910,6 +1911,9 @@ dist-hook:
9d10c9d
 	find $(top_distdir) -type f -name .sphinx-build.stamp -delete
9d10c9d
 	rm -rf $(top_distdir)/$(SPHINX_CACHE)
9d10c9d
 
9d10c9d
+VERSION: tools/git-version.sh
9d10c9d
+	$(AM_V_GEN)$< > $@.NEW && mv $@.NEW $@
9d10c9d
+
9d10c9d
 install-data-hook:
9d10c9d
 if CMULOCAL
9d10c9d
 	$(INSTALL) -m 644 $(top_srcdir)/depot/depot.conf $(DESTDIR)/
9d10c9d
diff --git a/tools/git-version.sh b/tools/git-version.sh
9d10c9d
index 66563c162..c728769db 100755
9d10c9d
--- a/tools/git-version.sh
9d10c9d
+++ b/tools/git-version.sh
9d10c9d
@@ -41,6 +41,10 @@
9d10c9d
 # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
9d10c9d
 #
9d10c9d
 
9d10c9d
+# if we've come from a release package, ignore git entirely
9d10c9d
+test -s VERSION &&
9d10c9d
+    exec head -1 VERSION
9d10c9d
+
9d10c9d
 # first try: based on annotated git tags (real releases)
9d10c9d
 version=$(git describe --dirty=-dirty 2>/dev/null)
9d10c9d
 test -n "$version" &&