[pygobject] use improved python.m4 macros to search for Python headers and libs
- From: Dieter Verfaillie <dieterv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] use improved python.m4 macros to search for Python headers and libs
- Date: Fri, 9 Sep 2011 17:32:08 +0000 (UTC)
commit 4671f5397003f376f00830e3fd1c214de594619f
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date: Fri Sep 9 14:55:01 2011 +0200
use improved python.m4 macros to search for Python headers and libs
https://bugzilla.gnome.org/show_bug.cgi?id=658652
configure.ac | 3 ++-
m4/python.m4 | 47 +++++++++++++++++++++++++++++++++++++----------
2 files changed, 39 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b50a3b1..b589a3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,7 +101,8 @@ if test $build_py3k = true ; then
[AC_MSG_ERROR(too old)])
fi
-AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
+AM_CHECK_PYTHON_HEADERS(, AC_MSG_ERROR([Python headers not found]))
+AM_CHECK_PYTHON_LIBS(, AC_MSG_ERROR([Python libs not found]))
AC_MSG_CHECKING([for PySignal_SetWakeupFd in Python.h])
old_CPPFLAGS=$CPPFLAGS
diff --git a/m4/python.m4 b/m4/python.m4
index 523e45a..968b9a6 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -43,16 +43,18 @@ AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
[AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING(for headers required to compile python extensions)
dnl deduce PYTHON_INCLUDES
-py_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.prefix)"`
-py_exec_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)"`
-PYTHON_CONFIG=`which $PYTHON`-config
-if test -x "$PYTHON_CONFIG"; then
-PYTHON_INCLUDES=`$PYTHON_CONFIG --includes 2>/dev/null`
-else
-PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
-if test "$py_prefix" != "$py_exec_prefix"; then
- PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
-fi
+if test "x$PYTHON_INCLUDES" == x; then
+ PYTHON_CONFIG=`which $PYTHON`-config
+ if test -x "$PYTHON_CONFIG"; then
+ PYTHON_INCLUDES=`$PYTHON_CONFIG --includes 2>/dev/null`
+ else
+ py_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.prefix)"`
+ py_exec_prefix=`$PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)"`
+ PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
+ if test "$py_prefix" != "$py_exec_prefix"; then
+ PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
+ fi
+ fi
fi
AC_SUBST(PYTHON_INCLUDES)
dnl check if the headers exist:
@@ -66,6 +68,31 @@ $2])
CPPFLAGS="$save_CPPFLAGS"
])
+dnl a macro to check for ability to embed python
+dnl AM_CHECK_PYTHON_LIBS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
+dnl function also defines PYTHON_LIBS
+AC_DEFUN([AM_CHECK_PYTHON_LIBS],
+[AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
+AC_MSG_CHECKING(for libraries required to embed python)
+dnl deduce PYTHON_LIBS
+py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
+if test "x$PYTHON_LIBS" == x; then
+ PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}"
+fi
+if test "x$PYTHON_LIB_LOC" == x; then
+ PYTHON_LIB_LOC="${py_prefix}/lib"
+fi
+AC_SUBST(PYTHON_LIBS)
+AC_SUBST(PYTHON_LIB_LOC)
+dnl check if the headers exist:
+save_LIBS="$LIBS"
+LIBS="$LIBS $PYTHON_LIBS"
+AC_TRY_LINK_FUNC(Py_Initialize, dnl
+ [LIBS="$save_LIBS"; AC_MSG_RESULT(yes); $1], dnl
+ [LIBS="$save_LIBS"; AC_MSG_RESULT(no); $2])
+
+])
+
# JD_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ---------------------------------------------------------------------------
# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]