Lines 1-10
Link Here
|
1 |
# =========================================================================== |
1 |
# =========================================================================== |
2 |
# http://autoconf-archive.cryp.to/ac_python_devel.html |
2 |
# http://www.gnu.org/software/autoconf-archive/ax_python_devel.html |
3 |
# =========================================================================== |
3 |
# =========================================================================== |
4 |
# |
4 |
# |
5 |
# SYNOPSIS |
5 |
# SYNOPSIS |
6 |
# |
6 |
# |
7 |
# AC_PYTHON_DEVEL([version]) |
7 |
# AX_PYTHON_DEVEL([version]) |
8 |
# |
8 |
# |
9 |
# DESCRIPTION |
9 |
# DESCRIPTION |
10 |
# |
10 |
# |
Lines 12-19
Link Here
|
12 |
# in your configure.ac. |
12 |
# in your configure.ac. |
13 |
# |
13 |
# |
14 |
# This macro checks for Python and tries to get the include path to |
14 |
# This macro checks for Python and tries to get the include path to |
15 |
# 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS) |
15 |
# 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LIBS) output |
16 |
# output variables. It also exports $(PYTHON_EXTRA_LIBS) and |
16 |
# variables. It also exports $(PYTHON_EXTRA_LIBS) and |
17 |
# $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code. |
17 |
# $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code. |
18 |
# |
18 |
# |
19 |
# You can search for some particular version of Python by passing a |
19 |
# You can search for some particular version of Python by passing a |
Lines 31-48
Link Here
|
31 |
# If you need to use this macro for an older Python version, please |
31 |
# If you need to use this macro for an older Python version, please |
32 |
# contact the authors. We're always open for feedback. |
32 |
# contact the authors. We're always open for feedback. |
33 |
# |
33 |
# |
34 |
# LAST MODIFICATION |
34 |
# LICENSE |
35 |
# |
35 |
# |
36 |
# 2008-04-12 |
36 |
# Copyright (c) 2009 Sebastian Huber <sebastian-huber@web.de> |
37 |
# |
37 |
# Copyright (c) 2009 Alan W. Irwin |
38 |
# COPYLEFT |
38 |
# Copyright (c) 2009 Rafael Laboissiere <rafael@laboissiere.net> |
39 |
# |
39 |
# Copyright (c) 2009 Andrew Collier |
40 |
# Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de> |
40 |
# Copyright (c) 2009 Matteo Settenvini <matteo@member.fsf.org> |
41 |
# Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca> |
41 |
# Copyright (c) 2009 Horst Knorr <hk_classes@knoda.org> |
42 |
# Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net> |
42 |
# Copyright (c) 2013 Daniel Mullner <muellner@math.stanford.edu> |
43 |
# Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za> |
|
|
44 |
# Copyright (c) 2008 Matteo Settenvini <matteo@member.fsf.org> |
45 |
# Copyright (c) 2008 Horst Knorr <hk_classes@knoda.org> |
46 |
# |
43 |
# |
47 |
# This program is free software: you can redistribute it and/or modify it |
44 |
# This program is free software: you can redistribute it and/or modify it |
48 |
# under the terms of the GNU General Public License as published by the |
45 |
# under the terms of the GNU General Public License as published by the |
Lines 66-76
Link Here
|
66 |
# all other use of the material that constitutes the Autoconf Macro. |
63 |
# all other use of the material that constitutes the Autoconf Macro. |
67 |
# |
64 |
# |
68 |
# This special exception to the GPL applies to versions of the Autoconf |
65 |
# This special exception to the GPL applies to versions of the Autoconf |
69 |
# Macro released by the Autoconf Macro Archive. When you make and |
66 |
# Macro released by the Autoconf Archive. When you make and distribute a |
70 |
# distribute a modified version of the Autoconf Macro, you may extend this |
67 |
# modified version of the Autoconf Macro, you may extend this special |
71 |
# special exception to the GPL to apply to your modified version as well. |
68 |
# exception to the GPL to apply to your modified version as well. |
72 |
|
69 |
|
73 |
AC_DEFUN([AC_PYTHON_DEVEL],[ |
70 |
#serial 18 |
|
|
71 |
|
72 |
AU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL]) |
73 |
AC_DEFUN([AX_PYTHON_DEVEL],[ |
74 |
# |
74 |
# |
75 |
# Allow the use of a (user set) custom python version |
75 |
# Allow the use of a (user set) custom python version |
76 |
# |
76 |
# |
Lines 90-97
Link Here
|
90 |
# |
90 |
# |
91 |
AC_MSG_CHECKING([for a version of Python >= '2.1.0']) |
91 |
AC_MSG_CHECKING([for a version of Python >= '2.1.0']) |
92 |
ac_supports_python_ver=`$PYTHON -c "import sys; \ |
92 |
ac_supports_python_ver=`$PYTHON -c "import sys; \ |
93 |
ver = sys.version.split()[[0]]; \ |
93 |
ver = sys.version.split ()[[0]]; \ |
94 |
print(ver >= '2.1.0')"` |
94 |
print (ver >= '2.1.0')"` |
95 |
if test "$ac_supports_python_ver" != "True"; then |
95 |
if test "$ac_supports_python_ver" != "True"; then |
96 |
if test -z "$PYTHON_NOVERSIONCHECK"; then |
96 |
if test -z "$PYTHON_NOVERSIONCHECK"; then |
97 |
AC_MSG_RESULT([no]) |
97 |
AC_MSG_RESULT([no]) |
Lines 99-105
Link Here
|
99 |
This version of the AC@&t@_PYTHON_DEVEL macro |
99 |
This version of the AC@&t@_PYTHON_DEVEL macro |
100 |
doesn't work properly with versions of Python before |
100 |
doesn't work properly with versions of Python before |
101 |
2.1.0. You may need to re-run configure, setting the |
101 |
2.1.0. You may need to re-run configure, setting the |
102 |
variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG, |
102 |
variables PYTHON_CPPFLAGS, PYTHON_LIBS, PYTHON_SITE_PKG, |
103 |
PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand. |
103 |
PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand. |
104 |
Moreover, to disable this check, set PYTHON_NOVERSIONCHECK |
104 |
Moreover, to disable this check, set PYTHON_NOVERSIONCHECK |
105 |
to something else than an empty string. |
105 |
to something else than an empty string. |
Lines 117-126
Link Here
|
117 |
if test -n "$1"; then |
117 |
if test -n "$1"; then |
118 |
AC_MSG_CHECKING([for a version of Python $1]) |
118 |
AC_MSG_CHECKING([for a version of Python $1]) |
119 |
ac_supports_python_ver=`$PYTHON -c "import sys; \ |
119 |
ac_supports_python_ver=`$PYTHON -c "import sys; \ |
120 |
ver = sys.version.split()[[0]]; \ |
120 |
ver = sys.version.split ()[[0]]; \ |
121 |
print(ver >= '2.1.0')"` |
121 |
print (ver $1)"` |
122 |
if test "$ac_supports_python_ver" = "True"; then |
122 |
if test "$ac_supports_python_ver" = "True"; then |
123 |
AC_MSG_RESULT([yes]) |
123 |
AC_MSG_RESULT([yes]) |
124 |
else |
124 |
else |
125 |
AC_MSG_RESULT([no]) |
125 |
AC_MSG_RESULT([no]) |
126 |
AC_MSG_ERROR([this package requires Python $1. |
126 |
AC_MSG_ERROR([this package requires Python $1. |
Lines 153-161
Link Here
|
153 |
AC_MSG_CHECKING([for Python include path]) |
153 |
AC_MSG_CHECKING([for Python include path]) |
154 |
if test -z "$PYTHON_CPPFLAGS"; then |
154 |
if test -z "$PYTHON_CPPFLAGS"; then |
155 |
python_path=`$PYTHON -c "import distutils.sysconfig; \ |
155 |
python_path=`$PYTHON -c "import distutils.sysconfig; \ |
156 |
print(distutils.sysconfig.get_python_inc());"` |
156 |
print (distutils.sysconfig.get_python_inc ());"` |
|
|
157 |
plat_python_path=`$PYTHON -c "import distutils.sysconfig; \ |
158 |
print (distutils.sysconfig.get_python_inc (plat_specific=1));"` |
157 |
if test -n "${python_path}"; then |
159 |
if test -n "${python_path}"; then |
158 |
python_path="-I$python_path" |
160 |
if test "${plat_python_path}" != "${python_path}"; then |
|
|
161 |
python_path="-I$python_path -I$plat_python_path" |
162 |
else |
163 |
python_path="-I$python_path" |
164 |
fi |
159 |
fi |
165 |
fi |
160 |
PYTHON_CPPFLAGS=$python_path |
166 |
PYTHON_CPPFLAGS=$python_path |
161 |
fi |
167 |
fi |
Lines 166-191
Link Here
|
166 |
# Check for Python library path |
172 |
# Check for Python library path |
167 |
# |
173 |
# |
168 |
AC_MSG_CHECKING([for Python library path]) |
174 |
AC_MSG_CHECKING([for Python library path]) |
169 |
if test -z "$PYTHON_LDFLAGS"; then |
175 |
if test -z "$PYTHON_LIBS"; then |
170 |
# (makes two attempts to ensure we've got a version number |
176 |
# (makes two attempts to ensure we've got a version number |
171 |
# from the interpreter) |
177 |
# from the interpreter) |
172 |
py_version=`$PYTHON -c "from distutils.sysconfig import *; \ |
178 |
ac_python_version=`cat<<EOD | $PYTHON - |
173 |
print(' '.join(get_config_vars('VERSION')))"` |
179 |
|
174 |
if test "$py_version" = "[None]"; then |
180 |
# join all versioning strings, on some systems |
|
|
181 |
# major/minor numbers could be in different list elements |
182 |
from distutils.sysconfig import * |
183 |
e = get_config_var('VERSION') |
184 |
if e is not None: |
185 |
print(e) |
186 |
EOD` |
187 |
|
188 |
if test -z "$ac_python_version"; then |
175 |
if test -n "$PYTHON_VERSION"; then |
189 |
if test -n "$PYTHON_VERSION"; then |
176 |
py_version=$PYTHON_VERSION |
190 |
ac_python_version=$PYTHON_VERSION |
177 |
else |
191 |
else |
178 |
py_version=`$PYTHON -c "import sys; \ |
192 |
ac_python_version=`$PYTHON -c "import sys; \ |
179 |
print(sys.version[[:3]]")` |
193 |
print (sys.version[[:3]])"` |
180 |
fi |
194 |
fi |
181 |
fi |
195 |
fi |
182 |
|
196 |
|
183 |
PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \ |
197 |
# Make the versioning information available to the compiler |
184 |
print('-L' + get_python_lib(0,1) + \ |
198 |
AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"], |
185 |
' -lpython');"`$py_version |
199 |
[If available, contains the Python version number currently in use.]) |
|
|
200 |
|
201 |
# First, the library directory: |
202 |
ac_python_libdir=`cat<<EOD | $PYTHON - |
203 |
|
204 |
# There should be only one |
205 |
import distutils.sysconfig |
206 |
e = distutils.sysconfig.get_config_var('LIBDIR') |
207 |
if e is not None: |
208 |
print (e) |
209 |
EOD` |
210 |
|
211 |
# Now, for the library: |
212 |
ac_python_library=`cat<<EOD | $PYTHON - |
213 |
|
214 |
import distutils.sysconfig |
215 |
c = distutils.sysconfig.get_config_vars() |
216 |
if 'LDVERSION' in c: |
217 |
print ('python'+c[['LDVERSION']]) |
218 |
else: |
219 |
print ('python'+c[['VERSION']]) |
220 |
EOD` |
221 |
|
222 |
# This small piece shamelessly adapted from PostgreSQL python macro; |
223 |
# credits goes to momjian, I think. I'd like to put the right name |
224 |
# in the credits, if someone can point me in the right direction... ? |
225 |
# |
226 |
if test -n "$ac_python_libdir" -a -n "$ac_python_library" |
227 |
then |
228 |
# use the official shared library |
229 |
ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"` |
230 |
PYTHON_LIBS="-L$ac_python_libdir -l$ac_python_library" |
231 |
else |
232 |
# old way: use libpython from python_configdir |
233 |
ac_python_libdir=`$PYTHON -c \ |
234 |
"from distutils.sysconfig import get_python_lib as f; \ |
235 |
import os; \ |
236 |
print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"` |
237 |
PYTHON_LIBS="-L$ac_python_libdir -lpython$ac_python_version" |
238 |
fi |
239 |
|
240 |
if test -z "PYTHON_LIBS"; then |
241 |
AC_MSG_ERROR([ |
242 |
Cannot determine location of your Python DSO. Please check it was installed with |
243 |
dynamic libraries enabled, or try setting PYTHON_LIBS by hand. |
244 |
]) |
245 |
fi |
186 |
fi |
246 |
fi |
187 |
AC_MSG_RESULT([$PYTHON_LDFLAGS]) |
247 |
AC_MSG_RESULT([$PYTHON_LIBS]) |
188 |
AC_SUBST([PYTHON_LDFLAGS]) |
248 |
AC_SUBST([PYTHON_LIBS]) |
189 |
|
249 |
|
190 |
# |
250 |
# |
191 |
# Check for site packages |
251 |
# Check for site packages |
Lines 193-199
Link Here
|
193 |
AC_MSG_CHECKING([for Python site-packages path]) |
253 |
AC_MSG_CHECKING([for Python site-packages path]) |
194 |
if test -z "$PYTHON_SITE_PKG"; then |
254 |
if test -z "$PYTHON_SITE_PKG"; then |
195 |
PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \ |
255 |
PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \ |
196 |
print(distutils.sysconfig.get_python_lib(0,0))"` |
256 |
print (distutils.sysconfig.get_python_lib(0,0));"` |
197 |
fi |
257 |
fi |
198 |
AC_MSG_RESULT([$PYTHON_SITE_PKG]) |
258 |
AC_MSG_RESULT([$PYTHON_SITE_PKG]) |
199 |
AC_SUBST([PYTHON_SITE_PKG]) |
259 |
AC_SUBST([PYTHON_SITE_PKG]) |
Lines 202-249
Link Here
|
202 |
# libraries which must be linked in when embedding |
262 |
# libraries which must be linked in when embedding |
203 |
# |
263 |
# |
204 |
AC_MSG_CHECKING(python extra libraries) |
264 |
AC_MSG_CHECKING(python extra libraries) |
205 |
if test -z "$PYTHON_EXTRA_LIBS"; then |
265 |
if test -z "$PYTHON_EXTRA_LDFLAGS"; then |
206 |
PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \ |
266 |
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \ |
207 |
conf = distutils.sysconfig.get_config_var; \ |
267 |
conf = distutils.sysconfig.get_config_var; \ |
208 |
print(conf('LOCALMODLIBS'), conf('LIBS'))"` |
268 |
print (conf('LIBS') + ' ' + conf('SYSLIBS'))"` |
209 |
fi |
269 |
fi |
210 |
AC_MSG_RESULT([$PYTHON_EXTRA_LIBS]) |
270 |
AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS]) |
211 |
AC_SUBST(PYTHON_EXTRA_LIBS) |
271 |
AC_SUBST(PYTHON_EXTRA_LDFLAGS) |
212 |
|
272 |
|
213 |
# |
273 |
# |
214 |
# linking flags needed when embedding |
274 |
# linking flags needed when embedding |
215 |
# |
275 |
# |
216 |
AC_MSG_CHECKING(python extra linking flags) |
276 |
AC_MSG_CHECKING(python extra linking flags) |
217 |
if test -z "$PYTHON_EXTRA_LDFLAGS"; then |
277 |
if test -z "$PYTHON_EXTRA_LIBS"; then |
218 |
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \ |
278 |
PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \ |
219 |
conf = distutils.sysconfig.get_config_var; \ |
279 |
conf = distutils.sysconfig.get_config_var; \ |
220 |
print(conf('LINKFORSHARED'))"` |
280 |
print (conf('LINKFORSHARED'))"` |
221 |
fi |
281 |
fi |
222 |
AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS]) |
282 |
AC_MSG_RESULT([$PYTHON_EXTRA_LIBS]) |
223 |
AC_SUBST(PYTHON_EXTRA_LDFLAGS) |
283 |
AC_SUBST(PYTHON_EXTRA_LIBS) |
224 |
|
284 |
|
225 |
# |
285 |
# |
226 |
# final check to see if everything compiles alright |
286 |
# final check to see if everything compiles alright |
227 |
# |
287 |
# |
228 |
AC_MSG_CHECKING([consistency of all components of python development environment]) |
288 |
AC_MSG_CHECKING([consistency of all components of python development environment]) |
229 |
AC_LANG_PUSH([C]) |
|
|
230 |
# save current global flags |
289 |
# save current global flags |
231 |
LIBS="$ac_save_LIBS $PYTHON_LDFLAGS" |
290 |
ac_save_LIBS="$LIBS" |
|
|
291 |
ac_save_LDFLAGS="$LDFLAGS" |
292 |
ac_save_CPPFLAGS="$CPPFLAGS" |
293 |
LIBS="$ac_save_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_EXTRA_LIBS" |
294 |
LDFLAGS="$ac_save_LDFLAGS $PYTHON_EXTRA_LDFLAGS" |
232 |
CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS" |
295 |
CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS" |
233 |
AC_TRY_LINK([ |
296 |
AC_LANG_PUSH([C]) |
234 |
#include <Python.h> |
297 |
AC_LINK_IFELSE([ |
235 |
],[ |
298 |
AC_LANG_PROGRAM([[#include <Python.h>]], |
236 |
Py_Initialize(); |
299 |
[[Py_Initialize();]]) |
237 |
],[pythonexists=yes],[pythonexists=no]) |
300 |
],[pythonexists=yes],[pythonexists=no]) |
|
|
301 |
AC_LANG_POP([C]) |
302 |
# turn back to default flags |
303 |
CPPFLAGS="$ac_save_CPPFLAGS" |
304 |
LIBS="$ac_save_LIBS" |
305 |
LDFLAGS="$ac_save_LDFLAGS" |
238 |
|
306 |
|
239 |
AC_MSG_RESULT([$pythonexists]) |
307 |
AC_MSG_RESULT([$pythonexists]) |
240 |
|
308 |
|
241 |
if test ! "$pythonexists" = "yes"; then |
309 |
if test ! "x$pythonexists" = "xyes"; then |
242 |
AC_MSG_ERROR([ |
310 |
AC_MSG_FAILURE([ |
243 |
Could not link test program to Python. Maybe the main Python library has been |
311 |
Could not link test program to Python. Maybe the main Python library has been |
244 |
installed in some non-standard library path. If so, pass it to configure, |
312 |
installed in some non-standard library path. If so, pass it to configure, |
245 |
via the LDFLAGS environment variable. |
313 |
via the LIBS environment variable. |
246 |
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib" |
314 |
Example: ./configure LIBS="-L/usr/non-standard-path/python/lib" |
247 |
============================================================================ |
315 |
============================================================================ |
248 |
ERROR! |
316 |
ERROR! |
249 |
You probably have to install the development version of the Python package |
317 |
You probably have to install the development version of the Python package |
Lines 252-261
Link Here
|
252 |
]) |
320 |
]) |
253 |
PYTHON_VERSION="" |
321 |
PYTHON_VERSION="" |
254 |
fi |
322 |
fi |
255 |
AC_LANG_POP |
|
|
256 |
# turn back to default flags |
257 |
CPPFLAGS="$ac_save_CPPFLAGS" |
258 |
LIBS="$ac_save_LIBS" |
259 |
|
323 |
|
260 |
# |
324 |
# |
261 |
# all done! |
325 |
# all done! |