build: keep --version strictly up to date
authorJim Meyering <meyering@redhat.com>
Wed, 7 Apr 2010 06:52:09 +0000 (08:52 +0200)
committerJim Meyering <meyering@redhat.com>
Wed, 7 Apr 2010 07:22:31 +0000 (09:22 +0200)
Before this change, in development, gzip's --version output could lag
behind reality by a couple deltas or by a "-dirty" suffix.  That would
lead to spurious failure of the new --version-$VERSION PATH cross-check.
* Makefile.am (version.c, version.h): New rules.
(BUILT_SOURCES): Set/append.
(noinst_LIBRARIES, noinst_libver_a_SOURCES): Define.
(gzip_LDADD): Add libver.a.
(DISTCLEANFILES): Define.
* gzip.c (license): Use Version, not VERSION.

Makefile.am
gzip.c

index 129c45321c8ced9616598a80e9d73447699c62d6..f9db12bba8907292088911a45672ac73171ea92e 100644 (file)
@@ -18,6 +18,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 ALL_RECURSIVE_TARGETS =
+BUILT_SOURCES =
 
 SUBDIRS = lib doc . tests
 ACLOCAL_AMFLAGS = -I m4
@@ -27,6 +28,10 @@ AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 # Tell the linker to omit references to unused shared libraries.
 AM_LDFLAGS = $(IGNORE_UNUSED_LIBRARIES_CFLAGS)
 
+noinst_LIBRARIES = libver.a
+nodist_libver_a_SOURCES = version.c version.h
+DISTCLEANFILES = version.c version.h
+
 man_MANS = gunzip.1 gzexe.1 gzip.1 \
   zcat.1 zcmp.1 zdiff.1 zforce.1 zgrep.1 zless.1 zmore.1 znew.1
 
@@ -53,9 +58,24 @@ bin_SCRIPTS = gunzip gzexe zcat zcmp zdiff \
 gzip_SOURCES = \
   bits.c crypt.c deflate.c gzip.c inflate.c lzw.c \
   trees.c unlzh.c unlzw.c unpack.c unzip.c util.c zip.c
-gzip_LDADD = lib/libgzip.a
+gzip_LDADD = libver.a lib/libgzip.a
 gzip_LDADD += $(LIB_CLOCK_GETTIME)
 
+BUILT_SOURCES += version.c
+version.c: Makefile
+       $(AM_V_GEN)rm -f $@
+       $(AM_V_at)printf '#include <config.h>\n' > $@t
+       $(AM_V_at)printf 'char const *Version = "$(PACKAGE_VERSION)";\n' >> $@t
+       $(AM_V_at)chmod a-w $@t
+       $(AM_V_at)mv $@t $@
+
+BUILT_SOURCES += version.h
+version.h: Makefile
+       $(AM_V_GEN)rm -f $@
+       $(AM_V_at)printf 'extern char const *Version;\n' > $@t
+       $(AM_V_at)chmod a-w $@t
+       $(AM_V_at)mv $@t $@
+
 gzip.doc: gzip.1
        $(AM_V_GEN)groff -man -Tascii $(srcdir)/gzip.1 | col -b | uniq > $@-t \
          && mv $@-t $@
diff --git a/gzip.c b/gzip.c
index 41322ec5104d88a76217d393bd40aa69d51868d6..4762e88a17f9660ea76a7d4ed85015d806f98344 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -73,6 +73,7 @@ static char const *const license_msg[] = {
 #include "getopt.h"
 #include "ignore-value.h"
 #include "stat-time.h"
+#include "version.h"
 
                 /* configuration */
 
@@ -383,7 +384,7 @@ local void license()
 {
     char const *const *p = license_msg;
 
-    printf ("%s %s\n", program_name, VERSION);
+    printf ("%s %s\n", program_name, Version);
     while (*p) printf ("%s\n", *p++);
 }