Add git version handling to build system

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.
This commit is contained in:
Travis Cross 2013-02-09 08:16:48 +00:00
parent ec39a1ed4e
commit 354c28d707
7 changed files with 42 additions and 3 deletions

2
.gitignore vendored
View File

@ -20,4 +20,6 @@ stamp-h1*
/ChangeLog
/INSTALL
/mtr
/version.h
/version.h.tmp

View 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) &

View 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)

View File

@ -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());

3
gtk.c
View File

@ -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

3
mtr.c
View File

@ -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);
}

20
version.h.in Normal file
View File

@ -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@"