Advertisement
Guest User

Untitled

a guest
Jun 9th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009,
  2. # 2011 Free Software Foundation, Inc.
  3. #
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7.  
  8. # AM_PATH_PYTHON2([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  9. # ---------------------------------------------------------------------------
  10. # Adds support for distributing Python modules and packages. To
  11. # install modules, copy them to $(pythondir), using the python_PYTHON
  12. # automake variable. To install a package with the same name as the
  13. # automake package, install to $(pkgpythondir), or use the
  14. # pkgpython_PYTHON automake variable.
  15. #
  16. # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
  17. # locations to install python extension modules (shared libraries).
  18. # Another macro is required to find the appropriate flags to compile
  19. # extension modules.
  20. #
  21. # If your package is configured with a different prefix to python,
  22. # users will have to add the install directory to the PYTHONPATH
  23. # environment variable, or create a .pth file (see the python
  24. # documentation for details).
  25. #
  26. # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON2 will
  27. # cause an error if the version of python installed on the system
  28. # doesn't meet the requirement. MINIMUM-VERSION should consist of
  29. # numbers and dots only.
  30. #
  31. # AM_PATH_PYTHON2 is based on AM_PATH_PYTHON but will search only
  32. # Python 2 locations.
  33. AC_DEFUN([AM_PATH_PYTHON2],
  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. [python2 python2.7 dnl
  39. python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 dnl
  40. python])
  41.  
  42. AC_ARG_VAR([PYTHON], [the Python interpreter])
  43.  
  44. m4_if([$1],[],[
  45. dnl No version check is needed.
  46. # Find any Python interpreter.
  47. if test -z "$PYTHON"; then
  48. AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
  49. fi
  50. am_display_PYTHON=python
  51. ], [
  52. dnl A version check is needed.
  53. if test -n "$PYTHON"; then
  54. # If the user set $PYTHON, use it and don't search something else.
  55. AC_MSG_CHECKING([whether $PYTHON version >= $1])
  56. AM_PYTHON2_CHECK_VERSION([$PYTHON], [$1],
  57. [AC_MSG_RESULT(yes)],
  58. [AC_MSG_ERROR(too old)])
  59. am_display_PYTHON=$PYTHON
  60. else
  61. # Otherwise, try each interpreter until we find one that satisfies
  62. # VERSION.
  63. AC_CACHE_CHECK([for a Python 2 interpreter with version >= $1],
  64. [am_cv_pathless_PYTHON],[
  65. for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
  66. test "$am_cv_pathless_PYTHON" = none && break
  67. AM_PYTHON2_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
  68. done])
  69. # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
  70. if test "$am_cv_pathless_PYTHON" = none; then
  71. PYTHON=:
  72. else
  73. AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
  74. fi
  75. am_display_PYTHON=$am_cv_pathless_PYTHON
  76. fi
  77. ])
  78.  
  79. if test "$PYTHON" = :; then
  80. dnl Run any user-specified action, or abort.
  81. m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
  82. else
  83.  
  84. dnl Query Python for its version number. Getting [:3] seems to be
  85. dnl the best way to do this; it's what "site.py" does in the standard
  86. dnl library.
  87.  
  88. AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
  89. [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
  90. AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
  91.  
  92. dnl Use the values of $prefix and $exec_prefix for the corresponding
  93. dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
  94. dnl distinct variables so they can be overridden if need be. However,
  95. dnl general consensus is that you shouldn't need this ability.
  96.  
  97. AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
  98. AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
  99.  
  100. dnl At times (like when building shared libraries) you may want
  101. dnl to know which OS platform Python thinks this is.
  102.  
  103. AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
  104. [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
  105. AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
  106.  
  107.  
  108. dnl Set up 4 directories:
  109.  
  110. dnl pythondir -- where to install python scripts. This is the
  111. dnl site-packages directory, not the python standard library
  112. dnl directory like in previous automake betas. This behavior
  113. dnl is more consistent with lispdir.m4 for example.
  114. dnl Query distutils for this directory.
  115. AC_CACHE_CHECK([for $am_display_PYTHON script directory],
  116. [am_cv_python_pythondir],
  117. [if test "x$prefix" = xNONE
  118. then
  119. am_py_prefix=$ac_default_prefix
  120. else
  121. am_py_prefix=$prefix
  122. fi
  123. am_cv_python_pythondir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(0,0,prefix='$am_py_prefix'))" 2>/dev/null`
  124. case $am_cv_python_pythondir in
  125. $am_py_prefix*)
  126. am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
  127. am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
  128. ;;
  129. *)
  130. case $am_py_prefix in
  131. /usr|/System*) ;;
  132. *)
  133. am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
  134. ;;
  135. esac
  136. ;;
  137. esac
  138. ])
  139. AC_SUBST([pythondir], [$am_cv_python_pythondir])
  140.  
  141. dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
  142. dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
  143. dnl more consistent with the rest of automake.
  144.  
  145. AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
  146.  
  147. dnl pyexecdir -- directory for installing python extension modules
  148. dnl (shared libraries)
  149. dnl Query distutils for this directory.
  150. AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
  151. [am_cv_python_pyexecdir],
  152. [if test "x$exec_prefix" = xNONE
  153. then
  154. am_py_exec_prefix=$am_py_prefix
  155. else
  156. am_py_exec_prefix=$exec_prefix
  157. fi
  158. am_cv_python_pyexecdir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(1,0,prefix='$am_py_exec_prefix'))" 2>/dev/null`
  159. case $am_cv_python_pyexecdir in
  160. $am_py_exec_prefix*)
  161. am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
  162. am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
  163. ;;
  164. *)
  165. case $am_py_exec_prefix in
  166. /usr|/System*) ;;
  167. *)
  168. am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
  169. ;;
  170. esac
  171. ;;
  172. esac
  173. ])
  174. AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
  175.  
  176. dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
  177.  
  178. AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
  179.  
  180. dnl Run any user-specified action.
  181. $2
  182. fi
  183.  
  184. ])
  185.  
  186.  
  187. # AM_PYTHON2_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  188. # ---------------------------------------------------------------------------
  189. # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION
  190. # and version == 3.
  191. # Run ACTION-IF-FALSE otherwise.
  192. # This test uses sys.hexversion instead of the string equivalent (first
  193. # word of sys.version), in order to cope with versions such as 2.2c1.
  194. # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
  195. #
  196. # Based on AM_PYTHON_CHECK_VERSION but for Python 2 only.
  197. AC_DEFUN([AM_PYTHON2_CHECK_VERSION],
  198. [prog="import sys
  199. # split strings by '.' and convert to numeric. Append some zeros
  200. # because we need at least 4 digits for the hex conversion.
  201. # map returns an iterator in Python 3.0 and a list in 2.x
  202. minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
  203. minverhex = 0
  204. # xrange is not present in Python 3.0 and range returns an iterator
  205. for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
  206. # sys.version_info.major only available since Python 2.7.
  207. # use sys.version_info[0] instead.
  208. # Double the square brackets for M4 syntax.
  209. sys.exit(sys.version_info[[0]] != 2 or sys.hexversion < minverhex)"
  210. AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
  211.  
  212.  
  213. ## Find the install dirs for the python installation.
  214. ## By James Henstridge
  215.  
  216. dnl a macro to check for ability to create python extensions
  217. dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
  218. dnl function also defines PYTHON_INCLUDES
  219. AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
  220. [AC_REQUIRE([AM_PATH_PYTHON2])
  221. AC_MSG_CHECKING(for headers required to compile python extensions)
  222. dnl Win32 doesn't have a versioned directory for headers
  223. if test "$PYTHON_PLATFORM" != "win32"; then
  224. py_versiondir="/python${PYTHON_VERSION}"
  225. else
  226. py_versiondir=
  227. fi
  228. dnl deduce PYTHON_INCLUDES
  229. py_prefix=`$PYTHON -c "import sys; print(sys.prefix)"`
  230. py_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
  231. PYTHON_INCLUDES="-I${py_prefix}/include${py_versiondir}"
  232. if test "$py_prefix" != "$py_exec_prefix"; then
  233. PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include${py_versiondir}"
  234. fi
  235. AC_SUBST(PYTHON_INCLUDES)
  236. dnl check if the headers exist:
  237. save_CPPFLAGS="$CPPFLAGS"
  238. CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
  239. AC_TRY_CPP([#include <Python.h>],dnl
  240. [AC_MSG_RESULT(found)
  241. $1],dnl
  242. [AC_MSG_RESULT(not found)
  243. $2])
  244. CPPFLAGS="$save_CPPFLAGS"
  245. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement