python.m4 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ## ------------------------ -*- Autoconf -*-
  2. ## Python file handling
  3. ## From Andrew Dalke
  4. ## Updated by James Henstridge
  5. ## ------------------------
  6. # Copyright (C) 1999-2014 Free Software Foundation, Inc.
  7. #
  8. # This file is free software; the Free Software Foundation
  9. # gives unlimited permission to copy and/or distribute it,
  10. # with or without modifications, as long as this notice is preserved.
  11. # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  12. # ---------------------------------------------------------------------------
  13. # Adds support for distributing Python modules and packages. To
  14. # install modules, copy them to $(pythondir), using the python_PYTHON
  15. # automake variable. To install a package with the same name as the
  16. # automake package, install to $(pkgpythondir), or use the
  17. # pkgpython_PYTHON automake variable.
  18. #
  19. # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
  20. # locations to install python extension modules (shared libraries).
  21. # Another macro is required to find the appropriate flags to compile
  22. # extension modules.
  23. #
  24. # If your package is configured with a different prefix to python,
  25. # users will have to add the install directory to the PYTHONPATH
  26. # environment variable, or create a .pth file (see the python
  27. # documentation for details).
  28. #
  29. # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
  30. # cause an error if the version of python installed on the system
  31. # doesn't meet the requirement. MINIMUM-VERSION should consist of
  32. # numbers and dots only.
  33. AC_DEFUN([AM_PATH_PYTHON],
  34. [
  35. dnl Find a Python interpreter. Python versions prior to 2.0 are not
  36. dnl supported. (2.0 was released on October 16, 2000).
  37. m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
  38. [python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 dnl
  39. python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
  40. AC_ARG_VAR([PYTHON], [the Python interpreter])
  41. m4_if([$1],[],[
  42. dnl No version check is needed.
  43. # Find any Python interpreter.
  44. if test -z "$PYTHON"; then
  45. AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
  46. fi
  47. am_display_PYTHON=python
  48. ], [
  49. dnl A version check is needed.
  50. if test -n "$PYTHON"; then
  51. # If the user set $PYTHON, use it and don't search something else.
  52. AC_MSG_CHECKING([whether $PYTHON version is >= $1])
  53. AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
  54. [AC_MSG_RESULT([yes])],
  55. [AC_MSG_RESULT([no])
  56. AC_MSG_ERROR([Python interpreter is too old])])
  57. am_display_PYTHON=$PYTHON
  58. else
  59. # Otherwise, try each interpreter until we find one that satisfies
  60. # VERSION.
  61. AC_CACHE_CHECK([for a Python interpreter with version >= $1],
  62. [am_cv_pathless_PYTHON],[
  63. for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
  64. test "$am_cv_pathless_PYTHON" = none && break
  65. AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
  66. done])
  67. # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
  68. if test "$am_cv_pathless_PYTHON" = none; then
  69. PYTHON=:
  70. else
  71. AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
  72. fi
  73. am_display_PYTHON=$am_cv_pathless_PYTHON
  74. fi
  75. ])
  76. if test "$PYTHON" = :; then
  77. dnl Run any user-specified action, or abort.
  78. m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
  79. else
  80. dnl Query Python for its version number. Getting [:3] seems to be
  81. dnl the best way to do this; it's what "site.py" does in the standard
  82. dnl library.
  83. AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
  84. [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
  85. AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
  86. dnl Use the values of $prefix, $libdir and $exec_prefix for the corresponding
  87. dnl values of PYTHON_PREFIX PYTHON_LIB_PREFIX, and PYTHON_EXEC_PREFIX. These are made
  88. dnl distinct variables so they can be overridden if need be. However,
  89. dnl general consensus is that you shouldn't need this ability.
  90. AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
  91. AC_SUBST([PYTHON_LIB_PREFIX], ['${libdir}'])
  92. AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
  93. dnl At times (like when building shared libraries) you may want
  94. dnl to know which OS platform Python thinks this is.
  95. AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
  96. [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
  97. AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
  98. # Just factor out some code duplication.
  99. am_python_setup_sysconfig="\
  100. import sys
  101. # Prefer sysconfig over distutils.sysconfig, for better compatibility
  102. # with python 3.x. See automake bug#10227.
  103. try:
  104. import sysconfig
  105. except ImportError:
  106. can_use_sysconfig = 0
  107. else:
  108. can_use_sysconfig = 1
  109. # Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
  110. # <https://github.com/pypa/virtualenv/issues/118>
  111. try:
  112. from platform import python_implementation
  113. if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
  114. can_use_sysconfig = 0
  115. except ImportError:
  116. pass"
  117. dnl Set up 4 directories:
  118. dnl pythondir -- where to install python scripts. This is the
  119. dnl site-packages directory, not the python standard library
  120. dnl directory like in previous automake betas. This behavior
  121. dnl is more consistent with lispdir.m4 for example.
  122. dnl Query distutils for this directory.
  123. AC_CACHE_CHECK([for $am_display_PYTHON script directory],
  124. [am_cv_python_pythondir],
  125. [if test "x$prefix" = xNONE
  126. then
  127. am_py_prefix=$ac_default_prefix
  128. else
  129. am_py_prefix=$prefix
  130. fi
  131. am_cv_python_pythondir=`echo "$PYTHON_LIB_PREFIX/python$PYTHON_VERSION/site-packages"`
  132. case $am_cv_python_pythondir in
  133. $am_py_prefix*)
  134. am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
  135. am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
  136. ;;
  137. *)
  138. case $am_py_prefix in
  139. /usr|/System*) ;;
  140. *)
  141. am_cv_python_pythondir=$PYTHON_LIB_PREFIX/python$PYTHON_VERSION/site-packages
  142. ;;
  143. esac
  144. ;;
  145. esac
  146. ])
  147. AC_SUBST([pythondir], [$am_cv_python_pythondir])
  148. dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
  149. dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
  150. dnl more consistent with the rest of automake.
  151. AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
  152. dnl pyexecdir -- directory for installing python extension modules
  153. dnl (shared libraries)
  154. dnl Query distutils for this directory.
  155. AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
  156. [am_cv_python_pyexecdir],
  157. [if test "x$exec_prefix" = xNONE
  158. then
  159. am_py_exec_prefix=$am_py_prefix
  160. else
  161. am_py_exec_prefix=$exec_prefix
  162. fi
  163. am_cv_python_pyexecdir=`echo "$PYTHON_LIB_PREFIX/python$PYTHON_VERSION/site-packages"`
  164. case $am_cv_python_pyexecdir in
  165. $am_py_exec_prefix*)
  166. am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
  167. am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
  168. ;;
  169. *)
  170. case $am_py_exec_prefix in
  171. /usr|/System*) ;;
  172. *)
  173. am_cv_python_pyexecdir=$PYTHON_LIB_PREFIX/python$PYTHON_VERSION/site-packages
  174. ;;
  175. esac
  176. ;;
  177. esac
  178. ])
  179. AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
  180. dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
  181. AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
  182. dnl Run any user-specified action.
  183. $2
  184. fi
  185. ])
  186. # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  187. # ---------------------------------------------------------------------------
  188. # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
  189. # Run ACTION-IF-FALSE otherwise.
  190. # This test uses sys.hexversion instead of the string equivalent (first
  191. # word of sys.version), in order to cope with versions such as 2.2c1.
  192. # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
  193. AC_DEFUN([AM_PYTHON_CHECK_VERSION],
  194. [prog="import sys
  195. # split strings by '.' and convert to numeric. Append some zeros
  196. # because we need at least 4 digits for the hex conversion.
  197. # map returns an iterator in Python 3.0 and a list in 2.x
  198. minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
  199. minverhex = 0
  200. # xrange is not present in Python 3.0 and range returns an iterator
  201. for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
  202. sys.exit(sys.hexversion < minverhex)"
  203. AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])