Re: Autotools integration / How to determine .so filename extension

Roland Lutz <[email protected]> Mon, 12 Jul 2021 17:33:36 +0200 (CEST)
Newsgroups gmane.comp.python.pypy
Message-ID <alpine.DEB.2.21.2107121711010.16673@nimbus>
On Sat, 10 Jul 2021, Matti Picus wrote:
> The canonical way is to use sysconfig
>
> pypy -c "import sysconfig;print(sysconfig.get_config_var('EXT_SUFFIX'))"
>
> .pypy37-pp73-x86_64-linux-gnu.so
>
>
> On python2.7 use 'SO'
>
> ~/oss/pypy2.7-HEAD/bin/pypy -c "import 
> sysconfig;print(sysconfig.get_config_var('SO'))"
>
> .pypy-73.so


This is exactly what I have been looking for.  Thenk you very much!


In case anyone is interested, here is my resulting autoconf macro:

     https://gist.github.com/rlutz/334b995462e8d52ae2ae102334b45170

This is an extended version of the standard `AM_PATH_PYTHON' macro.  It 
takes two arguments: a minimum Python 2 version, and a minimum Python 3 
version.

     AM_PATH_PYTHON_EXT([2.7], [3.5])

In case your package supports either only Python 2 or only Python 3, leave 
the other argument blank.

     AM_PATH_PYTHON_EXT([2.7], [])
     AM_PATH_PYTHON_EXT([], [3.5])

This macro chooses the newest available version of PyPy matching the 
arguments, falling back to CPython if PyPy isn't available.  It defines 
the following output values:

     PYTHON - the name of the Python executable
     PYTHON_VERSION - the Python version in the form MAJOR.MINOR
     PYTHON_PLATFORM - the value of sys.platform

     PYTHON_EXT_SUFFIX - filename extension for extension modules
     PYTHON_CFLAGS - CFLAGS for compiling extension modules
     PYTHON_LDFLAGS - LDFLAGS for compiling extension modules

     PYTHON_PREFIX, PYTHON_EXEC_PREFIX - the correct prefixes
     pythondir, pkgpythondir - where to install pure-Python packages
     pyexecdir, pkgpyexecdir - where to install packages that contain
                               extension modules

The macro can be used as a drop-in replacement for AM_PATH_PYTHON (but 
beware of the changed arguments).  If you are using Autotools for building 
Python extensions, you are probably also calling PKG_CHECK_MODULES for 
obtaining the PYTHON_CFLAGS; this call isn't necessary any more and should 
be removed.

Roland