diff --git a/config/python.m4 b/config/python.m4 index b95c8ed3b34..108d52cb077 100644 --- a/config/python.m4 +++ b/config/python.m4 @@ -58,36 +58,59 @@ AC_SUBST(python_includespec)[]dnl # PGAC_CHECK_PYTHON_EMBED_SETUP # ----------------------------- # -# Note: selecting libpython from python_configdir works in all Python -# releases, but it generally finds a non-shared library, which means -# that we are binding the python interpreter right into libplpython.so. -# In Python 2.3 and up there should be a shared library available in -# the main library location. +# Set python_libdir to the path of the directory containing the Python shared +# library. Set python_libspec to the -L/-l linker switches needed to link it. +# Set python_additional_libs to contain any additional linker switches needed +# for subsidiary libraries. +# +# In modern, well-configured Python installations, LIBDIR gives the correct +# directory name and LDLIBRARY is the file name of the shlib. But in older +# installations LDLIBRARY is frequently a useless path fragment, and it's also +# possible that the shlib is in a standard library directory such as /usr/lib +# so that LIBDIR is of no interest. We must also check that what we found is +# a shared library not a plain library, which we do by checking its extension. +# (We used to rely on Py_ENABLE_SHARED, but that only tells us that a shlib +# exists, not that we found it.) AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP], [AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS]) AC_MSG_CHECKING([how to link an embedded Python application]) python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"` python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"` -python_so=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('SO'))))"` -ldlibrary=`echo "${python_ldlibrary}" | sed "s/${python_so}$//"` -python_enable_shared=`${PYTHON} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars().get('Py_ENABLE_SHARED',0))"` -if test x"${python_libdir}" != x"" -a x"${python_ldlibrary}" != x"" -a x"${python_ldlibrary}" != x"${ldlibrary}" +# If LDLIBRARY exists and has a shlib extension, use it verbatim. +ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'` +if test -e "${python_libdir}/${python_ldlibrary}" -a x"${python_ldlibrary}" != x"${ldlibrary}" then - # New way: use the official shared library ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"` - python_libspec="-L${python_libdir} -l${ldlibrary}" else - # Old way: use libpython from python_configdir - python_libdir="${python_configdir}" - # LDVERSION was introduced in Python 3.2. + # Otherwise, guess the base name of the shlib. + # LDVERSION was added in Python 3.2, before that use $python_version. python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"` - if test x"${python_ldversion}" = x""; then - python_ldversion=$python_version + if test x"${python_ldversion}" != x""; then + ldlibrary="python${python_ldversion}" + else + ldlibrary="python${python_version}" + fi + # Search for a likely-looking file. + found_shlib=0 + for d in "${python_libdir}" /usr/lib64 /usr/lib; do + for e in .so .dll .dylib .sl; do + if test -e "$d/lib${ldlibrary}$e"; then + python_libdir="$d" + found_shlib=1 + break 2 + fi + done + done + if test "$found_shlib" != 1; then + AC_MSG_ERROR([could not find shared library for Python +You might have to rebuild your Python installation. Refer to the +documentation for details. Use --without-python to disable building +PL/Python.]) fi - python_libspec="-L${python_libdir} -lpython${python_ldversion}" fi +python_libspec="-L${python_libdir} -l${ldlibrary}" python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"` diff --git a/configure b/configure index 1021fd539ec..7bb8f8b1c65 100755 --- a/configure +++ b/configure @@ -7622,25 +7622,40 @@ $as_echo_n "checking how to link an embedded Python application... " >&6; } python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"` python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"` -python_so=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('SO'))))"` -ldlibrary=`echo "${python_ldlibrary}" | sed "s/${python_so}$//"` -python_enable_shared=`${PYTHON} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars().get('Py_ENABLE_SHARED',0))"` -if test x"${python_libdir}" != x"" -a x"${python_ldlibrary}" != x"" -a x"${python_ldlibrary}" != x"${ldlibrary}" +# If LDLIBRARY exists and has a shlib extension, use it verbatim. +ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'` +if test -e "${python_libdir}/${python_ldlibrary}" -a x"${python_ldlibrary}" != x"${ldlibrary}" then - # New way: use the official shared library ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"` - python_libspec="-L${python_libdir} -l${ldlibrary}" else - # Old way: use libpython from python_configdir - python_libdir="${python_configdir}" - # LDVERSION was introduced in Python 3.2. + # Otherwise, guess the base name of the shlib. + # LDVERSION was added in Python 3.2, before that use $python_version. python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"` - if test x"${python_ldversion}" = x""; then - python_ldversion=$python_version + if test x"${python_ldversion}" != x""; then + ldlibrary="python${python_ldversion}" + else + ldlibrary="python${python_version}" + fi + # Search for a likely-looking file. + found_shlib=0 + for d in "${python_libdir}" /usr/lib64 /usr/lib; do + for e in .so .dll .dylib .sl; do + if test -e "$d/lib${ldlibrary}$e"; then + python_libdir="$d" + found_shlib=1 + break 2 + fi + done + done + if test "$found_shlib" != 1; then + as_fn_error $? "could not find shared library for Python +You might have to rebuild your Python installation. Refer to the +documentation for details. Use --without-python to disable building +PL/Python." "$LINENO" 5 fi - python_libspec="-L${python_libdir} -lpython${python_ldversion}" fi +python_libspec="-L${python_libdir} -l${ldlibrary}" python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"` @@ -7649,40 +7664,6 @@ $as_echo "${python_libspec} ${python_additional_libs}" >&6; } - - # We need libpython as a shared library. With Python >=2.5, we - # check the Py_ENABLE_SHARED setting. On Debian, the setting is not - # correct before the jessie release (http://bugs.debian.org/695979). - # We also want to support older Python versions. So as a fallback - # we see if there is a file that is named like a shared library. - - if test "$python_enable_shared" != 1; then - if test "$PORTNAME" = darwin; then - # macOS does supply a .dylib even though Py_ENABLE_SHARED does - # not get set. The file detection logic below doesn't succeed - # on older macOS versions, so make it explicit. - python_enable_shared=1 - elif test "$PORTNAME" = win32; then - # Windows also needs an explicit override. - python_enable_shared=1 - else - # We don't know the platform shared library extension here yet, - # so we try some candidates. - for dlsuffix in .so .sl; do - if ls "$python_libdir"/libpython*${dlsuffix}* >/dev/null 2>&1; then - python_enable_shared=1 - break - fi - done - fi - fi - - if test "$python_enable_shared" != 1; then - as_fn_error $? "cannot build PL/Python because libpython is not a shared library -You might have to rebuild your Python installation. Refer to the -documentation for details. Use --without-python to disable building -PL/Python." "$LINENO" 5 - fi fi if test "$cross_compiling" = yes && test -z "$with_system_tzdata"; then diff --git a/configure.in b/configure.in index 9850d993ffc..40f3c093f1a 100644 --- a/configure.in +++ b/configure.in @@ -934,40 +934,6 @@ fi if test "$with_python" = yes; then PGAC_PATH_PYTHON PGAC_CHECK_PYTHON_EMBED_SETUP - - # We need libpython as a shared library. With Python >=2.5, we - # check the Py_ENABLE_SHARED setting. On Debian, the setting is not - # correct before the jessie release (http://bugs.debian.org/695979). - # We also want to support older Python versions. So as a fallback - # we see if there is a file that is named like a shared library. - - if test "$python_enable_shared" != 1; then - if test "$PORTNAME" = darwin; then - # macOS does supply a .dylib even though Py_ENABLE_SHARED does - # not get set. The file detection logic below doesn't succeed - # on older macOS versions, so make it explicit. - python_enable_shared=1 - elif test "$PORTNAME" = win32; then - # Windows also needs an explicit override. - python_enable_shared=1 - else - # We don't know the platform shared library extension here yet, - # so we try some candidates. - for dlsuffix in .so .sl; do - if ls "$python_libdir"/libpython*${dlsuffix}* >/dev/null 2>&1; then - python_enable_shared=1 - break - fi - done - fi - fi - - if test "$python_enable_shared" != 1; then - AC_MSG_ERROR([cannot build PL/Python because libpython is not a shared library -You might have to rebuild your Python installation. Refer to the -documentation for details. Use --without-python to disable building -PL/Python.]) - fi fi if test "$cross_compiling" = yes && test -z "$with_system_tzdata"; then