[Xfce4-commits] <thunarx-python:master> Added the python m4 macros from nautilus-python
Adam Plumb
noreply at xfce.org
Thu May 27 18:10:42 CEST 2010
Updating branch refs/heads/master
to bdf3c79147d499e8499f4d1c37c1c1e80d846ab8 (commit)
from 030b9cdd809655323a6a7c1fc103a1f7c9285a64 (commit)
commit bdf3c79147d499e8499f4d1c37c1c1e80d846ab8
Author: Adam Plumb <adamplumb at gmail.com>
Date: Wed Dec 16 13:05:26 2009 -0500
Added the python m4 macros from nautilus-python
autogen.sh | 2 +
configure.ac.in | 7 ++++
m4/python.m4 | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/Makefile.am | 4 ++-
src/thunarx-python.c | 4 +-
5 files changed, 102 insertions(+), 3 deletions(-)
diff --git a/autogen.sh b/autogen.sh
index f87947f..414d37c 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -16,6 +16,8 @@ EOF
exit 1
}
+ACLOCAL_AMFLAGS="-I m4"
+
XDT_AUTOGEN_REQUIRED_VERSION="4.7.0" exec xdt-autogen $@
# vi:set ts=2 sw=2 et ai:
diff --git a/configure.ac.in b/configure.ac.in
index 7a1fa52..f2b1721 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -61,6 +61,13 @@ AC_DISABLE_STATIC()
AC_PROG_LIBTOOL()
+dnl **************************************************
+dnl * Check for Python
+dnl **************************************************
+AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
+AM_CHECK_PYTHON_LIBS(,[AC_MSG_ERROR(could not find Python lib)])
+
+
dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
diff --git a/m4/python.m4 b/m4/python.m4
new file mode 100644
index 0000000..15a29a3
--- /dev/null
+++ b/m4/python.m4
@@ -0,0 +1,88 @@
+## this one is commonly used with AM_PATH_PYTHONDIR ...
+dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]])
+dnl Check if a module containing a given symbol is visible to python.
+AC_DEFUN(AM_CHECK_PYMOD,
+[AC_REQUIRE([AM_PATH_PYTHON])
+py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
+AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1)
+AC_CACHE_VAL(py_cv_mod_$py_mod_var, [
+ifelse([$2],[], [prog="
+import sys
+try:
+ import $1
+except ImportError:
+ sys.exit(1)
+except:
+ sys.exit(0)
+sys.exit(0)"], [prog="
+import $1
+$1.$2"])
+if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
+ then
+ eval "py_cv_mod_$py_mod_var=yes"
+ else
+ eval "py_cv_mod_$py_mod_var=no"
+ fi
+])
+py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"`
+if test "x$py_val" != xno; then
+ AC_MSG_RESULT(yes)
+ ifelse([$3], [],, [$3
+])dnl
+else
+ AC_MSG_RESULT(no)
+ ifelse([$4], [],, [$4
+])dnl
+fi
+])
+
+dnl a macro to check for ability to create python extensions
+dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
+dnl function also defines PYTHON_INCLUDES
+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; print sys.prefix"`
+py_exec_prefix=`$PYTHON -c "import sys; print 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
+AC_SUBST(PYTHON_INCLUDES)
+dnl check if the headers exist:
+save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
+AC_TRY_CPP([#include <Python.h>],dnl
+[AC_MSG_RESULT(found)
+$1],dnl
+[AC_MSG_RESULT(not found)
+$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])
+
+])
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 1469ca4..42091b7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,9 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \
-DG_LOG_DOMAIN=\"thunarx-python\" \
-DEXO_API_SUBJECT_TO_CHANGE \
- -DLIBEXECDIR=\"$(libexecdir)\"
+ -DLIBEXECDIR=\"$(libexecdir)\" \
+ -DPY_LIB_LOC=\"$(PYTHON_LIB_LOC)\" \
+ -DPYTHON_VERSION=\"$(PYTHON_VERSION)\"
extensionsdir = $(libdir)/thunarx-2
extensions_LTLIBRARIES = \
diff --git a/src/thunarx-python.c b/src/thunarx-python.c
index bf7df48..4375db5 100644
--- a/src/thunarx-python.c
+++ b/src/thunarx-python.c
@@ -102,8 +102,8 @@ thunarx_python_init_python (void)
if (Py_IsInitialized())
return TRUE;
- debug ("g_module_open libpython " G_MODULE_SUFFIX);
- libpython = g_module_open ("/usr/lib/libpython2.6." G_MODULE_SUFFIX, 0);
+ debug ("g_module_open " PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX);
+ libpython = g_module_open (PY_LIB_LOC "/libpython" PYTHON_VERSION "." G_MODULE_SUFFIX, 0);
if (!libpython)
g_warning ("g_module_open libpython failed: %s", g_module_error());
More information about the Xfce4-commits
mailing list