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.m4 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. if python_implementation() == "CPython" and sys.version[[:3]] == '2.7':
  425. can_use_sysconfig = False
  426. if not can_use_sysconfig:
  427. from distutils import sysconfig
  428. sitedir = sysconfig.get_python_lib(False, False, prefix='$pc_py_prefix')
  429. else:
  430. sitedir = sysconfig.get_path('purelib', vars={'base':'$pc_py_prefix'})
  431. ], [dnl
  432. sys.stdout.write(sitedir)
  433. ])], [pc_cv_python_site_dir=`./conftest`],
  434. [AC_MSG_FAILURE([failed to run Python program])])
  435. AC_LANG_POP(Python)[]dnl
  436. case $pc_cv_python_site_dir in
  437. $pc_py_prefix*)
  438. pc__strip_prefix=`echo "$pc_py_prefix" | sed 's|.|.|g'`
  439. pc_cv_python_site_dir=`echo "$pc_cv_python_site_dir" | sed "s,^$pc__strip_prefix/,,"`
  440. ;;
  441. *)
  442. case $pc_py_prefix in
  443. /usr|/System*) ;;
  444. *)
  445. pc_cv_python_site_dir=lib/python$PYTHON_VERSION/site-packages
  446. ;;
  447. esac
  448. ;;
  449. esac
  450. ])
  451. AC_SUBST([pythondir], [\${prefix}/$pc_cv_python_site_dir])])# PC_PYTHON_CHECK_SITE_DIR
  452. # PC_PYTHON_SITE_PACKAGE_DIR
  453. # --------------------------
  454. # $PACKAGE directory under PYTHON_SITE_DIR
  455. AC_DEFUN([PC_PYTHON_SITE_PACKAGE_DIR],
  456. [AC_REQUIRE([PC_PYTHON_CHECK_SITE_DIR])[]dnl
  457. AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE_NAME])])
  458. # PC_PYTHON_CHECK_EXEC_DIR
  459. # ------------------------
  460. # directory for installing python extension modules (shared libraries)
  461. AC_DEFUN([PC_PYTHON_CHECK_EXEC_DIR],
  462. [AC_REQUIRE([PC_PROG_PYTHON])AC_REQUIRE([PC_PYTHON_CHECK_EXEC_PREFIX])[]dnl
  463. AC_CACHE_CHECK([for Python extension module directory],
  464. [pc_cv_python_exec_dir],
  465. [AC_LANG_PUSH(Python)[]dnl
  466. if test "x$pc_cv_python_exec_prefix" = xNONE
  467. then
  468. pc_py_exec_prefix=$pc_cv_python_prefix
  469. else
  470. pc_py_exec_prefix=$pc_cv_python_exec_prefix
  471. fi
  472. AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
  473. import sys
  474. from platform import python_implementation
  475. # sysconfig in CPython 2.7 doesn't work in virtualenv
  476. # <https://github.com/pypa/virtualenv/issues/118>
  477. try:
  478. import sysconfig
  479. except:
  480. can_use_sysconfig = False
  481. else:
  482. can_use_sysconfig = True
  483. if can_use_sysconfig:
  484. if python_implementation() == "CPython" and sys.version[[:3]] == '2.7':
  485. can_use_sysconfig = False
  486. if not can_use_sysconfig:
  487. from distutils import sysconfig
  488. sitedir = sysconfig.get_python_lib(False, False, prefix='$pc_py__exec_prefix')
  489. else:
  490. sitedir = sysconfig.get_path('purelib', vars={'platbase':'$pc_py_exec_prefix'})
  491. ], [dnl
  492. sys.stdout.write(sitedir)
  493. ])], [pc_cv_python_exec_dir=`./conftest`],
  494. [AC_MSG_FAILURE([failed to run Python program])])
  495. AC_LANG_POP(Python)[]dnl
  496. case $pc_cv_python_exec_dir in
  497. $pc_py_exec_prefix*)
  498. pc__strip_prefix=`echo "$pc_py_exec_prefix" | sed 's|.|.|g'`
  499. pc_cv_python_exec_dir=`echo "$pc_cv_python_exec_dir" | sed "s,^$pc__strip_prefix/,,"`
  500. ;;
  501. *)
  502. case $pc_py_exec_prefix in
  503. /usr|/System*) ;;
  504. *)
  505. pc_cv_python_exec_dir=lib/python$PYTHON_VERSION/site-packages
  506. ;;
  507. esac
  508. ;;
  509. esac
  510. ])
  511. AC_SUBST([pyexecdir], [\${exec_prefix}/$pc_cv_python_pyexecdir])]) #PY_PYTHON_CHECK_EXEC_LIB_DIR
  512. # PC_PYTHON_EXEC_PACKAGE_DIR
  513. # --------------------------
  514. # $PACKAGE directory under PYTHON_SITE_DIR
  515. AC_DEFUN([PC_PYTHON_EXEC_PACKAGE_DIR],
  516. [AC_REQUIRE([PC_PYTHON_CHECK_EXEC_DIR])[]dnl
  517. AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE_NAME])])
  518. ## -------------------------------------------- ##
  519. ## 4. Looking for specific libs & functionality ##
  520. ## -------------------------------------------- ##
  521. # PC_PYTHON_CHECK_MODULE(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  522. # ----------------------------------------------------------------------
  523. # Macro for checking if a Python library is installed
  524. AC_DEFUN([PC_PYTHON_CHECK_MODULE],
  525. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  526. m4_define([pc_python_safe_mod], m4_bpatsubsts($1, [\.], [_]))
  527. AC_CACHE_CHECK([for Python '$1' library],
  528. [[pc_cv_python_module_]pc_python_safe_mod],
  529. [AC_LANG_PUSH(Python)[]dnl
  530. AC_RUN_IFELSE(
  531. [AC_LANG_PROGRAM([dnl
  532. import sys
  533. try:
  534. import $1
  535. except:
  536. sys.exit(1)
  537. else:
  538. sys.exit(0)
  539. ], [])],
  540. [[pc_cv_python_module_]pc_python_safe_mod="yes"],
  541. [[pc_cv_python_module_]pc_python_safe_mod="no"])
  542. AC_LANG_POP(Python)[]dnl
  543. ])
  544. AS_IF([test "$[pc_cv_python_module_]pc_python_safe_mod" = "no"], [$3], [$2])
  545. ])# PC_PYTHON_CHECK_MODULE
  546. # PC_PYTHON_CHECK_FUNC([LIBRARY], FUNCTION, ARGS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  547. # ---------------------------------------------------------------------------------------
  548. # Check to see if a given function call, optionally from a module, can
  549. # be successfully called
  550. AC_DEFUN([PC_PYTHON_CHECK_FUNC],
  551. [AC_REQUIRE([PC_PROG_PYTHON])[]dnl
  552. m4_define([pc_python_safe_mod], m4_bpatsubsts($1, [\.], [_]))
  553. AC_CACHE_CHECK([for Python m4_ifnblank($1, '$1.$2()', '$2()') function],
  554. [[pc_cv_python_func_]pc_python_safe_mod[_$2]],
  555. [AC_LANG_PUSH(Python)[]dnl
  556. AC_RUN_IFELSE(
  557. [AC_LANG_PROGRAM([dnl
  558. import sys
  559. m4_ifnblank([$1], [dnl
  560. try:
  561. import $1
  562. except:
  563. sys.exit(1)
  564. ], [])],
  565. [
  566. m4_ifnblank([$1], [
  567. try:
  568. $1.$2($3)], [
  569. try:
  570. $2($3)])
  571. except:
  572. sys.exit(1)
  573. else:
  574. sys.exit(0)
  575. ])],
  576. [[pc_cv_python_func_]pc_python_safe_mod[_$2]="yes"],
  577. [[pc_cv_python_func_]pc_python_safe_mod[_$2]="no"])
  578. AC_LANG_POP(Python)[]dnl
  579. ])
  580. AS_IF([test "$[pc_cv_python_func_]pc_python_safe_mod[_$2]" = "no"], [$5], [$4])
  581. ])# PC_PYTHON_CHECK_FUNC