Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python.m4 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ## ------------------------ -*- Autoconf -*-
  2. ## Python file handling
  3. ## From Andrew Dalke
  4. ## Updated by James Henstridge
  5. ## ------------------------
  6. # Copyright (C) 1999-2013 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 and $exec_prefix for the corresponding
  87. dnl values of PYTHON_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_EXEC_PREFIX], ['${exec_prefix}'])
  92. dnl At times (like when building shared libraries) you may want
  93. dnl to know which OS platform Python thinks this is.
  94. AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
  95. [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
  96. AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
  97. # Just factor out some code duplication.
  98. am_python_setup_sysconfig="\
  99. import sys
  100. # Prefer sysconfig over distutils.sysconfig, for better compatibility
  101. # with python 3.x. See automake bug#10227.
  102. # But not see <https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1408092>
  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. # Can't use sysconfig in CPython > 3.0 in debian since it's broken :
  112. # <https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1408092>
  113. try:
  114. from platform import python_implementation
  115. if python_implementation() == 'CPython' and ( \
  116. float(sys.version[[:3]]) > 3.0 or sys.version[[:3]] == '2.7'):
  117. can_use_sysconfig = 0
  118. except ImportError:
  119. pass"
  120. dnl Set up 4 directories:
  121. dnl pythondir -- where to install python scripts. This is the
  122. dnl site-packages directory, not the python standard library
  123. dnl directory like in previous automake betas. This behavior
  124. dnl is more consistent with lispdir.m4 for example.
  125. dnl Query distutils for this directory.
  126. AC_CACHE_CHECK([for $am_display_PYTHON script directory],
  127. [am_cv_python_pythondir],
  128. [if test "x$prefix" = xNONE
  129. then
  130. am_py_prefix=$ac_default_prefix
  131. else
  132. am_py_prefix=$prefix
  133. fi
  134. am_cv_python_pythondir=`$PYTHON -c "
  135. $am_python_setup_sysconfig
  136. if can_use_sysconfig:
  137. sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
  138. else:
  139. from distutils import sysconfig
  140. sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
  141. sys.stdout.write(sitedir)"`
  142. case $am_cv_python_pythondir in
  143. $am_py_prefix*)
  144. am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
  145. am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
  146. ;;
  147. *)
  148. case $am_py_prefix in
  149. /usr|/System*) ;;
  150. *)
  151. am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
  152. ;;
  153. esac
  154. ;;
  155. esac
  156. ])
  157. AC_SUBST([pythondir], [$am_cv_python_pythondir])
  158. dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
  159. dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
  160. dnl more consistent with the rest of automake.
  161. AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
  162. dnl pyexecdir -- directory for installing python extension modules
  163. dnl (shared libraries)
  164. dnl Query distutils for this directory.
  165. AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
  166. [am_cv_python_pyexecdir],
  167. [if test "x$exec_prefix" = xNONE
  168. then
  169. am_py_exec_prefix=$am_py_prefix
  170. else
  171. am_py_exec_prefix=$exec_prefix
  172. fi
  173. am_cv_python_pyexecdir=`$PYTHON -c "
  174. $am_python_setup_sysconfig
  175. if can_use_sysconfig:
  176. sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
  177. else:
  178. from distutils import sysconfig
  179. sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
  180. sys.stdout.write(sitedir)"`
  181. case $am_cv_python_pyexecdir in
  182. $am_py_exec_prefix*)
  183. am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
  184. am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
  185. ;;
  186. *)
  187. case $am_py_exec_prefix in
  188. /usr|/System*) ;;
  189. *)
  190. am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
  191. ;;
  192. esac
  193. ;;
  194. esac
  195. ])
  196. AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
  197. dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
  198. AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
  199. dnl Run any user-specified action.
  200. $2
  201. fi
  202. ])
  203. # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  204. # ---------------------------------------------------------------------------
  205. # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
  206. # Run ACTION-IF-FALSE otherwise.
  207. # This test uses sys.hexversion instead of the string equivalent (first
  208. # word of sys.version), in order to cope with versions such as 2.2c1.
  209. # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
  210. AC_DEFUN([AM_PYTHON_CHECK_VERSION],
  211. [prog="import sys
  212. # split strings by '.' and convert to numeric. Append some zeros
  213. # because we need at least 4 digits for the hex conversion.
  214. # map returns an iterator in Python 3.0 and a list in 2.x
  215. minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
  216. minverhex = 0
  217. # xrange is not present in Python 3.0 and range returns an iterator
  218. for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
  219. sys.exit(sys.hexversion < minverhex)"
  220. AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])