jamie@126
|
1 # ===========================================================================
|
jamie@126
|
2 # http://www.gnu.org/software/autoconf-archive/ax_python_devel.html
|
jamie@126
|
3 # ===========================================================================
|
jamie@126
|
4 #
|
jamie@126
|
5 # SYNOPSIS
|
jamie@126
|
6 #
|
jamie@126
|
7 # AX_PYTHON_DEVEL([version])
|
jamie@126
|
8 #
|
jamie@126
|
9 # DESCRIPTION
|
jamie@126
|
10 #
|
jamie@126
|
11 # Note: Defines as a precious variable "PYTHON_VERSION". Don't override it
|
jamie@126
|
12 # in your configure.ac.
|
jamie@126
|
13 #
|
jamie@126
|
14 # This macro checks for Python and tries to get the include path to
|
jamie@126
|
15 # 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS)
|
jamie@126
|
16 # output variables. It also exports $(PYTHON_EXTRA_LIBS) and
|
jamie@126
|
17 # $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
|
jamie@126
|
18 #
|
jamie@126
|
19 # You can search for some particular version of Python by passing a
|
jamie@126
|
20 # parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
|
jamie@126
|
21 # note that you *have* to pass also an operator along with the version to
|
jamie@126
|
22 # match, and pay special attention to the single quotes surrounding the
|
jamie@126
|
23 # version number. Don't use "PYTHON_VERSION" for this: that environment
|
jamie@126
|
24 # variable is declared as precious and thus reserved for the end-user.
|
jamie@126
|
25 #
|
jamie@126
|
26 # This macro should work for all versions of Python >= 2.1.0. As an end
|
jamie@126
|
27 # user, you can disable the check for the python version by setting the
|
jamie@126
|
28 # PYTHON_NOVERSIONCHECK environment variable to something else than the
|
jamie@126
|
29 # empty string.
|
jamie@126
|
30 #
|
jamie@126
|
31 # If you need to use this macro for an older Python version, please
|
jamie@126
|
32 # contact the authors. We're always open for feedback.
|
jamie@126
|
33 #
|
jamie@126
|
34 # LICENSE
|
jamie@126
|
35 #
|
jamie@126
|
36 # Copyright (c) 2009 Sebastian Huber <sebastian-huber@web.de>
|
jamie@126
|
37 # Copyright (c) 2009 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
|
jamie@126
|
38 # Copyright (c) 2009 Rafael Laboissiere <rafael@laboissiere.net>
|
jamie@126
|
39 # Copyright (c) 2009 Andrew Collier <colliera@ukzn.ac.za>
|
jamie@126
|
40 # Copyright (c) 2009 Matteo Settenvini <matteo@member.fsf.org>
|
jamie@126
|
41 # Copyright (c) 2009 Horst Knorr <hk_classes@knoda.org>
|
jamie@126
|
42 #
|
jamie@126
|
43 # This program is free software: you can redistribute it and/or modify it
|
jamie@126
|
44 # under the terms of the GNU General Public License as published by the
|
jamie@126
|
45 # Free Software Foundation, either version 3 of the License, or (at your
|
jamie@126
|
46 # option) any later version.
|
jamie@126
|
47 #
|
jamie@126
|
48 # This program is distributed in the hope that it will be useful, but
|
jamie@126
|
49 # WITHOUT ANY WARRANTY; without even the implied warranty of
|
jamie@126
|
50 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
jamie@126
|
51 # Public License for more details.
|
jamie@126
|
52 #
|
jamie@126
|
53 # You should have received a copy of the GNU General Public License along
|
jamie@126
|
54 # with this program. If not, see <http://www.gnu.org/licenses/>.
|
jamie@126
|
55 #
|
jamie@126
|
56 # As a special exception, the respective Autoconf Macro's copyright owner
|
jamie@126
|
57 # gives unlimited permission to copy, distribute and modify the configure
|
jamie@126
|
58 # scripts that are the output of Autoconf when processing the Macro. You
|
jamie@126
|
59 # need not follow the terms of the GNU General Public License when using
|
jamie@126
|
60 # or distributing such scripts, even though portions of the text of the
|
jamie@126
|
61 # Macro appear in them. The GNU General Public License (GPL) does govern
|
jamie@126
|
62 # all other use of the material that constitutes the Autoconf Macro.
|
jamie@126
|
63 #
|
jamie@126
|
64 # This special exception to the GPL applies to versions of the Autoconf
|
jamie@126
|
65 # Macro released by the Autoconf Archive. When you make and distribute a
|
jamie@126
|
66 # modified version of the Autoconf Macro, you may extend this special
|
jamie@126
|
67 # exception to the GPL to apply to your modified version as well.
|
jamie@126
|
68
|
jamie@126
|
69 #serial 8
|
jamie@126
|
70
|
jamie@126
|
71 AU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL])
|
jamie@126
|
72 AC_DEFUN([AX_PYTHON_DEVEL],[
|
jamie@126
|
73 #
|
jamie@126
|
74 # Allow the use of a (user set) custom python version
|
jamie@126
|
75 #
|
jamie@126
|
76 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
|
jamie@126
|
77 version to use, for example '2.3'. This string
|
jamie@126
|
78 will be appended to the Python interpreter
|
jamie@126
|
79 canonical name.])
|
jamie@126
|
80
|
jamie@126
|
81 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
|
jamie@126
|
82 if test -z "$PYTHON"; then
|
jamie@126
|
83 AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
|
jamie@126
|
84 PYTHON_VERSION=""
|
jamie@126
|
85 fi
|
jamie@126
|
86
|
jamie@126
|
87 #
|
jamie@126
|
88 # Check for a version of Python >= 2.1.0
|
jamie@126
|
89 #
|
jamie@126
|
90 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
|
jamie@126
|
91 ac_supports_python_ver=`$PYTHON -c "import sys; \
|
jamie@126
|
92 ver = sys.version.split ()[[0]]; \
|
jamie@126
|
93 print (ver >= '2.1.0')"`
|
jamie@126
|
94 if test "$ac_supports_python_ver" != "True"; then
|
jamie@126
|
95 if test -z "$PYTHON_NOVERSIONCHECK"; then
|
jamie@126
|
96 AC_MSG_RESULT([no])
|
jamie@126
|
97 AC_MSG_FAILURE([
|
jamie@126
|
98 This version of the AC@&t@_PYTHON_DEVEL macro
|
jamie@126
|
99 doesn't work properly with versions of Python before
|
jamie@126
|
100 2.1.0. You may need to re-run configure, setting the
|
jamie@126
|
101 variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
|
jamie@126
|
102 PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
|
jamie@126
|
103 Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
|
jamie@126
|
104 to something else than an empty string.
|
jamie@126
|
105 ])
|
jamie@126
|
106 else
|
jamie@126
|
107 AC_MSG_RESULT([skip at user request])
|
jamie@126
|
108 fi
|
jamie@126
|
109 else
|
jamie@126
|
110 AC_MSG_RESULT([yes])
|
jamie@126
|
111 fi
|
jamie@126
|
112
|
jamie@126
|
113 #
|
jamie@126
|
114 # if the macro parameter ``version'' is set, honour it
|
jamie@126
|
115 #
|
jamie@126
|
116 if test -n "$1"; then
|
jamie@126
|
117 AC_MSG_CHECKING([for a version of Python $1])
|
jamie@126
|
118 ac_supports_python_ver=`$PYTHON -c "import sys; \
|
jamie@126
|
119 ver = sys.version.split ()[[0]]; \
|
jamie@126
|
120 print (ver $1)"`
|
jamie@126
|
121 if test "$ac_supports_python_ver" = "True"; then
|
jamie@126
|
122 AC_MSG_RESULT([yes])
|
jamie@126
|
123 else
|
jamie@126
|
124 AC_MSG_RESULT([no])
|
jamie@126
|
125 AC_MSG_ERROR([this package requires Python $1.
|
jamie@126
|
126 If you have it installed, but it isn't the default Python
|
jamie@126
|
127 interpreter in your system path, please pass the PYTHON_VERSION
|
jamie@126
|
128 variable to configure. See ``configure --help'' for reference.
|
jamie@126
|
129 ])
|
jamie@126
|
130 PYTHON_VERSION=""
|
jamie@126
|
131 fi
|
jamie@126
|
132 fi
|
jamie@126
|
133
|
jamie@126
|
134 #
|
jamie@126
|
135 # Check if you have distutils, else fail
|
jamie@126
|
136 #
|
jamie@126
|
137 AC_MSG_CHECKING([for the distutils Python package])
|
jamie@126
|
138 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
|
jamie@126
|
139 if test -z "$ac_distutils_result"; then
|
jamie@126
|
140 AC_MSG_RESULT([yes])
|
jamie@126
|
141 else
|
jamie@126
|
142 AC_MSG_RESULT([no])
|
jamie@126
|
143 AC_MSG_ERROR([cannot import Python module "distutils".
|
jamie@126
|
144 Please check your Python installation. The error was:
|
jamie@126
|
145 $ac_distutils_result])
|
jamie@126
|
146 PYTHON_VERSION=""
|
jamie@126
|
147 fi
|
jamie@126
|
148
|
jamie@126
|
149 #
|
jamie@126
|
150 # Check for Python include path
|
jamie@126
|
151 #
|
jamie@126
|
152 AC_MSG_CHECKING([for Python include path])
|
jamie@126
|
153 if test -z "$PYTHON_CPPFLAGS"; then
|
jamie@126
|
154 python_path=`$PYTHON -c "import distutils.sysconfig; \
|
jamie@126
|
155 print (distutils.sysconfig.get_python_inc ());"`
|
jamie@126
|
156 if test -n "${python_path}"; then
|
jamie@126
|
157 python_path="-I$python_path"
|
jamie@126
|
158 fi
|
jamie@126
|
159 PYTHON_CPPFLAGS=$python_path
|
jamie@126
|
160 fi
|
jamie@126
|
161 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
|
jamie@126
|
162 AC_SUBST([PYTHON_CPPFLAGS])
|
jamie@126
|
163
|
jamie@126
|
164 #
|
jamie@126
|
165 # Check for Python library path
|
jamie@126
|
166 #
|
jamie@126
|
167 AC_MSG_CHECKING([for Python library path])
|
jamie@126
|
168 if test -z "$PYTHON_LDFLAGS"; then
|
jamie@126
|
169 # (makes two attempts to ensure we've got a version number
|
jamie@126
|
170 # from the interpreter)
|
jamie@126
|
171 ac_python_version=`cat<<EOD | $PYTHON -
|
jamie@126
|
172
|
jamie@126
|
173 # join all versioning strings, on some systems
|
jamie@126
|
174 # major/minor numbers could be in different list elements
|
jamie@126
|
175 from distutils.sysconfig import *
|
jamie@126
|
176 ret = ''
|
jamie@126
|
177 for e in get_config_vars ('VERSION'):
|
jamie@126
|
178 if (e != None):
|
jamie@126
|
179 ret += e
|
jamie@126
|
180 print (ret)
|
jamie@126
|
181 EOD`
|
jamie@126
|
182
|
jamie@126
|
183 if test -z "$ac_python_version"; then
|
jamie@126
|
184 if test -n "$PYTHON_VERSION"; then
|
jamie@126
|
185 ac_python_version=$PYTHON_VERSION
|
jamie@126
|
186 else
|
jamie@126
|
187 ac_python_version=`$PYTHON -c "import sys; \
|
jamie@126
|
188 print (sys.version[[:3]])"`
|
jamie@126
|
189 fi
|
jamie@126
|
190 fi
|
jamie@126
|
191
|
jamie@126
|
192 # Make the versioning information available to the compiler
|
jamie@126
|
193 AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"],
|
jamie@126
|
194 [If available, contains the Python version number currently in use.])
|
jamie@126
|
195
|
jamie@126
|
196 # First, the library directory:
|
jamie@126
|
197 ac_python_libdir=`cat<<EOD | $PYTHON -
|
jamie@126
|
198
|
jamie@126
|
199 # There should be only one
|
jamie@126
|
200 import distutils.sysconfig
|
jamie@126
|
201 for e in distutils.sysconfig.get_config_vars ('LIBDIR'):
|
jamie@126
|
202 if e != None:
|
jamie@126
|
203 print (e)
|
jamie@126
|
204 break
|
jamie@126
|
205 EOD`
|
jamie@126
|
206
|
jamie@126
|
207 # Before checking for libpythonX.Y, we need to know
|
jamie@126
|
208 # the extension the OS we're on uses for libraries
|
jamie@126
|
209 # (we take the first one, if there's more than one fix me!):
|
jamie@126
|
210 ac_python_soext=`$PYTHON -c \
|
jamie@126
|
211 "import distutils.sysconfig; \
|
jamie@126
|
212 print (distutils.sysconfig.get_config_vars('SO')[[0]])"`
|
jamie@126
|
213
|
jamie@126
|
214 # Now, for the library:
|
jamie@126
|
215 ac_python_soname=`$PYTHON -c \
|
jamie@126
|
216 "import distutils.sysconfig; \
|
jamie@126
|
217 print (distutils.sysconfig.get_config_vars('LDLIBRARY')[[0]])"`
|
jamie@126
|
218
|
jamie@126
|
219 # Strip away extension from the end to canonicalize its name:
|
jamie@126
|
220 ac_python_library=`echo "$ac_python_soname" | sed "s/${ac_python_soext}$//"`
|
jamie@126
|
221
|
jamie@126
|
222 # This small piece shamelessly adapted from PostgreSQL python macro;
|
jamie@126
|
223 # credits goes to momjian, I think. I'd like to put the right name
|
jamie@126
|
224 # in the credits, if someone can point me in the right direction... ?
|
jamie@126
|
225 #
|
jamie@126
|
226 if test -n "$ac_python_libdir" -a -n "$ac_python_library" \
|
jamie@126
|
227 -a x"$ac_python_library" != x"$ac_python_soname"
|
jamie@126
|
228 then
|
jamie@126
|
229 # use the official shared library
|
jamie@126
|
230 ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"`
|
jamie@126
|
231 PYTHON_LDFLAGS="-L$ac_python_libdir -l$ac_python_library"
|
jamie@126
|
232 else
|
jamie@126
|
233 # old way: use libpython from python_configdir
|
jamie@126
|
234 ac_python_libdir=`$PYTHON -c \
|
jamie@126
|
235 "from distutils.sysconfig import get_python_lib as f; \
|
jamie@126
|
236 import os; \
|
jamie@126
|
237 print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"`
|
jamie@126
|
238 PYTHON_LDFLAGS="-L$ac_python_libdir -lpython$ac_python_version"
|
jamie@126
|
239 fi
|
jamie@126
|
240
|
jamie@126
|
241 if test -z "PYTHON_LDFLAGS"; then
|
jamie@126
|
242 AC_MSG_ERROR([
|
jamie@126
|
243 Cannot determine location of your Python DSO. Please check it was installed with
|
jamie@126
|
244 dynamic libraries enabled, or try setting PYTHON_LDFLAGS by hand.
|
jamie@126
|
245 ])
|
jamie@126
|
246 fi
|
jamie@126
|
247 fi
|
jamie@126
|
248 AC_MSG_RESULT([$PYTHON_LDFLAGS])
|
jamie@126
|
249 AC_SUBST([PYTHON_LDFLAGS])
|
jamie@126
|
250
|
jamie@126
|
251 #
|
jamie@126
|
252 # Check for site packages
|
jamie@126
|
253 #
|
jamie@126
|
254 AC_MSG_CHECKING([for Python site-packages path])
|
jamie@126
|
255 if test -z "$PYTHON_SITE_PKG"; then
|
jamie@126
|
256 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
|
jamie@126
|
257 print (distutils.sysconfig.get_python_lib(0,0));"`
|
jamie@126
|
258 fi
|
jamie@126
|
259 AC_MSG_RESULT([$PYTHON_SITE_PKG])
|
jamie@126
|
260 AC_SUBST([PYTHON_SITE_PKG])
|
jamie@126
|
261
|
jamie@126
|
262 #
|
jamie@126
|
263 # libraries which must be linked in when embedding
|
jamie@126
|
264 #
|
jamie@126
|
265 AC_MSG_CHECKING(python extra libraries)
|
jamie@126
|
266 if test -z "$PYTHON_EXTRA_LIBS"; then
|
jamie@126
|
267 PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
|
jamie@126
|
268 conf = distutils.sysconfig.get_config_var; \
|
jamie@126
|
269 print (conf('LOCALMODLIBS') + ' ' + conf('LIBS'))"`
|
jamie@126
|
270 fi
|
jamie@126
|
271 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
|
jamie@126
|
272 AC_SUBST(PYTHON_EXTRA_LIBS)
|
jamie@126
|
273
|
jamie@126
|
274 #
|
jamie@126
|
275 # linking flags needed when embedding
|
jamie@126
|
276 #
|
jamie@126
|
277 AC_MSG_CHECKING(python extra linking flags)
|
jamie@126
|
278 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
|
jamie@126
|
279 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
|
jamie@126
|
280 conf = distutils.sysconfig.get_config_var; \
|
jamie@126
|
281 print (conf('LINKFORSHARED'))"`
|
jamie@126
|
282 fi
|
jamie@126
|
283 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
|
jamie@126
|
284 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
|
jamie@126
|
285
|
jamie@126
|
286 #
|
jamie@126
|
287 # final check to see if everything compiles alright
|
jamie@126
|
288 #
|
jamie@126
|
289 AC_MSG_CHECKING([consistency of all components of python development environment])
|
jamie@126
|
290 # save current global flags
|
jamie@126
|
291 ac_save_LIBS="$LIBS"
|
jamie@126
|
292 ac_save_CPPFLAGS="$CPPFLAGS"
|
jamie@126
|
293 LIBS="$ac_save_LIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LDFLAGS $PYTHON_EXTRA_LIBS"
|
jamie@126
|
294 CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
|
jamie@126
|
295 AC_LANG_PUSH([C])
|
jamie@126
|
296 AC_LINK_IFELSE([
|
jamie@126
|
297 AC_LANG_PROGRAM([[#include <Python.h>]],
|
jamie@126
|
298 [[Py_Initialize();]])
|
jamie@126
|
299 ],[pythonexists=yes],[pythonexists=no])
|
jamie@126
|
300 AC_LANG_POP([C])
|
jamie@126
|
301 # turn back to default flags
|
jamie@126
|
302 CPPFLAGS="$ac_save_CPPFLAGS"
|
jamie@126
|
303 LIBS="$ac_save_LIBS"
|
jamie@126
|
304
|
jamie@126
|
305 AC_MSG_RESULT([$pythonexists])
|
jamie@126
|
306
|
jamie@126
|
307 if test ! "x$pythonexists" = "xyes"; then
|
jamie@126
|
308 AC_MSG_FAILURE([
|
jamie@126
|
309 Could not link test program to Python. Maybe the main Python library has been
|
jamie@126
|
310 installed in some non-standard library path. If so, pass it to configure,
|
jamie@126
|
311 via the LDFLAGS environment variable.
|
jamie@126
|
312 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
|
jamie@126
|
313 ============================================================================
|
jamie@126
|
314 ERROR!
|
jamie@126
|
315 You probably have to install the development version of the Python package
|
jamie@126
|
316 for your distribution. The exact name of this package varies among them.
|
jamie@126
|
317 ============================================================================
|
jamie@126
|
318 ])
|
jamie@126
|
319 PYTHON_VERSION=""
|
jamie@126
|
320 fi
|
jamie@126
|
321
|
jamie@126
|
322 #
|
jamie@126
|
323 # all done!
|
jamie@126
|
324 #
|
jamie@126
|
325 ])
|