~siretart/lcd4linux/debian

« back to all changes in this revision

Viewing changes to ax_python_devel.m4

  • Committer: Reinhard Tartler
  • Date: 2011-04-27 17:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 750.
  • Revision ID: siretart@tauware.de-20110427172415-6n4aptmvmz0eztvm
Tags: upstream-0.11.0~svn1143
ImportĀ upstreamĀ versionĀ 0.11.0~svn1143

Show diffs side-by-side

added added

removed removed

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