automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

python-version.patch (Was: Bug in AM_PATH_PYTHON ?)


From: Alexandre Duret-Lutz
Subject: python-version.patch (Was: Bug in AM_PATH_PYTHON ?)
Date: 05 Dec 2001 21:59:03 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>> "Patrick" == Patrick Guio <address@hidden> writes:

[...]
 Patrick> AM_PATH_PYTHON(2)
[...]
 Patrick> I am running RH7.2 and have several python
 Patrick> versions. The default "python" is version 1.5 but
 Patrick> there are in addition python2 and python2.1 all of
 Patrick> them coming from rpm's.  The problem is that configure
 Patrick> does not check all the possibilities as it should do:
[...]
 Patrick> checking for python... /usr/bin/python
 Patrick> checking if Python version >= 2... configure: error: too old
[...]
 Patrick> Another comment is that maybe the command python2
 Patrick> could be tried since some rpms contain the python2
 Patrick> command.

The following patch should fix this.

Akim, I'm almost certain I should not call _AC_EVAL (see the
last line of the patch) from an Automake macro, but I don't know
what I should use instead.  All I want is too log the each run
of python and capture any error message to ease debugging.  I
don't need the command to be eval'ed.  Is there a public macro
for this?

Index: ChangeLog
from  Alexandre Duret-Lutz  <address@hidden>

        * m4/python.m4 (AM_PATH_PYTHON): Check all known Python interpreters
        in loop until we find one the satisfies the user supplied version.
        Add python2 to the list of known interpreters.  Don't use
        changequote.
        (AM_PYTHON_CHECK_VERSION): New function, extracted from
        AM_PATH_PYTHON and modernized.

Index: m4/python.m4
===================================================================
RCS file: /home/adl/CVSROOT/automake-20011205-1931/m4/python.m4,v
retrieving revision 1.1
diff -u -c -r1.1 python.m4
*** m4/python.m4        5 Dec 2001 18:31:22 -0000       1.1
--- m4/python.m4        5 Dec 2001 20:05:03 -0000
***************
*** 44,81 ****
  # doesn't meet the requirement.  MINIMUM-VERSION should consist of
  # numbers and dots only.
  
- 
  AC_DEFUN([AM_PATH_PYTHON],
   [
!   dnl Find a version of Python.  I could check for python versions 1.4
!   dnl or earlier, but the default installation locations changed from
    dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
!   dnl in 1.5, and I don't want to maintain that logic.
! 
!   AC_PATH_PROG(PYTHON, python python2.1 python2.0 python1.6 python1.5)
! 
!   dnl should we do the version check?
!   ifelse([$1],[],,[
!     AC_MSG_CHECKING(if Python version >= $1)
!     changequote(<<, >>)dnl
!     prog="
! import sys, string
! minver = '$1'
! pyver = string.split(sys.version)[0]  # first word is version string
! # split strings by '.' and convert to numeric
! minver = map(string.atoi, string.split(minver, '.'))
! pyver = map(string.atoi, string.split(pyver, '.'))
! # we can now do comparisons on the two lists:
! if pyver >= minver:
!       sys.exit(0)
! else:
!       sys.exit(1)"
!     changequote([, ])dnl
!     if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
!     then
!       AC_MSG_RESULT(okay)
      else
!       AC_MSG_ERROR(too old)
      fi
    ])
  
--- 44,81 ----
  # doesn't meet the requirement.  MINIMUM-VERSION should consist of
  # numbers and dots only.
  
  AC_DEFUN([AM_PATH_PYTHON],
   [
!   dnl Find a Python interpreter.  Python versions prior to 1.5 are not
!   dnl supported because the default installation locations changed from
    dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
!   dnl in 1.5.
!   m4_define([_AM_PYTHON_INTERPRETER_LIST],
!           [python python2 python2.1 python2.0 python1.6 python1.5])
! 
!   m4_if([$1],[],[
!     dnl No version check is needed.
!     # Find any Python interpreter.
!     AC_PATH_PROG([PYTHON], _AM_PYTHON_INTERPRETER_LIST)],[
!     dnl A version check is needed.
!     if test -n "$PYTHON"; then
!       # If the user set $PYTHON, use it and don't search something else.
!       AC_MSG_CHECKING([whether $PYTHON version >= $1])
!       AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
!                             [AC_MSG_RESULT(yes)],
!                             [AC_MSG_ERROR(too old)])
      else
!       # Otherwise, try each interpreter until we find one that satisfies
!       # VERSION.
!       AC_MSG_CHECKING([for a Python interpreter with version >= $1])
!       for PYTHON in _AM_PYTHON_INTERPRETER_LIST : ; do
!         if test "$PYTHON" = : ; then
!           AC_MSG_ERROR([no suitable Python interpreter found])
!       fi
!         AM_PYTHON_CHECK_VERSION([$PYTHON], [$1], [break])
!       done
!       AC_MSG_RESULT([$PYTHON])
!       AC_SUBST([PYTHON])
      fi
    ])
  
***************
*** 83,111 ****
  
    dnl Query Python for its version number.  Getting [:3] seems to be
    dnl the best way to do this; it's what "site.py" does in the standard
!   dnl library.  Need to change quote character because of [:3]
! 
!   AC_SUBST(PYTHON_VERSION)
!   changequote(<<, >>)dnl
!   PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
!   changequote([, ])dnl
  
  
    dnl Use the values of $prefix and $exec_prefix for the corresponding
    dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
    dnl distinct variables so they can be overridden if need be.  However,
    dnl general consensus is that you shouldn't need this ability.
  
!   AC_SUBST(PYTHON_PREFIX)
    PYTHON_PREFIX='${prefix}'
  
!   AC_SUBST(PYTHON_EXEC_PREFIX)
    PYTHON_EXEC_PREFIX='${exec_prefix}'
  
    dnl At times (like when building shared libraries) you may want
    dnl to know which OS platform Python thinks this is.
  
!   AC_SUBST(PYTHON_PLATFORM)
    PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
  
  
--- 83,108 ----
  
    dnl Query Python for its version number.  Getting [:3] seems to be
    dnl the best way to do this; it's what "site.py" does in the standard
!   dnl library.
  
+   AC_SUBST([PYTHON_VERSION])
+   PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[:3]]"`
  
    dnl Use the values of $prefix and $exec_prefix for the corresponding
    dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
    dnl distinct variables so they can be overridden if need be.  However,
    dnl general consensus is that you shouldn't need this ability.
  
!   AC_SUBST([PYTHON_PREFIX])
    PYTHON_PREFIX='${prefix}'
  
!   AC_SUBST([PYTHON_EXEC_PREFIX])
    PYTHON_EXEC_PREFIX='${exec_prefix}'
  
    dnl At times (like when building shared libraries) you may want
    dnl to know which OS platform Python thinks this is.
  
!   AC_SUBST([PYTHON_PLATFORM])
    PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
  
  
***************
*** 119,125 ****
    dnl Also, if the package prefix isn't the same as python's prefix,
    dnl then the old $(pythondir) was pretty useless.
  
!   AC_SUBST(pythondir)
    pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
  
    dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
--- 116,122 ----
    dnl Also, if the package prefix isn't the same as python's prefix,
    dnl then the old $(pythondir) was pretty useless.
  
!   AC_SUBST([pythondir])
    pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
  
    dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
***************
*** 127,146 ****
    dnl   more consistent with the rest of automake.
    dnl   Maybe this should be put in python.am?
  
!   AC_SUBST(pkgpythondir)
    pkgpythondir=\${pythondir}/$PACKAGE
  
    dnl pyexecdir -- directory for installing python extension modules
    dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
  
!   AC_SUBST(pyexecdir)
    pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
  
    dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
    dnl   Maybe this should be put in python.am?
  
!   AC_SUBST(pkgpyexecdir)
    pkgpyexecdir=\${pyexecdir}/$PACKAGE
  
    AC_MSG_RESULT([looks good])
  ])
--- 124,158 ----
    dnl   more consistent with the rest of automake.
    dnl   Maybe this should be put in python.am?
  
!   AC_SUBST([pkgpythondir])
    pkgpythondir=\${pythondir}/$PACKAGE
  
    dnl pyexecdir -- directory for installing python extension modules
    dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
  
!   AC_SUBST([pyexecdir])
    pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
  
    dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
    dnl   Maybe this should be put in python.am?
  
!   AC_SUBST([pkgpyexecdir])
    pkgpyexecdir=\${pyexecdir}/$PACKAGE
  
    AC_MSG_RESULT([looks good])
  ])
+ 
+ 
+ # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
+ # ---------------------------------------------------------------------------
+ # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
+ # Run ACTION-IF-FALSE otherwise.
+ AC_DEFUN([AM_PYTHON_CHECK_VERSION],
+  [prog="import sys, string
+ pyver = string.split(sys.version)[[0]]  # first word is version string
+ # split strings by '.' and convert to numeric
+ minver = map(string.atoi, string.split('$2', '.'))
+ pyver = map(string.atoi, string.split(pyver, '.'))
+ # we can now do comparisons on the two lists:
+ sys.exit(pyver < minver)"
+   AS_IF([_AC_EVAL(['$1 -c "$prog"'])], [$3], [$4])])

-- 
Alexandre Duret-Lutz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]