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