No Description
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_pyconfigure.m4 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. # Copyright 2012, 2013, 2014 Brandon Invergo <brandon@invergo.net>
  2. #
  3. # This file is part of pyconfigure. This program is free
  4. # software; you can redistribute it and/or modify it under the
  5. # terms of the GNU General Public License as published by the
  6. # Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # Under Section 7 of GPL version 3, you are granted additional
  15. # permissions described in the Autoconf Configure Script Exception,
  16. # version 3.0, as published by the Free Software Foundation.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # and a copy of the Autoconf Configure Script Exception along with
  20. # this program; see the files COPYINGv3 and COPYING.EXCEPTION
  21. # respectively. If not, see <http://www.gnu.org/licenses/>.
  22. # Many of these macros were adapted from ones written by Andrew Dalke
  23. # and James Henstridge and are included with the Automake utility
  24. # under the following copyright terms:
  25. #
  26. # Copyright (C) 1999-2012 Free Software Foundation, Inc.
  27. #
  28. # This file is free software; the Free Software Foundation
  29. # gives unlimited permission to copy and/or distribute it,
  30. # with or without modifications, as long as this notice is preserved.
  31. # Table of Contents:
  32. #
  33. # 1. Language selection
  34. # and routines to produce programs in a given language.
  35. #
  36. # 2. Producing programs in a given language.
  37. #
  38. # 3. Looking for a compiler
  39. # And possibly the associated preprocessor.
  40. #
  41. # 4. Looking for specific libs & functionality
  42. ## ----------------------- ##
  43. ## 1. Language selection. ##
  44. ## ----------------------- ##
  45. # AC_LANG(Python)
  46. # ---------------
  47. AC_LANG_DEFINE([Python], [py], [PY], [PYTHON], [],
  48. [ac_ext=py
  49. ac_compile='chmod +x conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
  50. ac_link='chmod +x conftest.$ac_ext && cp conftest.$ac_ext conftest >&AS_MESSAGE_LOG_FD'
  51. ])
  52. # AC_LANG_PYTHON
  53. # --------------
  54. AU_DEFUN([AC_LANG_PYTHON], [AC_LANG(Python)])
  55. ## ----------------------- ##
  56. ## 2. Producing programs. ##
  57. ## ----------------------- ##
  58. # AC_LANG_PROGRAM(Python)([PROLOGUE], [BODY])
  59. # -------------------------------------------
  60. m4_define([AC_LANG_PROGRAM(Python)], [dnl
  61. @%:@!$PYTHON
  62. $1
  63. m4_if([$2], [], [], [dnl
  64. if __name__ == '__main__':
  65. $2])])
  66. # _AC_LANG_IO_PROGRAM(Python)
  67. # ---------------------------
  68. # Produce source that performs I/O.
  69. m4_define([_AC_LANG_IO_PROGRAM(Python)],
  70. [AC_LANG_PROGRAM([dnl
  71. import sys
  72. try:
  73. h = open('conftest.out')
  74. except:
  75. sys.exit(1)
  76. else:
  77. close(h)
  78. sys.exit(0)
  79. ], [])])
  80. # _AC_LANG_CALL(Python)([PROLOGUE], [FUNCTION])
  81. # ---------------------
  82. # Produce source that calls FUNCTION
  83. m4_define([_AC_LANG_CALL(Python)],
  84. [AC_LANG_PROGRAM([$1], [$2])])
  85. ## -------------------------------------------- ##
  86. ## 3. Looking for Compilers and Interpreters. ##
  87. ## -------------------------------------------- ##
  88. AC_DEFUN([AC_LANG_COMPILER(Python)],
  89. [AC_REQUIRE([PC_PROG_PYTHON])])
  90. # PC_INIT([MIN-VERSION], [MAX-VERSION])
  91. # -----------------------------
  92. # Initialize pyconfigure, finding a Python interpreter with a given
  93. # minimum and/or maximum version.
  94. AC_DEFUN([PC_INIT],
  95. [PC_PROG_PYTHON([], [$1], [$2])
  96. dnl If we found something, do a sanity check that the interpreter really
  97. dnl has the version its name would suggest.
  98. m4_ifval([PYTHON],
  99. [PC_PYTHON_VERIFY_VERSION([>=], [pc_min_ver], [],
  100. [AC_MSG_FAILURE([No compatible Python interpreter found. If you're sure that you have one, try setting the PYTHON environment variable to the location of the interpreter.])])])
  101. m4_ifval([PYTHON],
  102. [PC_PYTHON_VERIFY_VERSION([<=], [pc_max_ver], [],
  103. [AC_MSG_FAILURE([No compatible Python interpreter found. If you're sure that you have one, try setting the PYTHON environment variable to the location of the interpreter.])])])
  104. ])# PC_INIT
  105. # PC_PROG_PYTHON([PROG-TO-CHECK-FOR], [MIN-VERSION], [MAX-VERSION])
  106. # ---------------------------------
  107. # Find a Python interpreter. Python versions prior to 2.0 are not
  108. # supported. (2.0 was released on October 16, 2000).
  109. AC_DEFUN_ONCE([PC_PROG_PYTHON],
  110. [AC_ARG_VAR([PYTHON], [the Python interpreter])
  111. dnl The default minimum version is 2.0
  112. m4_define_default([pc_min_ver], m4_ifval([$2], [$2], [2.0]))
  113. dnl The default maximum version is 3.3
  114. m4_define_default([pc_max_ver], m4_ifval([$3], [$3], [4.0]))
  115. dnl Build up a list of possible interpreter names.
  116. m4_define_default([_PC_PYTHON_INTERPRETER_LIST],
  117. [dnl If we want some Python 3 versions (max version >= 3.0),
  118. dnl also search for "python3"
  119. m4_if(m4_version_compare(pc_max_ver, [2.9]), [1], [python3], []) \
  120. dnl If we want some Python 2 versions (min version <= 2.7),
  121. dnl also search for "python2".
  122. m4_if(m4_version_compare(pc_min_ver, [2.8]), [-1], [python2], []) \
  123. dnl Construct a comma-separated list of interpreter names (python2.6,
  124. dnl python2.7, etc). We only care about the first 3 characters of the
  125. dnl version strings (major-dot-minor; not
  126. dnl major-dot-minor-dot-bugfix[-dot-whatever])
  127. m4_foreach([pc_ver],
  128. m4_esyscmd_s(seq -s[[", "]] -f["[[%.1f]]"] m4_substr(pc_max_ver, [0], [3]) -0.1 m4_substr(pc_min_ver, [0], [3])),
  129. dnl Remove python2.8 and python2.9 since they will never exist
  130. [m4_bmatch(pc_ver, [2.[89]], [], [python]pc_ver)]) \
  131. [python]])
  132. dnl Do the actual search at last.
  133. m4_ifval([$1],
  134. [AC_PATH_PROGS(PYTHON, [$1 _PC_PYTHON_INTERPRETER_LIST])],
  135. [AC_PATH_PROGS(PYTHON, [_PC_PYTHON_INTERPRETER_LIST])])
  136. ])# PC_PROG_PYTHON
  137. # PC_PYTHON_PROG_PYTHON_CONFIG(PROG-TO-CHECK-FOR)
  138. # ----------------------------------------------
  139. # Find the python-config program
  140. AC_DEFUN([PC_PYTHON_PROG_PYTHON_CONFIG],
  141. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  142. AC_ARG_VAR([PYTHON_CONFIG], [the Python-config program])
  143. dnl python-config's binary name is normally based on the Python interpreter's
  144. dnl binary name (i.e. python2.7 -> python2.7-config)
  145. m4_define([_PYTHON_BASENAME], [`basename $PYTHON`])
  146. m4_ifval([$1],
  147. [AC_PATH_PROGS(PYTHON_CONFIG, [$1 _PYTHON_BASENAME-config])],
  148. [AC_PATH_PROG(PYTHON_CONFIG, _PYTHON_BASENAME-config)])
  149. ]) # PC_PYTHON_PROG_PYTHON_CONFIG
  150. # PC_PYTHON_VERIFY_VERSION([RELATION], [VERSION], [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  151. # ---------------------------------------------------------------------------
  152. # Run ACTION-IF-TRUE if the Python interpreter PROG has version [RELATION] VERSION.
  153. # i.e if RELATION is "<", check if PROG has a version number less than VERSION.
  154. # Run ACTION-IF-FALSE otherwise.
  155. # Specify RELATION as any mathematical comparison "<", ">", "<=", ">=", "==" or "!="
  156. # This test uses sys.hexversion instead of the string equivalent (first
  157. # word of sys.version), in order to cope with versions such as 2.2c1.
  158. # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
  159. AC_DEFUN([PC_PYTHON_VERIFY_VERSION],
  160. [m4_define([pc_python_safe_ver], m4_bpatsubsts($2, [\.], [_]))
  161. AC_CACHE_CHECK([if Python $1 '$2'],
  162. [[pc_cv_python_req_version_]pc_python_safe_ver],
  163. [AC_LANG_PUSH(Python)[]dnl
  164. AC_RUN_IFELSE(
  165. [AC_LANG_PROGRAM([dnl
  166. import sys
  167. ], [dnl
  168. # split strings by '.' and convert to numeric. Append some zeros
  169. # because we need at least 4 digits for the hex conversion.
  170. # map returns an iterator in Python 3.0 and a list in 2.x
  171. reqver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
  172. reqverhex = 0
  173. # xrange is not present in Python 3.0 and range returns an iterator
  174. for i in list(range(4)):
  175. reqverhex = (reqverhex << 8) + reqver[[i]]
  176. # the final 8 bits are "0xf0" for final versions, which are all
  177. # we'll test against, since it's doubtful that a released software
  178. # will depend on an alpha- or beta-state Python.
  179. reqverhex += 0xf0
  180. if sys.hexversion $1 reqverhex:
  181. sys.exit()
  182. else:
  183. sys.exit(1)
  184. ])],
  185. [[pc_cv_python_req_version_]pc_python_safe_ver=yes],
  186. [[pc_cv_python_req_version_]pc_python_safe_ver=no])
  187. AC_LANG_POP(Python)[]dnl
  188. ])
  189. AS_IF([test "$[pc_cv_python_req_version_]pc_python_safe_ver" = "no"], [$4], [$3])
  190. ])# PC_PYTHON_VERIFY_VERSION
  191. # PC_PYTHON_CHECK_VERSION
  192. # -----------------------
  193. # Query Python for its version number. Getting [:3] seems to be
  194. # the best way to do this; it's what "site.py" does in the standard
  195. # library.
  196. AC_DEFUN([PC_PYTHON_CHECK_VERSION],
  197. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  198. AC_CACHE_CHECK([for $1 version],
  199. [pc_cv_python_version],
  200. [AC_LANG_PUSH(Python)[]dnl
  201. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  202. import sys
  203. ], [dnl
  204. sys.stdout.write(sys.version[[:3]])
  205. ])],
  206. [pc_cv_python_version=`./conftest`],
  207. [AC_MSG_FAILURE([failed to run Python program])])
  208. AC_LANG_POP(Python)[]dnl
  209. ])
  210. AC_SUBST([PYTHON_VERSION], [$pc_cv_python_version])
  211. ])# PC_PYTHON_CHECK_VERSION
  212. # PC_PYTHON_CHECK_PREFIX
  213. # ----------------------
  214. # Use the value of $prefix for the corresponding value of
  215. # PYTHON_PREFIX. This is made a distinct variable so it can be
  216. # overridden if need be. However, general consensus is that you
  217. # shouldn't need this ability.
  218. AC_DEFUN([PC_PYTHON_CHECK_PREFIX],
  219. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  220. dnl Try to get it with python-config otherwise do it from within Python
  221. AC_CACHE_CHECK([for Python prefix], [pc_cv_python_prefix],
  222. [if test -x "$PYTHON_CONFIG"; then
  223. pc_cv_python_prefix=`$PYTHON_CONFIG --prefix 2>&AS_MESSAGE_LOG_FD`
  224. else
  225. AC_LANG_PUSH(Python)[]dnl
  226. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  227. import sys
  228. ], [dnl
  229. sys.stdout.write(sys.prefix)
  230. ])], [pc_cv_python_prefix=`./conftest`;
  231. if test $? != 0; then
  232. AC_MSG_FAILURE([could not determine Python prefix])
  233. fi],
  234. [AC_MSG_FAILURE([failed to run Python program])])
  235. AC_LANG_POP(Python)[]dnl
  236. fi])
  237. AC_SUBST([PYTHON_PREFIX], [$pc_cv_python_prefix])])
  238. # PC_PYTHON_CHECK_EXEC_PREFIX
  239. # --------------------------
  240. # Like above, but for $exec_prefix
  241. AC_DEFUN([PC_PYTHON_CHECK_EXEC_PREFIX],
  242. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  243. dnl Try to get it with python-config otherwise do it from within Python
  244. AC_CACHE_CHECK([for Python exec-prefix], [pc_cv_python_exec_prefix],
  245. [if test -x "$PYTHON_CONFIG"; then
  246. pc_cv_python_exec_prefix=`$PYTHON_CONFIG --exec-prefix 2>&AS_MESSAGE_LOG_FD`
  247. else
  248. AC_LANG_PUSH(Python)[]dnl
  249. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  250. import sys
  251. ], [dnl
  252. sys.stdout.write(sys.exec_prefix)
  253. ])],
  254. [pc_cv_python_exec_prefix=`./conftest`;
  255. if test $? != 0; then
  256. AC_MSG_FAILURE([could not determine Python exec_prefix])
  257. fi],
  258. [AC_MSG_FAILURE([failed to run Python program])])
  259. AC_LANG_POP(Python)[]dnl
  260. fi
  261. ])
  262. AC_SUBST([PYTHON_EXEC_PREFIX], [$pc_cv_python_exec_prefix])])
  263. # PC_PYTHON_CHECK_INCLUDES
  264. # ------------------------
  265. # Find the Python header file include flags (ie
  266. # '-I/usr/include/python')
  267. AC_DEFUN([PC_PYTHON_CHECK_INCLUDES],
  268. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  269. dnl Try to find the headers location with python-config otherwise guess
  270. AC_CACHE_CHECK([for Python includes], [pc_cv_python_includes],
  271. [if test -x "$PYTHON_CONFIG"; then
  272. pc_cv_python_includes=`$PYTHON_CONFIG --includes 2>&AS_MESSAGE_LOG_FD`
  273. else
  274. pc_cv_python_includes="[-I$includedir/$_PYTHON_BASENAME]m4_ifdef(PYTHON_ABI_FLAGS,
  275. PYTHON_ABI_FLAGS,)"
  276. fi
  277. ])
  278. AC_SUBST([PYTHON_INCLUDES], [$pc_cv_python_includes])])
  279. # PC_PYTHON_CHECK_HEADERS([ACTION-IF-PRESENT], [ACTION-IF-ABSENT])
  280. # -----------------------
  281. # Check for the presence and usability of Python.h
  282. AC_DEFUN([PC_PYTHON_CHECK_HEADERS],
  283. [AC_REQUIRE([PC_PYTHON_CHECK_INCLUDES])[]dnl
  284. pc_cflags_store=$CPPFLAGS
  285. CPPFLAGS="$CFLAGS $PYTHON_INCLUDES"
  286. AC_CHECK_HEADER([Python.h], [$1], [$2])
  287. CPPFLAGS=$pc_cflags_store
  288. ])
  289. # PC_PYTHON_CHECK_LIBS
  290. # --------------------
  291. # Find the Python lib flags (ie '-lpython')
  292. AC_DEFUN([PC_PYTHON_CHECK_LIBS],
  293. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  294. dnl Try to find the lib flags with python-config otherwise guess
  295. AC_CACHE_CHECK([for Python libs], [pc_cv_python_libs],
  296. [if test -x "$PYTHON_CONFIG"; then
  297. pc_cv_python_libs=`$PYTHON_CONFIG --libs 2>&AS_MESSAGE_LOG_FD`
  298. else
  299. pc_cv_python_libs="[-l$_PYTHON_BASENAME]m4_ifdef(PYTHON_ABI_FLAGS, PYTHON_ABI_FLAGS,)"
  300. fi
  301. ])
  302. AC_SUBST([PYTHON_LIBS], [$pc_cv_python_libs])])
  303. # PC_PYTHON_TEST_LIBS(LIBRARY-FUNCTION, [ACTION-IF-PRESENT], [ACTION-IF-ABSENT])
  304. # -------------------
  305. # Verify that the Python libs can be loaded
  306. AC_DEFUN([PC_PYTHON_TEST_LIBS],
  307. [AC_REQUIRE([PC_PYTHON_CHECK_LIBS])[]dnl
  308. pc_libflags_store=$LIBS
  309. for lflag in $PYTHON_LIBS; do
  310. case $lflag in
  311. -lpython*@:}@
  312. LIBS="$LIBS $lflag"
  313. pc_libpython=`echo $lflag | sed -e 's/^-l//'`
  314. ;;
  315. *@:}@;;
  316. esac
  317. done
  318. AC_CHECK_LIB([$pc_libpython], [$1], [$2], [$3])])
  319. # PC_PYTHON_CHECK_CFLAGS
  320. # ----------------------
  321. # Find the Python CFLAGS
  322. AC_DEFUN([PC_PYTHON_CHECK_CFLAGS],
  323. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  324. dnl Try to find the CFLAGS with python-config otherwise give up
  325. AC_CACHE_CHECK([for Python CFLAGS], [pc_cv_python_cflags],
  326. [if test -x "$PYTHON_CONFIG"; then
  327. pc_cv_python_cflags=`$PYTHON_CONFIG --cflags 2>&AS_MESSAGE_LOG_FD`
  328. else
  329. pc_cv_python_cflags=
  330. fi
  331. ])
  332. AC_SUBST([PYTHON_CFLAGS], [$pc_cv_python_cflags])])
  333. # PC_PYTHON_CHECK_LDFLAGS
  334. # -----------------------
  335. # Find the Python LDFLAGS
  336. AC_DEFUN([PC_PYTHON_CHECK_LDFLAGS],
  337. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  338. dnl Try to find the LDFLAGS with python-config otherwise give up
  339. AC_CACHE_CHECK([for Python LDFLAGS], [pc_cv_python_ldflags],
  340. [if test -x "$PYTHON_CONFIG"; then
  341. pc_cv_python_ldflags=`$PYTHON_CONFIG --ldflags 2>&AS_MESSAGE_LOG_FD`
  342. else
  343. pc_cv_python_ldflags=
  344. fi
  345. ])
  346. AC_SUBST([PYTHON_LDFLAGS], [$pc_cv_python_ldflags])])
  347. # PC_PYTHON_CHECK_EXTENSION_SUFFIX
  348. # --------------------------------
  349. # Find the Python extension suffix (i.e. '.cpython-32.so')
  350. AC_DEFUN([PC_PYTHON_CHECK_EXTENSION_SUFFIX],
  351. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  352. dnl Try to find the suffix with python-config otherwise give up
  353. AC_CACHE_CHECK([for Python extension suffix], [pc_cv_python_extension_suffix],
  354. [if test -x "$PYTHON_CONFIG"; then
  355. pc_cv_python_extension_suffix=`$PYTHON_CONFIG --extension-suffix 2>&AS_MESSAGE_LOG_FD`
  356. else
  357. pc_cv_python_extension_suffix=
  358. fi
  359. ])
  360. AC_SUBST([PYTHON_EXTENSION_SUFFIX], [$pc_cv_python_extension_suffix])])
  361. # PC_PYTHON_CHECK_ABI_FLAGS
  362. # -------------------------
  363. # Find the Python ABI flags
  364. AC_DEFUN([PC_PYTHON_CHECK_ABI_FLAGS],
  365. [AC_REQUIRE([PC_PYTHON_PROG_PYTHON_CONFIG])[]dnl
  366. dnl Try to find the ABI flags with python-config otherwise give up
  367. AC_CACHE_CHECK([for Python ABI flags], [pc_cv_python_abi_flags],
  368. [if test -x "$PYTHON_CONFIG"; then
  369. pc_cv_python_abi_flags=`$PYTHON_CONFIG --abiflags 2>&AS_MESSAGE_LOG_FD`
  370. else
  371. pc_cv_python_abi_flags=
  372. fi
  373. ])
  374. AC_SUBST([PYTHON_ABI_FLAGS], [$pc_cv_python_abi_flags])])
  375. # PC_PYTHON_CHECK_PLATFORM
  376. # ------------------------
  377. # At times (like when building shared libraries) you may want
  378. # to know which OS platform Python thinks this is.
  379. AC_DEFUN([PC_PYTHON_CHECK_PLATFORM],
  380. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  381. dnl Get the platform from within Python (sys.platform)
  382. AC_CACHE_CHECK([for Python platform], [pc_cv_python_platform],
  383. [AC_LANG_PUSH(Python)[]dnl
  384. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  385. import sys
  386. ], [dnl
  387. sys.stdout.write(sys.platform)
  388. ])], [pc_cv_python_platform=`./conftest`;
  389. if test $? != 0; then
  390. AC_MSG_FAILURE([could not determine Python platform])
  391. fi],
  392. [AC_MSG_FAILURE([failed to run Python program])])
  393. AC_LANG_POP(Python)[]dnl
  394. ])
  395. AC_SUBST([PYTHON_PLATFORM], [$pc_cv_python_platform])
  396. ])
  397. # PC_PYTHON_CHECK_SITE_DIR
  398. # ---------------------
  399. # The directory to which new libraries are installed (i.e. the
  400. # "site-packages" directory.
  401. AC_DEFUN([PC_PYTHON_CHECK_SITE_DIR],
  402. [AC_REQUIRE([PC_PROG_PYTHON])AC_REQUIRE([PC_PYTHON_CHECK_PREFIX])[]dnl
  403. AC_CACHE_CHECK([for Python site-packages directory],
  404. [pc_cv_python_site_dir],
  405. [AC_LANG_PUSH(Python)[]dnl
  406. if test "x$prefix" = xNONE
  407. then
  408. pc_py_prefix=$ac_default_prefix
  409. else
  410. pc_py_prefix=$prefix
  411. fi
  412. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  413. import sys
  414. from platform import python_implementation
  415. # sysconfig in CPython 2.7 doesn't work in virtualenv
  416. # <https://github.com/pypa/virtualenv/issues/118>
  417. try:
  418. import sysconfig
  419. except:
  420. can_use_sysconfig = False
  421. else:
  422. can_use_sysconfig = True
  423. if can_use_sysconfig:
  424. # Can't use sysconfig in CPython > 3.0 in debian since it's broken :
  425. # <https://bugs.launchpad.net/ubuntu/+source/python3-defaults/+bug/1408092>
  426. if python_implementation() == "CPython" (
  427. float(sys.version[[:3]]) > 3.0 or sys.version[[:3]] == '2.7'):
  428. can_use_sysconfig = False
  429. if not can_use_sysconfig:
  430. from distutils import sysconfig
  431. sitedir = sysconfig.get_python_lib(False, False, prefix='$pc_py_prefix')
  432. else:
  433. sitedir = sysconfig.get_path('purelib', vars={'base':'$pc_py_prefix'})
  434. ], [dnl
  435. sys.stdout.write(sitedir)
  436. ])], [pc_cv_python_site_dir=`./conftest`],
  437. [AC_MSG_FAILURE([failed to run Python program])])
  438. AC_LANG_POP(Python)[]dnl
  439. case $pc_cv_python_site_dir in
  440. $pc_py_prefix*)
  441. pc__strip_prefix=`echo "$pc_py_prefix" | sed 's|.|.|g'`
  442. pc_cv_python_site_dir=`echo "$pc_cv_python_site_dir" | sed "s,^$pc__strip_prefix/,,"`
  443. ;;
  444. *)
  445. case $pc_py_prefix in
  446. /usr|/System*) ;;
  447. *)
  448. pc_cv_python_site_dir=lib/python$PYTHON_VERSION/site-packages
  449. ;;
  450. esac
  451. ;;
  452. esac
  453. ])
  454. AC_SUBST([pythondir], [\${prefix}/$pc_cv_python_site_dir])])# PC_PYTHON_CHECK_SITE_DIR
  455. # PC_PYTHON_SITE_PACKAGE_DIR
  456. # --------------------------
  457. # $PACKAGE directory under PYTHON_SITE_DIR
  458. AC_DEFUN([PC_PYTHON_SITE_PACKAGE_DIR],
  459. [AC_REQUIRE([PC_PYTHON_CHECK_SITE_DIR])[]dnl
  460. AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE_NAME])])
  461. # PC_PYTHON_CHECK_EXEC_DIR
  462. # ------------------------
  463. # directory for installing python extension modules (shared libraries)
  464. AC_DEFUN([PC_PYTHON_CHECK_EXEC_DIR],
  465. [AC_REQUIRE([PC_PROG_PYTHON])AC_REQUIRE([PC_PYTHON_CHECK_EXEC_PREFIX])[]dnl
  466. AC_CACHE_CHECK([for Python extension module directory],
  467. [pc_cv_python_exec_dir],
  468. [AC_LANG_PUSH(Python)[]dnl
  469. if test "x$pc_cv_python_exec_prefix" = xNONE
  470. then
  471. pc_py_exec_prefix=$pc_cv_python_prefix
  472. else
  473. pc_py_exec_prefix=$pc_cv_python_exec_prefix
  474. fi
  475. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  476. import sys
  477. from platform import python_implementation
  478. # sysconfig in CPython 2.7 doesn't work in virtualenv
  479. # <https://github.com/pypa/virtualenv/issues/118>
  480. try:
  481. import sysconfig
  482. except:
  483. can_use_sysconfig = False
  484. else:
  485. can_use_sysconfig = True
  486. if can_use_sysconfig:
  487. if python_implementation() == "CPython" and sys.version[[:3]] == '2.7':
  488. can_use_sysconfig = False
  489. if not can_use_sysconfig:
  490. from distutils import sysconfig
  491. sitedir = sysconfig.get_python_lib(False, False, prefix='$pc_py__exec_prefix')
  492. else:
  493. sitedir = sysconfig.get_path('purelib', vars={'platbase':'$pc_py_exec_prefix'})
  494. ], [dnl
  495. sys.stdout.write(sitedir)
  496. ])], [pc_cv_python_exec_dir=`./conftest`],
  497. [AC_MSG_FAILURE([failed to run Python program])])
  498. AC_LANG_POP(Python)[]dnl
  499. case $pc_cv_python_exec_dir in
  500. $pc_py_exec_prefix*)
  501. pc__strip_prefix=`echo "$pc_py_exec_prefix" | sed 's|.|.|g'`
  502. pc_cv_python_exec_dir=`echo "$pc_cv_python_exec_dir" | sed "s,^$pc__strip_prefix/,,"`
  503. ;;
  504. *)
  505. case $pc_py_exec_prefix in
  506. /usr|/System*) ;;
  507. *)
  508. pc_cv_python_exec_dir=lib/python$PYTHON_VERSION/site-packages
  509. ;;
  510. esac
  511. ;;
  512. esac
  513. ])
  514. AC_SUBST([pyexecdir], [\${exec_prefix}/$pc_cv_python_pyexecdir])]) #PY_PYTHON_CHECK_EXEC_LIB_DIR
  515. # PC_PYTHON_EXEC_PACKAGE_DIR
  516. # --------------------------
  517. # $PACKAGE directory under PYTHON_SITE_DIR
  518. AC_DEFUN([PC_PYTHON_EXEC_PACKAGE_DIR],
  519. [AC_REQUIRE([PC_PYTHON_CHECK_EXEC_DIR])[]dnl
  520. AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE_NAME])])
  521. ## -------------------------------------------- ##
  522. ## 4. Looking for specific libs & functionality ##
  523. ## -------------------------------------------- ##
  524. # PC_PYTHON_CHECK_MODULE(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  525. # ----------------------------------------------------------------------
  526. # Macro for checking if a Python library is installed
  527. AC_DEFUN([PC_PYTHON_CHECK_MODULE],
  528. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  529. m4_define([pc_python_safe_mod], m4_bpatsubsts($1, [\.], [_]))
  530. AC_CACHE_CHECK([for Python '$1' library],
  531. [[pc_cv_python_module_]pc_python_safe_mod],
  532. [AC_LANG_PUSH(Python)[]dnl
  533. AC_RUN_IFELSE(
  534. [AC_LANG_PROGRAM([dnl
  535. import sys
  536. try:
  537. import $1
  538. except:
  539. sys.exit(1)
  540. else:
  541. sys.exit(0)
  542. ], [])],
  543. [[pc_cv_python_module_]pc_python_safe_mod="yes"],
  544. [[pc_cv_python_module_]pc_python_safe_mod="no"])
  545. AC_LANG_POP(Python)[]dnl
  546. ])
  547. AS_IF([test "$[pc_cv_python_module_]pc_python_safe_mod" = "no"], [$3], [$2])
  548. ])# PC_PYTHON_CHECK_MODULE
  549. # PC_PYTHON_CHECK_FUNC([LIBRARY], FUNCTION, ARGS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  550. # ---------------------------------------------------------------------------------------
  551. # Check to see if a given function call, optionally from a module, can
  552. # be successfully called
  553. AC_DEFUN([PC_PYTHON_CHECK_FUNC],
  554. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  555. m4_define([pc_python_safe_mod], m4_bpatsubsts($1, [\.], [_]))
  556. AC_CACHE_CHECK([for Python m4_ifnblank($1, '$1.$2()', '$2()') function],
  557. [[pc_cv_python_func_]pc_python_safe_mod[_$2]],
  558. [AC_LANG_PUSH(Python)[]dnl
  559. AC_RUN_IFELSE(
  560. [AC_LANG_PROGRAM([dnl
  561. import sys
  562. m4_ifnblank([$1], [dnl
  563. try:
  564. import $1
  565. except:
  566. sys.exit(1)
  567. ], [])],
  568. [
  569. m4_ifnblank([$1], [
  570. try:
  571. $1.$2($3)], [
  572. try:
  573. $2($3)])
  574. except:
  575. sys.exit(1)
  576. else:
  577. sys.exit(0)
  578. ])],
  579. [[pc_cv_python_func_]pc_python_safe_mod[_$2]="yes"],
  580. [[pc_cv_python_func_]pc_python_safe_mod[_$2]="no"])
  581. AC_LANG_POP(Python)[]dnl
  582. ])
  583. AS_IF([test "$[pc_cv_python_func_]pc_python_safe_mod[_$2]" = "no"], [$5], [$4])
  584. ])# PC_PYTHON_CHECK_FUNC
  585. # PC_PYTHON_CHECK_MODULE_MATCH_VERSION(LIBRARY, VERSION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND)
  586. # -------------------------------------------------
  587. # Macro for checking if a Python library with this version is installed
  588. #
  589. AC_DEFUN([PC_PYTHON_CHECK_MODULE_MATCH_VERSION],
  590. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  591. m4_define([pc_python_safe_mod], m4_bpatsubsts($1, [\.], [_]))
  592. AC_CACHE_CHECK([for Python '$1' library version '$2'],
  593. [[pc_cv_python_module_version]pc_python_safe_mod],
  594. [AC_LANG_PUSH(Python)[]dnl
  595. AC_LINK_IFELSE(
  596. [AC_LANG_PROGRAM([dnl
  597. import sys
  598. try:
  599. import $1
  600. except:
  601. version='no'
  602. else:
  603. for vers_attr in ('__version__', 'version', 'version_info'):
  604. if hasattr($1, vers_attr):
  605. version = getattr($1, vers_attr)
  606. break
  607. else:
  608. version = 'unknown'
  609. sys.stdout.write(version)
  610. ], [])],
  611. [[pc_cv_python_module_version]pc_python_safe_mod=`./conftest`],
  612. [AC_MSG_FAILURE([failed to run Python program])])
  613. AC_LANG_POP(Python)[]dnl
  614. ])
  615. AS_IF([test "x$[pc_cv_python_module_version]pc_python_safe_mod" = "x$2" ],
  616. [$3],
  617. [ AS_IF(
  618. [test "x$[pc_cv_python_module_version]pc_python_safe_mod" = 'unknown'],
  619. AC_MSG_WARN([Unable to fetch version of Python module $1]))
  620. [$4]
  621. ])
  622. ])# PC_PYTHON_CHECK_MODULE_VERSION
  623. # PC_PYTHON_CHECK_MODULE_VERSION(LIBRARY, MIN-VERSION, MAX-VERSION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND)
  624. # -------------------------------------------------
  625. # Macro for checking if a Python library with this version is installed
  626. #
  627. AC_DEFUN([PC_PYTHON_CHECK_MODULE_VERSION],
  628. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  629. m4_define([pc_python_safe_mod], m4_bpatsubsts($1, [\.], [_]))
  630. m4_append([pc_python_safe_mod], m4_bpatsubsts($2, [\.], [_]))
  631. m4_append([pc_python_safe_mod], m4_bpatsubsts($3, [\.], [_]))
  632. AC_CACHE_CHECK(
  633. [for Python '$1' library m4_ifnblank([$2],['$2' <= ]) version m4_ifnblank([$3], [<= '$3'])],
  634. [[pc_cv_python_module_version]pc_python_safe_mod],
  635. [AC_LANG_PUSH(Python)[]dnl
  636. AC_LINK_IFELSE(
  637. [AC_LANG_PROGRAM([dnl
  638. import sys
  639. def cmp_vers(v1,v2):
  640. v1 = v1.split('.')
  641. v2 = v2.split('.')
  642. for i in range(max([len](v1), [len](v2))):
  643. v1v = int(v1[[i]] if i < [len](v1) else 0)
  644. v2v = int(v2[[i]] if i < [len](v2) else 0)
  645. if v1v > v2v:
  646. return 1
  647. if v1v < v2v:
  648. return -1
  649. return 0
  650. try:
  651. import $1
  652. except:
  653. result='not found'
  654. else:
  655. result='yes'
  656. vmin = '$2'
  657. vmax = '$3'
  658. for vers_attr in ('__version__', 'version', 'version_info'):
  659. if hasattr($1, vers_attr):
  660. version = getattr($1, vers_attr)
  661. break
  662. else:
  663. result = 'unknown'
  664. if version not in ('unknonwn', 'no'):
  665. failmsg = "but "+ version + " found"
  666. if [len](vmin) > 0:
  667. if cmp_vers(version, vmin) < 0:
  668. result = failmsg
  669. if [len](vmax) > 0:
  670. if cmp_vers(version, vmax) > 0:
  671. result = failmsg
  672. sys.stdout.write(result)
  673. ], [])],
  674. [[pc_cv_python_module_version]pc_python_safe_mod=`./conftest`],
  675. [AC_MSG_FAILURE([failed to run Python program])])
  676. AC_LANG_POP(Python)[]dnl
  677. ])
  678. AS_IF( [test "$[pc_cv_python_module_version]pc_python_safe_mod" = "yes"],
  679. [$4],
  680. [ AS_IF(
  681. [test "x$[pc_cv_python_module_version]pc_python_safe_mod" = 'unknown'],
  682. AC_MSG_WARN([Unable to fetch version of Python module $1]))
  683. [$5]
  684. ])
  685. ])# PC_PYTHON_CHECK_MODULE_VERSION