Hello there,

Proposed below is a patch to remove the redundant instance of the
version algorithm, together with some cleanup (for unification of
the two algorithms, which have diverged a little) and a micro bit
more efficiency.

One could add a rebuilding rule to config/Makefile.am, if you think it's
useful, just as Automake adds them for 'configure' and Makefiles.

If you apply this, you should add config/ompi_get_version.m4sh to svn,
and remove config/ompi_get_version.sh, as it's now a generated file.
The latter should still be distributed so users don't need autom4te
(done in patch below).

In case ompi_get_version.sh may be used in other configure.ac files than
the toplevel one, the script should be generated before autoconf is run
there.

Cheers,
Ralf

* config/ompi_get_version.m4sh: New (distributed) file, acts as input to
ompi_get_version.sh.  Common functionality factored in
ompi_get_version.m4, generation done by autom4te in autogen.

--- /dev/null   1970-01-01 12:00:00.000000000 +0000
+++ config/ompi_get_version.m4sh        2006-01-18 20:57:14.000000000 +0100
@@ -0,0 +1,98 @@
+m4_define([_m4_divert(SCRIPT)], 100)
+m4_divert_push([SCRIPT])dnl
+#!/bin/sh
+#
+# ompi_get_version is created from ompi_get_version.m4 and 
ompi_get_version.m4sh.
+#
+# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
+#                         University Research and Technology
+#                         Corporation.  All rights reserved.
+# Copyright (c) 2004-2005 The University of Tennessee and The University
+#                         of Tennessee Research Foundation.  All rights
+#                         reserved.
+# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 
+#                         University of Stuttgart.  All rights reserved.
+# Copyright (c) 2004-2005 The Regents of the University of California.
+#                         All rights reserved.
+# $COPYRIGHT$
+# 
+# Additional copyrights may follow
+# 
+# $HEADER$
+#
+
+m4_include([ompi_get_version.m4])
+
+srcfile="$1"
+option="$2"
+
+case "$option" in
+    # svnversion can take a while to run.  If we don't need it, don't run it.
+    --major|--minor|--release|--greek|--base|--help)
+        gv_need_svn=0
+        ;;
+    *)
+        gv_need_svn=1
+esac
+
+
+if test -z "$srcfile"; then
+    option="--help"
+else
+    OMPI_GET_VERSION([$srcfile],[OMPI])
+
+    if test "$option" = ""; then
+       option="--full"
+    fi
+fi
+
+case "$option" in
+    --full|-v|--version)
+       echo $OMPI_VERSION
+       ;;
+    --major)
+       echo $OMPI_MAJOR_VERSION
+       ;;
+    --minor)
+       echo $OMPI_MINOR_VERSION
+       ;;
+    --release)
+       echo $OMPI_RELEASE_VERSION
+       ;;
+    --greek)
+       echo $OMPI_GREEK_VERSION
+       ;;
+    --svn)
+       echo $OMPI_SVN_R
+       ;;
+    --base)
+        echo $OMPI_BASE_VERSION
+        ;;
+    --all)
+        echo ${OMPI_VERSION} ${OMPI_MAJOR_VERSION} ${OMPI_MINOR_VERSION} 
${OMPI_RELEASE_VERSION} ${OMPI_GREEK_VERSION} ${OMPI_SVN_R}
+        ;;
+    -h|--help)
+       cat <<EOF
+$0 <srcfile> [<option>]
+
+<srcfile> - Text version file
+<option>  - One of:
+    --full    - Full version number
+    --major   - Major version number
+    --minor   - Minor version number
+    --release - Release version number
+    --greek   - Greek (alpha, beta, etc) version number
+    --svn     - Subversion repository number
+    --all     - Show all version numbers, separated by :
+    --base    - Show base version number (no svn number)
+    --help    - This message
+EOF
+        ;;
+    *)
+        echo "Unrecognized option $option.  Run $0 --help for options"
+        ;;
+esac
+
+# All done
+
+exit 0
Index: config/ompi_get_version.m4
===================================================================
--- config/ompi_get_version.m4  (revision 8727)
+++ config/ompi_get_version.m4  (working copy)
@@ -18,32 +18,30 @@
 dnl

 dnl
-dnl This file is almost identical in functionality to
-dnl ompi_get_version.sh.  It is unfortunate that we have to duplicate code,
-dnl but it is really the only what that I can think to do it.  :-( Hence,
-dnl if you change the logic here for determining version numbers, YOU MUST
-dnl ALSO CHANGE IT IN ompi_get_version.sh!!
-dnl 
+dnl This file is also used as input to ompi_get_version.sh.
+dnl

-AC_DEFUN([OMPI_GET_VERSION],[
+m4_define([OMPI_GET_VERSION],[
 gv_ver_file="$1"
 gv_prefix="$2"
+: ${gv_need_svn=0}
+: ${srcdir=.}

 dnl quote eval to suppress macro expansion with non-GNU m4

-gv_run() {
-    str="${gv_prefix}_${2}=\$gv_${1}"
-   [eval] $str
-}
-
-if test -n "$gv_ver_file" -a -f "$gv_ver_file"; then
-    gv_major_version="`egrep '^major=' $gv_ver_file | cut -d= -f2`"
-    gv_minor_version="`egrep '^minor=' $gv_ver_file | cut -d= -f2`"
-    gv_release_version="`egrep '^release=' $gv_ver_file | cut -d= -f2`"
-    gv_greek_version="`egrep '^greek=' $gv_ver_file | cut -d= -f2`"
-    gv_want_svn="`egrep '^want_svn=' $gv_ver_file | cut -d= -f2`"
-    gv_svn_r="`egrep '^svn_r=' $gv_ver_file | cut -d= -f2`"
-
+if test -n "$gv_ver_file" && test -f "$gv_ver_file"; then
+    [eval] "`sed -n \"\
+       t clear
+       : clear
+       s/^major/gv_&_version/
+       s/^minor/gv_&_version/
+       s/^release/gv_&_version/
+       s/^greek/gv_&_version/
+       s/^want_svn/gv_&/
+       s/^svn_r/gv_&/
+       T
+       p\" < \"\$gv_ver_file\"`"
+       
     if test -n "$gv_release_version" -a "$gv_release_version" != "0"; then
        
gv_full_version="$gv_major_version.$gv_minor_version.$gv_release_version"
     else
@@ -52,12 +50,14 @@

     gv_full_version="${gv_full_version}${gv_greek_version}"

-    if test "$gv_want_svn" = "1"; then
-        if test "$gv_svn_r" = "-1"; then
+    gv_base_version=$gv_full_version
+
+    if test "$gv_want_svn" = 1 && test "$gv_need_svn" = 1; then
+        if test "$gv_svn_r" = -1; then
             if test -d "$srcdir/.svn"; then
                 ver=r`svnversion "$srcdir"`
                 # make sure svnversion worked
-                if test "$?" != "0" ; then
+                if test "$?" != 0 ; then
                     ver=svn`date '+%m%d%Y'` 
                 fi
             else
@@ -69,14 +69,14 @@
     fi

     # Set the values
-
-    gv_run full_version    VERSION
-    gv_run major_version   MAJOR_VERSION
-    gv_run minor_version   MINOR_VERSION
-    gv_run release_version RELEASE_VERSION
-    gv_run greek_version   GREEK_VERSION
-    gv_run want_svn        WANT_SVN
-    gv_run svn_r           SVN_R
+    [eval] "${gv_prefix}_VERSION=\$gv_full_version
+           ${gv_prefix}_BASE_VERSION=\$gv_base_version
+            ${gv_prefix}_MAJOR_VERSION=\$gv_major_version
+            ${gv_prefix}_MINOR_VERSION=\$gv_minor_version
+            ${gv_prefix}_RELEASE_VERSION=\$gv_release_version
+            ${gv_prefix}_GREEK_VERSION=\$gv_greek_version
+            ${gv_prefix}_WANT_SVN=\$gv_want_svn
+            ${gv_prefix}_SVN_R=\$gv_svn_r"
 fi

 # Clean up
Index: config/Makefile.am
===================================================================
--- config/Makefile.am  (revision 8727)
+++ config/Makefile.am  (working copy)
@@ -49,6 +49,7 @@
         ompi_configure_options.m4 \
         ompi_functions.m4 \
         ompi_get_version.m4 \
+        ompi_get_version.m4sh \
         ompi_get_version.sh \
         ompi_make_stripped_flags.m4 \
         ompi_mca.m4 \
Index: autogen.sh
===================================================================
--- autogen.sh  (revision 8727)
+++ autogen.sh  (working copy)
@@ -40,6 +40,10 @@
 if test ! -z "$AUTOCONF"; then
     ompi_autoconf_search="$AUTOCONF"
 fi
+ompi_autom4te_search="autom4te"
+if test ! -z "$AUTOM4TE"; then
+    ompi_autom4te_search="$AUTOM4TE"
+fi
 ompi_libtoolize_search="libtoolize;glibtoolize"
 if test ! -z "$LIBTOOLIZE"; then
     ompi_libtoolize_search="$LIBTOOLIZE"
@@ -375,6 +379,12 @@

     echo "*** Running GNU tools"

+    if test -f include/mpi.h.in; then
+       cd config
+       run_and_check $ompi_autom4te --language=m4sh ompi_get_version.m4sh -o 
ompi_get_version.sh
+       cd ..
+    fi
+
     run_and_check $ompi_aclocal
     if test "`grep AC_CONFIG_HEADER $file`" != "" -o \
        "`grep AM_CONFIG_HEADER $file`" != ""; then
@@ -1088,6 +1098,7 @@
 fi

 # find all the apps we are going to run
+find_app "autom4te"
 find_app "aclocal"
 find_app "autoheader"
 find_app "autoconf"

Reply via email to