1 diff --git a/m4/ax_python_devel.m4 b/m4/ax_python_devel.m4
2 --- a/m4/ax_python_devel.m4
3 +++ b/m4/ax_python_devel.m4
5 # ===========================================================================
6 -# https://www.gnu.org/software/autoconf-archive/ax_python_devel.html
7 +# https://www.gnu.org/software/autoconf-archive/ax_python_devel.html
8 # ===========================================================================
12 # in your configure.ac.
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.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LIBS) output
18 +# variables. It also exports $(PYTHON_EXTRA_LIBS) and
19 # $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
21 # You can search for some particular version of Python by passing a
23 # modified version of the Autoconf Macro, you may extend this special
24 # exception to the GPL to apply to your modified version as well.
29 AU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL])
30 AC_DEFUN([AX_PYTHON_DEVEL],[
32 This version of the AC@&t@_PYTHON_DEVEL macro
33 doesn't work properly with versions of Python before
34 2.1.0. You may need to re-run configure, setting the
35 -variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
36 +variables PYTHON_CPPFLAGS, PYTHON_LIBS, PYTHON_SITE_PKG,
37 PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
38 Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
39 to something else than an empty string.
42 # Check if you have distutils, else fail
44 - AC_MSG_CHECKING([for the distutils Python package])
45 - ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
46 - if test -z "$ac_distutils_result"; then
47 + AC_MSG_CHECKING([for the sysconfig Python package])
48 + ac_sysconfig_result=`$PYTHON -c "import sysconfig" 2>&1`
49 + if test $? -eq 0; then
51 + IMPORT_SYSCONFIG="import sysconfig"
54 - AC_MSG_ERROR([cannot import Python module "distutils".
56 + AC_MSG_CHECKING([for the distutils Python package])
57 + ac_sysconfig_result=`$PYTHON -c "from distutils import sysconfig" 2>&1`
58 + if test $? -eq 0; then
59 + AC_MSG_RESULT([yes])
60 + IMPORT_SYSCONFIG="from distutils import sysconfig"
62 + AC_MSG_ERROR([cannot import Python module "distutils".
63 Please check your Python installation. The error was:
64 -$ac_distutils_result])
66 +$ac_sysconfig_result])
74 AC_MSG_CHECKING([for Python include path])
75 if test -z "$PYTHON_CPPFLAGS"; then
76 - python_path=`$PYTHON -c "import distutils.sysconfig; \
77 - print (distutils.sysconfig.get_python_inc ());"`
78 - plat_python_path=`$PYTHON -c "import distutils.sysconfig; \
79 - print (distutils.sysconfig.get_python_inc (plat_specific=1));"`
80 + if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
81 + # sysconfig module has different functions
82 + python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
83 + print (sysconfig.get_path ('include'));"`
84 + plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
85 + print (sysconfig.get_path ('platinclude'));"`
88 + python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
89 + print (sysconfig.get_python_inc ());"`
90 + plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \
91 + print (sysconfig.get_python_inc (plat_specific=1));"`
93 if test -n "${python_path}"; then
94 if test "${plat_python_path}" != "${python_path}"; then
95 python_path="-I$python_path -I$plat_python_path"
97 # Check for Python library path
99 AC_MSG_CHECKING([for Python library path])
100 - if test -z "$PYTHON_LDFLAGS"; then
101 + if test -z "$PYTHON_LIBS"; then
102 # (makes two attempts to ensure we've got a version number
103 # from the interpreter)
104 ac_python_version=`cat<<EOD | $PYTHON -
106 # join all versioning strings, on some systems
107 # major/minor numbers could be in different list elements
108 -from distutils.sysconfig import *
109 +from sysconfig import *
110 e = get_config_var('VERSION')
114 # Make the versioning information available to the compiler
116 # JW: We don't need it and it interferes with the hack
117 - # to detect multiple Pyhton versions
118 + # to detect multiple Python versions
119 #AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"],
120 # [If available, contains the Python version number currently in use.])
123 ac_python_libdir=`cat<<EOD | $PYTHON -
125 # There should be only one
126 -import distutils.sysconfig
127 -e = distutils.sysconfig.get_config_var('LIBDIR')
129 +e = sysconfig.get_config_var('LIBDIR')
134 # Now, for the library:
135 ac_python_library=`cat<<EOD | $PYTHON -
137 -import distutils.sysconfig
138 -c = distutils.sysconfig.get_config_vars()
140 +c = sysconfig.get_config_vars()
142 print ('python'+c[['LDVERSION']])
144 @@ -230,44 +248,67 @@
146 # use the official shared library
147 ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"`
148 - PYTHON_LDFLAGS="-L$ac_python_libdir -l$ac_python_library"
149 + PYTHON_LIBS="-L$ac_python_libdir -l$ac_python_library"
151 # old way: use libpython from python_configdir
152 ac_python_libdir=`$PYTHON -c \
153 - "from distutils.sysconfig import get_python_lib as f; \
154 + "from sysconfig import get_python_lib as f; \
156 print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"`
157 - PYTHON_LDFLAGS="-L$ac_python_libdir -lpython$ac_python_version"
158 + PYTHON_LIBS="-L$ac_python_libdir -lpython$ac_python_version"
161 - if test -z "PYTHON_LDFLAGS"; then
162 + if test -z "PYTHON_LIBS"; then
164 Cannot determine location of your Python DSO. Please check it was installed with
165 - dynamic libraries enabled, or try setting PYTHON_LDFLAGS by hand.
166 + dynamic libraries enabled, or try setting PYTHON_LIBS by hand.
170 - AC_MSG_RESULT([$PYTHON_LDFLAGS])
171 - AC_SUBST([PYTHON_LDFLAGS])
172 + AC_MSG_RESULT([$PYTHON_LIBS])
173 + AC_SUBST([PYTHON_LIBS])
176 # Check for site packages
178 AC_MSG_CHECKING([for Python site-packages path])
179 if test -z "$PYTHON_SITE_PKG"; then
180 - PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
181 - print (distutils.sysconfig.get_python_lib(0,0));"`
182 + if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
183 + PYTHON_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
184 + print (sysconfig.get_path('purelib'));"`
186 + # distutils.sysconfig way
187 + PYTHON_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
188 + print (sysconfig.get_python_lib(0,0));"`
191 AC_MSG_RESULT([$PYTHON_SITE_PKG])
192 AC_SUBST([PYTHON_SITE_PKG])
195 + # Check for platform-specific site packages
197 + AC_MSG_CHECKING([for Python platform specific site-packages path])
198 + if test -z "$PYTHON_SITE_PKG"; then
199 + if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then
200 + PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
201 + print (sysconfig.get_path('platlib'));"`
203 + # distutils.sysconfig way
204 + PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \
205 + print (sysconfig.get_python_lib(1,0));"`
208 + AC_MSG_RESULT([$PYTHON_PLATFORM_SITE_PKG])
209 + AC_SUBST([PYTHON_PLATFORM_SITE_PKG])
212 # libraries which must be linked in when embedding
214 AC_MSG_CHECKING(python extra libraries)
215 if test -z "$PYTHON_EXTRA_LIBS"; then
216 - PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
217 - conf = distutils.sysconfig.get_config_var; \
218 + PYTHON_EXTRA_LIBS=`$PYTHON -c "$IMPORT_SYSCONFIG; \
219 + conf = sysconfig.get_config_var; \
220 print (conf('LIBS') + ' ' + conf('SYSLIBS'))"`
222 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
225 AC_MSG_CHECKING(python extra linking flags)
226 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
227 - PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
228 - conf = distutils.sysconfig.get_config_var; \
229 + PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "$IMPORT_SYSCONFIG; \
230 + conf = sysconfig.get_config_var; \
231 print (conf('LINKFORSHARED'))"`
233 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
235 AC_MSG_CHECKING([consistency of all components of python development environment])
236 # save current global flags
238 + ac_save_LDFLAGS="$LDFLAGS"
239 ac_save_CPPFLAGS="$CPPFLAGS"
240 - LIBS="$ac_save_LIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LDFLAGS $PYTHON_EXTRA_LIBS"
241 + LIBS="$ac_save_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_EXTRA_LIBS"
242 + LDFLAGS="$ac_save_LDFLAGS $PYTHON_EXTRA_LDFLAGS"
243 CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
246 @@ -303,15 +346,17 @@
247 # turn back to default flags
248 CPPFLAGS="$ac_save_CPPFLAGS"
250 + LDFLAGS="$ac_save_LDFLAGS"
252 AC_MSG_RESULT([$pythonexists])
254 if test ! "x$pythonexists" = "xyes"; then
255 + # gpgme: only warn here, no error, as we are looking for multiple versions
257 Could not link test program to Python. Maybe the main Python library has been
258 installed in some non-standard library path. If so, pass it to configure,
259 - via the LDFLAGS environment variable.
260 - Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
261 + via the LIBS environment variable.
262 + Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"
263 ============================================================================
264 You probably have to install the development version of the Python package
265 for your distribution. The exact name of this package varies among them.
272 \ No newline at end of file