| 1 |
|
| 2 |
AC_DEFUN([CF_CHECK_PYTHON], |
| 3 |
[ |
| 4 |
PYTHON_LIB="" |
| 5 |
PY_LIBS="" |
| 6 |
PY_INCLUDES="" |
| 7 |
dir="" |
| 8 |
if test "x$PYTHON_HOME" != "x"; then |
| 9 |
for dir in $PYTHON_HOME/include/python{,2.5,2.4,2.3,2.2,2.1,2.0} ; do |
| 10 |
AC_CHECK_HEADERS(["$dir/Python.h"],[cf_have_python_h=yes]) |
| 11 |
if test "x$cf_have_python_h" != "x" ; then |
| 12 |
PY_INCLUDES="-I$dir" |
| 13 |
break |
| 14 |
fi |
| 15 |
done |
| 16 |
PYTHON_SEARCH=$PYTHON |
| 17 |
else |
| 18 |
AC_CHECK_HEADERS([Python.h],[cf_have_python_h=yes]) |
| 19 |
if test "x$cf_have_python_h" = "x" ; then |
| 20 |
for dir in /usr{,/local}/include/python{,2.5,2.4,2.3,2.2,2.1,2.0} ; do |
| 21 |
AC_CHECK_HEADERS(["$dir/Python.h"],[cf_have_python_h=yes]) |
| 22 |
if test "x$cf_have_python_h" != "x" ; then |
| 23 |
PY_INCLUDES="-I$dir" |
| 24 |
break |
| 25 |
fi |
| 26 |
done |
| 27 |
else |
| 28 |
PY_INCLUDES="" |
| 29 |
fi |
| 30 |
fi |
| 31 |
|
| 32 |
if test "x$cf_have_python_h" = "xyes" ; then |
| 33 |
PYTHON_LIB="" |
| 34 |
if test "x$PYTHON_HOME" != "x"; then |
| 35 |
# I am going of how manually compiled python installed on |
| 36 |
# my system. We can't use AC_CHECK_LIB, because that will |
| 37 |
# find the one in the stanard location, which is what we |
| 38 |
# want to avoid. |
| 39 |
python=`echo $dir | awk -F/ '{print $NF}'`; |
| 40 |
AC_MSG_CHECKING([For python lib in various places]) |
| 41 |
if test -f $PYTHON_HOME/lib/lib$python.so ; then |
| 42 |
# Hopefully -R is a universal option |
| 43 |
AC_MSG_RESULT([found in $PYTHON_HOME/lib/]) |
| 44 |
if test -n "$hardcode_libdir_flag_spec" ; then |
| 45 |
oldlibdir=$libdir |
| 46 |
libdir="$PYTHON_HOME/lib/" |
| 47 |
rpath=`eval echo $hardcode_libdir_flag_spec` |
| 48 |
PYTHON_LIB="$rpath -L$PYTHON_HOME/lib/ -l$python" |
| 49 |
echo "rpath=$rpath" |
| 50 |
libdir=$oldlibdir |
| 51 |
else |
| 52 |
PYTHON_LIB="-L$PYTHON_HOME/lib/ -l$python" |
| 53 |
fi |
| 54 |
|
| 55 |
elif test -f $PYTHON_HOME/lib/$python/lib$python.a ; then |
| 56 |
PYTHON_LIB="$PYTHON_HOME/lib/$python/lib$python.a" |
| 57 |
AC_MSG_RESULT([found in $PYTHON_HOME/lib/$python]) |
| 58 |
elif test -f $PYTHON_HOME/lib/$python/config/lib$python.a ; then |
| 59 |
PYTHON_LIB="$PYTHON_HOME/lib/$python/config/lib$python.a" |
| 60 |
AC_MSG_RESULT([found in $PYTHON_HOME/lib/$python/config]) |
| 61 |
fi |
| 62 |
|
| 63 |
else |
| 64 |
for lib in python{,2.5,2.4,2.3,2.2,2.1,2.0} ; do |
| 65 |
AC_CHECK_LIB($lib, PyArg_ParseTuple,[PYTHON_LIB="-l$lib"]) |
| 66 |
if test "x$PYTHON_LIB" != "x" ; then |
| 67 |
break |
| 68 |
fi |
| 69 |
done |
| 70 |
|
| 71 |
# These checks are a bit bogus - would be better to use AC_CHECK_LIB, |
| 72 |
# but it caches the result of the first check, even if we run AC_CHECK_LIB |
| 73 |
# with other options. |
| 74 |
python=`echo $dir | awk -F/ '{print $NF}'`; |
| 75 |
if test "x$PYTHON_LIB" = "x" ; then |
| 76 |
AC_MSG_CHECKING([For python lib in various places]) |
| 77 |
if test -f /usr/lib/$python/lib$python.a ; then |
| 78 |
PYTHON_LIB="/usr/lib/$python/lib$python.a" |
| 79 |
AC_MSG_RESULT([found in /usr/lib/$python]) |
| 80 |
elif test -f /usr/lib/$python/config/lib$python.a ; then |
| 81 |
PYTHON_LIB="/usr/lib/$python/config/lib$python.a" |
| 82 |
AC_MSG_RESULT([found in /usr/lib/$python/config]) |
| 83 |
fi |
| 84 |
fi |
| 85 |
fi |
| 86 |
if test "x$PYTHON_LIB" != "x" ; then |
| 87 |
AC_CHECK_LIB(pthread, main, PY_LIBS="$PY_LIBS -lpthread", , $PY_LIBS ) |
| 88 |
AC_CHECK_LIB(util, main, PY_LIBS="$PY_LIBS -lutil", , $PY_LIBS ) |
| 89 |
AC_CHECK_LIB(dl, main, PY_LIBS="$PY_LIBS -ldl", , $PY_LIBS ) |
| 90 |
|
| 91 |
AC_MSG_CHECKING([whether python supports the "L" format specifier]) |
| 92 |
saved_LIBS="$LIBS" |
| 93 |
LIBS="$LIBS $PYTHON_LIB $PY_LIBS" |
| 94 |
saved_CXXFLAGS="$CXXFLAGS" |
| 95 |
CXXFLAGS="$CXXFLAGS $PY_INCLUDES" |
| 96 |
AC_TRY_RUN([ |
| 97 |
#include <Python.h> |
| 98 |
#include <stdlib.h> |
| 99 |
|
| 100 |
static PyObject *callback(PyObject *self, PyObject *args) |
| 101 |
{ |
| 102 |
long long val; |
| 103 |
|
| 104 |
if (!PyArg_ParseTuple(args, "L", &val)) |
| 105 |
return NULL; |
| 106 |
if (val != 1) |
| 107 |
exit(1); |
| 108 |
Py_INCREF(Py_None); |
| 109 |
return Py_None; |
| 110 |
} |
| 111 |
|
| 112 |
static PyMethodDef methods[] = { |
| 113 |
{"callback", callback, METH_VARARGS}, |
| 114 |
{NULL, NULL, 0, NULL}, |
| 115 |
}; |
| 116 |
|
| 117 |
int main() |
| 118 |
{ |
| 119 |
Py_Initialize(); |
| 120 |
Py_InitModule("test", methods); |
| 121 |
return(PyRun_SimpleString("import test\ntest.callback(1)\n") != 0); |
| 122 |
} |
| 123 |
], [ |
| 124 |
AC_MSG_RESULT([yes]) |
| 125 |
], [ |
| 126 |
AC_MSG_RESULT([no]) |
| 127 |
PYTHON_LIB="" |
| 128 |
PYLIBS="" |
| 129 |
PY_INCLUDE="" |
| 130 |
], |
| 131 |
[ |
| 132 |
AC_MSG_RESULT([skipped because cross compiling]) |
| 133 |
]) |
| 134 |
LIBS="$saved_LIBS" |
| 135 |
CXXFLAGS="$saved_CXXFLAGS" |
| 136 |
fi |
| 137 |
fi |
| 138 |
|
| 139 |
if test "x$PYTHON_LIB" = "x" ; then |
| 140 |
$2 |
| 141 |
else |
| 142 |
$1 |
| 143 |
fi |
| 144 |
|
| 145 |
AC_SUBST(PYTHON_LIB) |
| 146 |
AC_SUBST(PY_LIBS) |
| 147 |
AC_SUBST(PY_INCLUDES) |
| 148 |
]) |