Check if detected libpython.so can be dlopen-ed
authorRicardo Mones <ricardo@mones.org>
Thu, 30 May 2013 16:29:07 +0000 (18:29 +0200)
committerPaul <paul@claws-mail.org>
Sat, 8 Jun 2013 19:58:00 +0000 (20:58 +0100)
A somewhat better solution for the libpython.so detection saga.
Unfortunately it has not presented itself and had to be painfully
extracted from a series of trial and error experiments. No living
beings were harmed in the process, though.

Many thanks to Paul for the help with testing this.
(cherry picked from commit df8a1d7e766dea1c48a47d6a7766e20922a78cab)

configure.ac

index 3c8a5f5fcf4bd3dfd4cb54c30a28d28c9b1b8c43..f57dea12c9ae6c79c9dbecef482d767cde1358b3 100644 (file)
@@ -1238,25 +1238,28 @@ AM_PATH_PYTHON([2.5], [
 
        if test x"$HAVE_PYTHON" = xyes; then
                # libpython.so
-               PYTHON_SO_FILE_LOCATION=`python-config --ldflags|sed 's/-L//'|awk '{print $1}'`
-               PYTHON_SO_FILE="libpython${PYTHON_VERSION}.so"
-               found_libpython_so="no"
-               if test -f "$PYTHON_PREFIX/lib/$PYTHON_SO_FILE"; then
-                       found_libpython_so="yes"
-                       PYTHON_SHARED_LIB=`python -c "import os,sys; print os.path.basename(os.path.realpath(\"$PYTHON_PREFIX/lib/$PYTHON_SO_FILE\"))"`
-               fi
-               if  test x"$found_libpython_so" != x"yes" && test -f "$PYTHON_PREFIX/lib64/$PYTHON_SO_FILE"; then
-                       found_libpython_so="yes"
-                       PYTHON_SHARED_LIB=`python -c "import os,sys; print os.path.basename(os.path.realpath(\"$PYTHON_PREFIX/lib64/$PYTHON_SO_FILE\"))"`
-               fi
-               if test x"$found_libpython_so" != x"yes" && test -f "$PYTHON_SO_FILE_LOCATION/$PYTHON_SO_FILE"; then
-                       found_libpython_so="yes"
-                       PYTHON_SHARED_LIB=`python -c "import os,sys; print os.path.basename(os.path.realpath(\"$PYTHON_SO_FILE_LOCATION/$PYTHON_SO_FILE\"))"`
-               fi
+               PYTHON_SHARED_LIB="libpython${PYTHON_VERSION}.so"
+               _save_libs="$LIBS"
+               LIBS="-ldl"
+               AC_MSG_CHECKING([whether to dlopen $PYTHON_SHARED_LIB works])
+               AC_RUN_IFELSE(
+                       [AC_LANG_PROGRAM(
+                               [#include <dlfcn.h>
+                                #define PYTHON_SO_FILE "${PYTHON_SHARED_LIB}"
+                               ],
+                               [if (!dlopen(PYTHON_SO_FILE, RTLD_NOW | RTLD_GLOBAL)) return 1; return 0;])
+                       ],
+                       [found_libpython_so="yes"],
+                       [found_libpython_so="no"],
+                       [AC_MSG_FAILURE([cross-compiling not supported])])
                if test x"$found_libpython_so" != x"yes"; then
+                       AC_MSG_RESULT(no)
                        AC_MSG_WARN(Could not find Python shared libary: $PYTHON_SO_FILE does not exist. Maybe you need to install development packages for Python.)
                        HAVE_PYTHON=no
+               else
+                       AC_MSG_RESULT(yes)
                fi
+               LIBS="$_save_libs";
        fi
        if test x"$HAVE_PYTHON" = xyes; then
                PKG_CHECK_MODULES(PYGTK, pygtk-2.0 >= 2.10.3, [AC_DEFINE(ENABLE_PYTHON, [1], [Enable Python support])], HAVE_PYTHON=no)