+dnl --- *@-mdw__PYTHON_VERSION-@* ---
+dnl
+dnl Will fail hopelessly on Python < 1.5.2. Nobody uses that any more,
+dnl right?
+
+AC_DEFUN([mdw__PYTHON_VERSION],
+[$1 -c 'from sys import *; v = argv[1]; vv = v.split("."); x = 0
+for i in range(len(vv)): x = x | (int(vv[i]) << (24 - i * 8))
+exit(x > hexversion)' $2])
+
+dnl --- *@-mdw_PROG_PYTHON-@* ---
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_PROG_PYTHON(VERSION, [IF-FOUND], [IF-NOT-FOUND])
+dnl
+dnl Arguments: VERSION = version number of Python required
+dnl IF-FOUND = what to do if it's found
+dnl IF-NOT-FOUND = what to do if it isn't
+dnl
+dnl Use: Attempts to find a working version of Python with a late
+dnl enough version number. It supplies an option `--with-python'
+dnl to allow the user to provide a Python interpreter. If one
+dnl isn't provided explicitly, it searches for `python' and
+dnl `pythonVERSION' in the current PATH, asking them whether they
+dnl have a late enough version number. The path of the working
+dnl Python is put into the `PYTHON' environment variable;
+dnl `AC_SUBST' is used to substitute its value into Python
+dnl scripts. If there is no Python to be found, the value of
+dnl `PYTHON' is set to be `none'.
+
+AC_DEFUN([mdw_PROG_PYTHON],
+[AC_ARG_WITH([python],
+[ --with-python=PYTHON specify path to Python version $1 or newer],
+[PYTHON="$withval"],
+if test -z "$PYTHON"; then
+[AC_CACHE_CHECK([for Python version $1 or later], mdw_cv_prog_python,
+[mdw_cv_prog_python="none"
+for p in `echo "$PATH:/usr/local/bin" | tr ":" " "`; do
+ case $p in /*) ;; *) p=`pwd`/$p ;; esac
+ if mdw__PYTHON_VERSION(["$p/python"], $1); then
+ mdw_cv_prog_python="$p/python"
+ break
+ fi
+ if mdw__PYTHON_VERSION(["$p/python$1"], $1); then
+ mdw_cv_prog_python="$p/python$1"
+ break
+ fi
+done])
+PYTHON="$mdw_cv_prog_python"])
+fi
+
+AC_SUBST(PYTHON)dnl
+if test "$PYTHON" = "none"; then :
+ $3
+else :
+ $2
+fi])
+
+dnl --- *@-mdw_CHECK_PYTHON-@* ---
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_CHECK_PYTHON(VERSION)
+dnl
+dnl Arguments: VERSION = version number of Python required
+dnl
+dnl Use: Verifies that the Python interpreter in the `PYTHON' shell
+dnl variable actually works and is of the right version. If it's
+dnl not, an error is raised and configuration is aborted.
+
+AC_DEFUN([mdw_CHECK_PYTHON],
+[mdw_REQUIRE([mdw_PROG_PYTHON], [$1])
+AC_MSG_CHECKING([whether Python ($PYTHON) works])
+if test "$PYTHON" != "none" && mdw__PYTHON_VERSION("$PYTHON", $1); then
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
+ AC_MSG_ERROR([Python version $1 or newer not found.
+If you have a recent enough Python, and I just failed to find it, try using
+the --with-python=PYTHON option to give me an explicit pathname.])
+fi])
+