]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Add git version handling to build system
authorTravis Cross <tc@traviscross.com>
Sat, 9 Feb 2013 08:16:48 +0000 (08:16 +0000)
committerTravis Cross <tc@traviscross.com>
Sat, 9 Feb 2013 09:07:51 +0000 (09:07 +0000)
When building from a git tree, the version number built into the
binary will be appended with +git-XXXXXXXX.

The base version number is stored in-tree in configure.in and is that
of the last tagged release.  Presumably the git version is later than
the last tag, so we use '+git' rather than '-git' to produce the
correct the lexical sort order -- though of course the sort order
between any two git revisions can only be determined from the git tree
rather than from a lexical sort.

.gitignore
Makefile.am
configure.in
curses.c
gtk.c
mtr.c
version.h.in [new file with mode: 0644]

index 4cefe3edd63a036b1de895aad85ca200622ec4a5..ec6d2882b4ca3a022ec820e1fb2de0bfbcffd5e4 100644 (file)
@@ -20,4 +20,6 @@ stamp-h1*
 /ChangeLog
 /INSTALL
 /mtr
+/version.h
+/version.h.tmp
 
index 013ef42f2049cda970214508f591dde3301646d2..a42ce3624d56e564f4a7397841161259f60b2c73 100644 (file)
@@ -17,11 +17,24 @@ mtr_SOURCES = mtr.c \
               select.c select.h \
               mtr-curses.h \
               mtr-gtk.h
+nodist_mtr_SOURCES = version.h
 EXTRA_mtr_SOURCES = curses.c \
                     gtk.c
 mtr_DEPENDENCIES = $(GTK_OBJ) $(CURSES_OBJ)
 mtr_LDFLAGS = $(GTK_OBJ) $(CURSES_OBJ)
 
+CLEANFILES = version.h
+BUILT_SOURCES = version.h
+
+version.h: version.h.tmp Makefile $(mtr_SOURCES)
+       @cat $< > $@; \
+       if [ -d .git ] && [ -n "$$(which git)" ]; then \
+         xver="+git-$$(git rev-list -n1 --abbrev=8 --abbrev-commit HEAD)"; \
+         sed \
+           -e "/#define *MTR_VERSION */{s/\"\([^\"]*\)\"/\"\1$$xver\"/;}" \
+           $< > $@; \
+       fi;
+
 EXTRA_DIST = SECURITY mtr.8 Makefile Makefile.dist
 distclean-local:
        (sleep 3; cp Makefile.dist Makefile) &
index 4b81c444ae80beb6cf6f81c820ce88f22867d823..43eed03007a5cdae92f229283f8ff866d59f67a0 100644 (file)
@@ -1,6 +1,7 @@
 AC_INIT(mtr.c)
 AM_INIT_AUTOMAKE(mtr, 0.83)
 
+AC_CONFIG_FILES([version.h.tmp:version.h.in])
 
 AC_SUBST(GTK_OBJ)
 AC_SUBST(CURSES_OBJ)
index 0652e874bb9df5add3e5057055ee11f14d372473..5d6c483132ee38992163f2894d4b15721e1b6053 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -64,6 +64,7 @@
 #include "net.h"
 #include "dns.h"
 #include "asn.h"
+#include "version.h"
 #include <glib.h>
 #endif
 
@@ -565,7 +566,7 @@ void mtr_curses_redraw(void)
 
   move(0, 0);
   attron(A_BOLD);
-  pwcenter("My traceroute  [v" VERSION "]");
+  pwcenter("My traceroute  [v" MTR_VERSION "]");
   attroff(A_BOLD);
 
   mvprintw(1, 0, "%s (%s)", LocalHostname, net_localaddr());
diff --git a/gtk.c b/gtk.c
index 5a04b3ee5a4972379aaf1c55d5ccd432e77af3bb..60867cb0a96806cdbd84c608b34e4b4c3a1f758d 100644 (file)
--- a/gtk.c
+++ b/gtk.c
@@ -36,6 +36,7 @@
 #include "net.h"
 #include "dns.h"
 #include "mtr-gtk.h"
+#include "version.h"
 
 #include "img/mtr_icon.xpm"
 #endif
@@ -167,7 +168,7 @@ gint About_clicked(UNUSED GtkWidget *Button, UNUSED gpointer data)
     };
   
   gtk_show_about_dialog(GTK_WINDOW(main_window)
-    , "version", VERSION
+    , "version", MTR_VERSION
     , "copyright", "Copyright \xc2\xa9 1997,1998  Matt Kimball"
     , "website", "http://www.bitwizard.nl/mtr/"
     , "authors", authors
diff --git a/mtr.c b/mtr.c
index 044fac574c215d5b04d9323f5895e754177c6fa8..9246bb1a1f684b039f53e2483ef5b1856db221f0 100644 (file)
--- a/mtr.c
+++ b/mtr.c
@@ -35,6 +35,7 @@
 #include "report.h"
 #include "net.h"
 #include "asn.h"
+#include "version.h"
 
 
 #ifdef ENABLE_IPV6
@@ -387,7 +388,7 @@ int main(int argc, char **argv)
   }
 
   if (PrintVersion) {
-    printf ("mtr " VERSION "\n");
+    printf ("mtr " MTR_VERSION "\n");
     exit(0);
   }
 
diff --git a/version.h.in b/version.h.in
new file mode 100644 (file)
index 0000000..d39e6a4
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+    mtr  --  a network diagnostic tool
+    Copyright (C) 1997,1998  Matt Kimball
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License version 2 as 
+    published by the Free Software Foundation.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#define MTR_VERSION "@VERSION@"
+