Add release versioning support.

Base version string on 'git describe --long', and provide cpp
macros in jemalloc.h.

Add the version mallctl.
diff --git a/.gitignore b/.gitignore
index 35acc25..13b2f96 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@
 /jemalloc/src/jemalloc\.h
 /jemalloc/src/jemalloc_defs\.h
 /jemalloc/src/*.[od]
+/jemalloc/VERSION
diff --git a/jemalloc/Makefile.in b/jemalloc/Makefile.in
index 788fedc..96f1e74 100644
--- a/jemalloc/Makefile.in
+++ b/jemalloc/Makefile.in
@@ -100,6 +100,7 @@
 relclean: distclean
 	rm -rf @objroot@autom4te.cache
 	rm -f @objroot@configure
+	rm -f @srcroot@VERSION
 
 #===============================================================================
 # Re-configuration rules.
diff --git a/jemalloc/VERSION b/jemalloc/VERSION
deleted file mode 100644
index 77d6f4c..0000000
--- a/jemalloc/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.0.0
diff --git a/jemalloc/configure.ac b/jemalloc/configure.ac
index 918be8b..4d2d66a 100644
--- a/jemalloc/configure.ac
+++ b/jemalloc/configure.ac
@@ -563,9 +563,23 @@
 dnl ============================================================================
 dnl jemalloc configuration.
 dnl 
+
+dnl Set VERSION if source directory has an embedded git repository.
+if test -d "${srcroot}../.git" ; then
+  git describe --long > ${srcroot}VERSION
+fi
 jemalloc_version=`cat ${srcroot}VERSION`
-AC_DEFINE_UNQUOTED([JEMALLOC_VERSION], ["$jemalloc_version"])
+jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
+jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
+jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
+jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
+jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
 AC_SUBST([jemalloc_version])
+AC_SUBST([jemalloc_version_major])
+AC_SUBST([jemalloc_version_minor])
+AC_SUBST([jemalloc_version_bugfix])
+AC_SUBST([jemalloc_version_nrev])
+AC_SUBST([jemalloc_version_gid])
 
 dnl ============================================================================
 dnl Configure pthreads.
diff --git a/jemalloc/doc/jemalloc.3.in b/jemalloc/doc/jemalloc.3.in
index 306b569..fca1106 100644
--- a/jemalloc/doc/jemalloc.3.in
+++ b/jemalloc/doc/jemalloc.3.in
@@ -640,6 +640,11 @@
 @roff_stats@can be used to access the summation of statistics from all arenas.
 .Bl -ohang
 .\"-----------------------------------------------------------------------------
+.It Sy "version (const char *) r-"
+.Bd -ragged -offset indent -compact
+Return the jemalloc version string.
+.Ed
+.\"-----------------------------------------------------------------------------
 .It Sy "epoch (uint64_t) rw"
 .Bd -ragged -offset indent -compact
 If a value is passed in, refresh the data from which the
diff --git a/jemalloc/include/jemalloc/jemalloc.h.in b/jemalloc/include/jemalloc/jemalloc.h.in
index baa8459..537d766 100644
--- a/jemalloc/include/jemalloc/jemalloc.h.in
+++ b/jemalloc/include/jemalloc/jemalloc.h.in
@@ -4,6 +4,13 @@
 extern "C" {
 #endif
 
+#define	JEMALLOC_VERSION "@jemalloc_version@"
+#define	JEMALLOC_VERSION_MAJOR @jemalloc_version_major@
+#define	JEMALLOC_VERSION_MINOR @jemalloc_version_minor@
+#define	JEMALLOC_VERSION_BUGFIX @jemalloc_version_bugfix@
+#define	JEMALLOC_VERSION_NREV @jemalloc_version_nrev@
+#define	JEMALLOC_VERSION_GID "@jemalloc_version_gid@"
+
 #include "jemalloc_defs@install_suffix@.h"
 #ifndef JEMALLOC_P
 #  define JEMALLOC_P(s) s
diff --git a/jemalloc/src/ctl.c b/jemalloc/src/ctl.c
index aa7e53d..33ddbb5 100644
--- a/jemalloc/src/ctl.c
+++ b/jemalloc/src/ctl.c
@@ -30,6 +30,7 @@
 static int	ctl_lookup(const char *name, ctl_node_t const **nodesp,
     size_t *mibp, size_t *depthp);
 
+CTL_PROTO(version)
 CTL_PROTO(epoch)
 #ifdef JEMALLOC_TCACHE
 CTL_PROTO(tcache_flush)
@@ -426,6 +427,7 @@
 #endif
 
 static const ctl_node_t	root_node[] = {
+	{NAME("version"),	CTL(version)},
 	{NAME("epoch"),		CTL(epoch)},
 #ifdef JEMALLOC_TCACHE
 	{NAME("tcache"),	CHILD(tcache)},
@@ -916,6 +918,8 @@
 	return (ret);							\
 }
 
+CTL_RO_GEN(version, JEMALLOC_VERSION, const char *)
+
 static int
 epoch_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
     void *newp, size_t newlen)