Skip to content

Commit

Permalink
Add git version handling to build system
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
traviscross committed Feb 9, 2013
1 parent ec39a1e commit 354c28d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ stamp-h1*
/ChangeLog
/INSTALL
/mtr
/version.h
/version.h.tmp

13 changes: 13 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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) &
Expand Down
1 change: 1 addition & 0 deletions configure.in
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "net.h"
#include "dns.h"
#include "asn.h"
#include "version.h"
#include <glib.h>
#endif

Expand Down Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "net.h"
#include "dns.h"
#include "mtr-gtk.h"
#include "version.h"

#include "img/mtr_icon.xpm"
#endif
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion mtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "report.h"
#include "net.h"
#include "asn.h"
#include "version.h"


#ifdef ENABLE_IPV6
Expand Down Expand Up @@ -387,7 +388,7 @@ int main(int argc, char **argv)
}

if (PrintVersion) {
printf ("mtr " VERSION "\n");
printf ("mtr " MTR_VERSION "\n");
exit(0);
}

Expand Down
20 changes: 20 additions & 0 deletions version.h.in
Original file line number Diff line number Diff line change
@@ -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@"

0 comments on commit 354c28d

Please sign in to comment.