3

I'm trying to get autofoo to test for a maximum version of Python rather than a minimum. Example:

AC_REQUIRE([AM_PATH_PYTHON([2.7])])

... will test for Python >= 2.7, and will probably turn up with /usr/bin/python3. I want it to return nothing greater than python2.7, however.

Is there a straightforward way to do this? I asked around, and so far the best response I've gotten is, "rewrite the macro."

Thanks in advance!

bhilburn
  • 579
  • 7
  • 18
  • 2
    I'm afraid your best response so far is probably right. Isn't it just a question of copying the macro and changing `-gt` to `-lt`? – ptomato Jan 07 '11 at 18:32

3 Answers3

2

1). Add to acinclude.m4

`# my_CHECK_MAJOR_VERSION(VARIABLE, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])`  
`# ---------------------------------------------------------------------------`  
`# Run ACTION-IF-TRUE if the VAR has a major version >= VERSION.`  
`# Run ACTION-IF-FALSE otherwise.`  
AC_DEFUN([my_CHECK_MAJOR_VERSION],  
[AC_MSG_CHECKING([whether $1 $$1 major version == $2])  
case $$1 in  
$2*)  
  AC_MSG_RESULT([yes])  
  ifelse([$3], [$3], [:])  
  ;;  
*)  
  AC_MSG_RESULT([no])  
  ifelse([$4], , [AC_MSG_ERROR([$$1 differs from $2])], [$4])  
  ;;  
esac])  

2.) Add to zconfigure.inz

my_CHECK_MAJOR_VERSION([PYTHON_VERSION], [2])  

3.) aclocal, automake, autoconf

That's it.

biegleux
  • 13,179
  • 11
  • 45
  • 52
HHG
  • 36
  • 2
2

The version argument to AM_PATH_PYTHON is optional. If python is required, call it like this:

AM_PATH_PYTHON

If it's not required, call it like this:

AM_PATH_PYTHON(,, [:])

Now, AM_PATH_PYTHON sets the shell variable $PYTHON_VERSION to the value of sys.version[:3], which you can test yourself.

Jack Kelly
  • 18,264
  • 2
  • 56
  • 81
  • 1
    Right, the issue is that if there are multiple installations of Python on the system, e.g., 2.7 and 3.0, I want $PYTHON_VERSION to become 2.7, and have the rest of the vars reflect that binary path, etc., – bhilburn Jan 28 '11 at 19:10
  • Ah yes, I missed that bit. Even though it doesn't show up in `./configure --help`, you can set `$PYTHON` using something like `./configure PYTHON=/usr/bin/python2.7`. – Jack Kelly Jan 30 '11 at 22:38
  • 2
    Apparently allowing the user to set `$PYTHON` is the correct behaviour, see the bug report here: http://lists.gnu.org/archive/html/bug-automake/2011-01/msg00105.html . It works fine on current automake, but future versions will add help information to `./configure --help`. So you should be fine to test against the result of `AM_PATH_PYTHON` and direct the user to provide an alternate `$PYTHON` if their system version is too new. – Jack Kelly Jan 31 '11 at 22:42
0

An alternative solution can be setting the default for _AM_PYTHON_INTERPRETER_LIST, to include only Python 2 binaries.

Community
  • 1
  • 1