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