As described in the previous section, AC_PROG_PYTHON finds the
Python interpreter with the highest version installed on the
system. Often, you will want to be sure that the user has some minimum
version installed. There is a macro available to simplify this,
PC_PYTHON_VERIFY_VERSION.
m4_define(python_min_ver, 2.6.1)
PC_PYTHON_VERIFY_VERSION([$PYTHON], python_min_ver, ,
[AC_MSG_ERROR(Python interpreter too old)])
In this example, we set the minimum version to 2.6.1 through the use
of an M4 macro. We then check if the interpreter stored in the
PYTHON variable (either set by the user or found by
AC_PROG_PYTHON) is at least of that version. If it is not, the
resulting configure script will exit with an appropriate error
message.
Unfortunately, the divide between Python 2 and Python 3 and many
programs are only compatible with Python 2. Since
AC_PROG_PYTHON will find the latest Python interpreter, if the
user has any Python version 3.x installed, configure must be
able to instead find the most latest 2.x version installed. This is
slightly less straight-forward, but one possible implementation is as
follows:
AC_PROG_PYTHON([python2])
if [[ "x$PYTHON" == "x" ]]; then
AC_PROG_PYTHON
PC_PYTHON_VERIFY_VERSION(3.0, ,
AC_MSG_ERROR(Python 2 (python_min_ver+) is required))
fi
PC_PYTHON_VERIFY_VERSION(python_min_ver, ,
AC_MSG_ERROR(Python 2 (python_min_ver+) is required))
We first check to see if Python is version 3.0 or greater. If it is, we create a list of compatible Python interpreters and manually check for them using standard Autoconf macros. Finally, we check if the interpreter that we found this time is of sufficient version, otherwise configure will halt with an error. Likewise, if no appropriate interpreter was found, an error message will be printed and configure will stop.