ax_with_python.m4 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. dnl @synopsis AX_WITH_PYTHON([minimum-version], [value-if-not-found], [path])
  2. dnl
  3. dnl @version 20015-01-22
  4. dnl
  5. dnl @author Dustin Mitchell <dustin@cs.uchicago.edu>
  6. dnl
  7. dnl Locates an installed Python binary, placing the result in the precious
  8. dnl variable $PYTHON. Accepts a present $PYTHON, then --with-python, and
  9. dnl failing that searches for python in the given path (which defaults to the
  10. dnl system path). If python is found, $PYTHON is set to the full path of the
  11. dnl binary; if it is not found, $PYTHON is set to VALUE-IF-NOT-FOUND, which
  12. dnl defaults to 'python'.
  13. dnl
  14. AC_DEFUN([AX_WITH_PYTHON],
  15. [
  16. AC_ARG_VAR([PYTHON])
  17. dnl unless PYTHON was supplied to us (as a precious variable)
  18. if test -z "$PYTHON"
  19. then
  20. AC_MSG_CHECKING(for --with-python)
  21. AC_ARG_WITH(python,
  22. AC_HELP_STRING([--with-python=PYTHON],
  23. [absolute path name of Python executable]),
  24. [ if test "$withval" != "yes"
  25. then
  26. PYTHON="$withval"
  27. AC_MSG_RESULT($withval)
  28. else
  29. AC_MSG_RESULT(no)
  30. fi
  31. ],
  32. [ AC_MSG_RESULT(no)
  33. ])
  34. fi
  35. dnl if it's still not found, check the paths, or use the fallback
  36. if test -z "$PYTHON"
  37. then
  38. AC_PATH_PROG([PYTHON], python, m4_ifval([$2],[$2],[python]), $3)
  39. fi
  40. dnl check version if required
  41. m4_ifvaln([$1], [
  42. dnl do this only if we didn't fall back
  43. if test "$PYTHON" != "m4_ifval([$2],[$2],[python])"
  44. then
  45. AC_MSG_CHECKING($PYTHON version >= $1)
  46. if test `$PYTHON -c ["import sys; print sys.version[:3] >= \"$1\" and \"OK\" or \"OLD\""]` = "OK"
  47. then
  48. AC_MSG_RESULT(ok)
  49. else
  50. AC_MSG_RESULT(no)
  51. PYTHON="$2"
  52. fi
  53. fi])
  54. ])