Add a new configure flag, --enable-git-version, that allows the output of
'git describe' to be used in the version string associated with this
package. This could aid in debugging for users that are using a development
version of pacman and we should be able to figure out which cut of code they
are using.

Sample output:
$ pacman --version
Pacman v3.1.4-190-g4cfa-dirty - libalpm v2.3.1

$ makepkg --version
makepkg (pacman) 3.1.4-190-g5861-dirty

Signed-off-by: Dan McGee <[EMAIL PROTECTED]>
---
 configure.ac           |   47 ++++++++++++++++++++++++++++++++---------------
 scripts/Makefile.am    |    9 ++++++++-
 src/pacman/Makefile.am |    5 +++++
 src/pacman/pacman.c    |    6 ++++++
 4 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac
index 27efd17..ab5a374 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,28 +40,19 @@ AC_PREREQ(2.60)
 #
 #   Bugfix releases:
 #     pacman_version_micro += 1
-#
-#   pacman_version_suffix should be similar to one of the following:
-#     For beta releases:          [beta2]
-#     For code under development: [devel]
-#     For production releases:    []
 
 m4_define([lib_current], [5])
 m4_define([lib_revision], [1])
 m4_define([lib_age], [3])
 
 m4_define([pacman_version_major], [3])
-m4_define([pacman_version_minor], [2])
-m4_define([pacman_version_micro], [0])
-m4_define([pacman_version_suffix], [devel])
+m4_define([pacman_version_minor], [1])
+m4_define([pacman_version_micro], [4])
 m4_define([pacman_version],
           [pacman_version_major.pacman_version_minor.pacman_version_micro])
-m4_define([pacman_display_version],
-                                       
pacman_version[]m4_ifdef([pacman_version_suffix],[pacman_version_suffix]))
 
 # Autoconf initialization
-AC_INIT([Pacman Package Manager], [pacman_display_version],
-        [EMAIL PROTECTED], [pacman])
+AC_INIT([pacman], [pacman_version], [EMAIL PROTECTED])
 AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADERS([config.h])
 
@@ -122,6 +113,12 @@ AC_ARG_ENABLE(debug,
        AS_HELP_STRING([--enable-debug], [enable debugging support]),
        [debug=$enableval], [debug=no])
 
+# Help line for using git version in pacman version string
+AC_ARG_ENABLE(git-version,
+       AS_HELP_STRING([--enable-git-version],
+               [enable use of git version in version string if available]),
+       [wantgitver=$enableval], [wantgitver=no])
+
 # Help line for pacman.static
 AC_ARG_ENABLE(pacman-static,
        AS_HELP_STRING([--disable-pacman-static], [do not build static version 
of pacman]),
@@ -259,9 +256,9 @@ fi
 AM_CONDITIONAL(WANT_DOC, test "x$wantdoc" = "xyes")
 
 # Check for doxygen support and status
+AC_CHECK_PROGS([DOXYGEN], [doxygen])
 AC_MSG_CHECKING([for doxygen])
 if test "x$wantdoxygen" = "xyes" ; then
-       AC_CHECK_PROGS([DOXYGEN], [doxygen])
        if test $DOXYGEN ; then
                AC_MSG_RESULT([yes])
                usedoxygen=yes
@@ -276,9 +273,9 @@ fi
 AM_CONDITIONAL(USE_DOXYGEN, test "x$usedoxygen" = "xyes")
 
 # Check for asciidoc support and status
+AC_CHECK_PROGS([ASCIIDOC], [asciidoc])
 AC_MSG_CHECKING([for asciidoc])
 if test "x$wantasciidoc" = "xyes" ; then
-       AC_CHECK_PROGS([ASCIIDOC], [asciidoc])
        if test $ASCIIDOC ; then
                AC_MSG_RESULT([yes])
                useasciidoc=yes
@@ -308,6 +305,25 @@ else
        CFLAGS="$CFLAGS -Wall"
 fi
 
+# Enable or disable use of git version in pacman version string
+AC_CHECK_PROGS([GIT], [git])
+AC_CHECK_FILE([.git/], hasgitdir=yes)
+AC_MSG_CHECKING(whether to use git version if available)
+if test "x$wantgitver" = "xyes" ; then
+       if test $GIT -a "x$hasgitdir" = "xyes"; then
+               AC_MSG_RESULT([yes])
+               usegitver=yes
+               AC_DEFINE([USE_GIT_VERSION], , [Use GIT version in version 
string])
+       else
+               AC_MSG_RESULT([no, git or .git dir missing])
+               usegitver=no
+       fi
+else
+       AC_MSG_RESULT([no, disabled by configure])
+       usegitver=no
+fi
+AM_CONDITIONAL(USE_GIT_VERSION, test "x$usegitver" = "xyes")
+
 # Enable or disable inclusion of pacman.static
 AC_MSG_CHECKING(whether to build pacman.static)
 if test "x$pacmanstatic" = "xyes" ; then
@@ -347,7 +363,7 @@ Makefile
 AC_OUTPUT
 
 echo "
-pacman_display_version:
+${PACKAGE_NAME}:
 
   Build information:
     source code location   : ${srcdir}
@@ -368,6 +384,7 @@ pacman_display_version:
     libalpm version        : ${LIB_VERSION}
     libalpm version info   : ${LIB_VERSION_INFO}
     pacman version         : ${PACKAGE_VERSION}
+    using git version      : ${usegitver}
 
   Directory and file information:
     root working directory : ${ROOTDIR}
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 3185a47..e6c051b 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -18,13 +18,20 @@ EXTRA_DIST = \
 # Files that should be removed, but which Automake does not know.
 MOSTLYCLEANFILES = $(bin_SCRIPTS) *.tmp
 
+if USE_GIT_VERSION
+GIT_VERSION := $(shell sh -c 'git describe --abbrev=4 | sed s/^v//')-dirty
+REAL_PACKAGE_VERSION = $(GIT_VERSION)
+else
+REAL_PACKAGE_VERSION = $(PACKAGE_VERSION)
+endif
+
 #### Taken from the autoconf scripts Makefile.am ####
 edit = sed \
        -e 's|@[EMAIL PROTECTED]|$(localedir)|g' \
        -e 's|@[EMAIL PROTECTED]|$(sysconfdir)|g' \
        -e 's|@[EMAIL PROTECTED]|$(localstatedir)|g' \
        -e 's|@[EMAIL PROTECTED]|$(prefix)|g' \
-       -e 's|@[EMAIL PROTECTED]|$(PACKAGE_VERSION)|g' \
+       -e 's|@[EMAIL PROTECTED]|$(REAL_PACKAGE_VERSION)|g' \
        -e 's|@[EMAIL PROTECTED]|$(PACKAGE_BUGREPORT)|g' \
        -e 's|@[EMAIL PROTECTED]|$(PACKAGE_NAME)|g' \
        -e 's|@[EMAIL PROTECTED]|$(DBEXT)|g' \
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index 5d6fef3..e5f8cb3 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -21,6 +21,11 @@ INCLUDES = -I$(top_srcdir)/lib/libalpm
 
 AM_CFLAGS = -pedantic -D_GNU_SOURCE
 
+if USE_GIT_VERSION
+GIT_VERSION := $(shell sh -c 'git describe --abbrev=4 | sed s/^v//')-dirty
+DEFS += -DGIT_VERSION=\"$(GIT_VERSION)\"
+endif
+
 pacman_SOURCES = \
        conf.h conf.c \
        deptest.c \
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 66fafa1..0ce9c1e 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -19,6 +19,12 @@
 
 #include "config.h"
 
+/* special handling of package version for GIT */
+#if defined(GIT_VERSION)
+#undef PACKAGE_VERSION
+#define PACKAGE_VERSION GIT_VERSION
+#endif
+
 #include <stdlib.h> /* atoi */
 #include <stdio.h>
 #include <limits.h>
-- 
1.5.5.3


_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev

Reply via email to