build: include git info

If enabled with --with-pkg-gitversion on ./configure, this will append
git version strings and branch information at the following places:
 - overall version number: 0.99.21-g0123456
 - login motd and show version: tag information + git id + branches

Sample output:
  Hello, this is Quagga (version 0.99.21-g14b49ad-dirty).
  Copyright 1996-2005 Kunihiro Ishiguro, et al.

  This is a git build of quagga_0_99_21_release-106-g14b49ad-dirty
  Associated branch(es):
	local:master

[v2]: fix build without gitinfo (add "else" branch)
[v2]: fix for repos without any tags (different git describe output)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/configure.ac b/configure.ac
index 9bbe89f..fb6efd7 100755
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,7 @@
 AM_INIT_AUTOMAKE(1.6)
 AM_CONFIG_HEADER(config.h)
 
+AC_PATH_PROG(PERL, perl)
 AC_CHECK_PROG([GAWK],[gawk],[gawk],[not-in-PATH])
 if test "x$GAWK" = "xnot-in-PATH" ; then
 	AC_MSG_ERROR([GNU awk is required for lib/memtype.h made by memtypes.awk.
@@ -192,6 +193,12 @@
 AC_ARG_WITH(pkg-extra-version,
 	AS_HELP_STRING([--with-pkg-extra-version=VER], [add extra version field, for packagers/distributions]),
 	[EXTRAVERSION=$withval],)
+AC_ARG_WITH(pkg-git-version,
+	AS_HELP_STRING([--with-pkg-git-version], [add git information to MOTD and build version string]),
+	[ if test "x$withval" != "xno"; then
+		with_pkg_git_version="1"
+		AC_DEFINE(GIT_VERSION, [1], [include git version info])
+	fi ],)
 AC_ARG_ENABLE(vtysh,
 [  --enable-vtysh          include integrated vty shell for Quagga])
 AC_ARG_ENABLE(ipv6,
@@ -398,11 +405,13 @@
 dnl name, string and version fields.
 dnl -----------------------------------
 if test "x${EXTRAVERSION}" != "x" ; then
-  VERSION=${VERSION}${EXTRAVERSION}
-  PACKAGE_VERSION=${PACKAGE_VERSION}${EXTRAVERSION}
-  PACKAGE_STRING=${PACKAGE_STRING}${EXTRAVERSION}
+  VERSION="${VERSION}${EXTRAVERSION}"
+  PACKAGE_VERSION="${PACKAGE_VERSION}${EXTRAVERSION}"
+  PACKAGE_STRING="${PACKAGE_STRING}${EXTRAVERSION}"
 fi
 
+AM_CONDITIONAL([GIT_VERSION], [test "x$with_pkg_git_version" != "x"])
+
 dnl ------------------------------------
 dnl Check C keywords and standard  types
 dnl ------------------------------------
@@ -611,7 +620,6 @@
 case "${enable_vtysh}" in
   "yes") VTYSH="vtysh";
          AC_DEFINE(VTYSH,,VTY shell)
-	 AC_PATH_PROG(PERL, perl)
 dnl	 Vtysh uses libreadline, which looks for termcap functions at
 dnl	 configure time.  We follow readlines search order.
 dnl	 The required procedures are in libtermcap on NetBSD, in