1 | |
---|
2 | AC_DEFUN([RP_LANG_PYTHON],[ |
---|
3 | PYTHON="" |
---|
4 | PYTHON_CFLAGS="" |
---|
5 | PYTHON_CPPFLAGS="" |
---|
6 | PYTHON_DISTUTILS="" |
---|
7 | PYTHON_INCLUDES="" |
---|
8 | PYTHON_LDFLAGS="" |
---|
9 | PYTHON_LIB="" |
---|
10 | PYTHON_LIBDIR="" |
---|
11 | PYTHON_SITE_DIR="" |
---|
12 | PYTHON_SITE_PACKAGES="" |
---|
13 | PYTHON_VERSION="" |
---|
14 | pythondir="" |
---|
15 | AC_ARG_WITH([python], |
---|
16 | [AS_HELP_STRING([--with-python[=DIR]],[location of python @<:@default=yes@:>@])], |
---|
17 | [], |
---|
18 | [with_python=yes]) |
---|
19 | |
---|
20 | if test "$with_python" != "no" ; then |
---|
21 | if test "$with_python" = "yes" ; then |
---|
22 | AC_PATH_PROG(PYTHON, python python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5) |
---|
23 | else |
---|
24 | AC_PATH_PROG(PYTHON, python, [], [${with_python}/bin:${with_python}]) |
---|
25 | fi |
---|
26 | AC_MSG_CHECKING([for Python version]) |
---|
27 | if test "x${PYTHON}" != "x"; then |
---|
28 | PYTHON_VERSION=`${PYTHON} -c "import sys; print sys.version[[0:3]]"` |
---|
29 | fi |
---|
30 | AC_MSG_RESULT([$PYTHON_VERSION]) |
---|
31 | fi |
---|
32 | |
---|
33 | if test "x${PYTHON_VERSION}" != "x"; then |
---|
34 | PYTHON_INCLUDES=$incdir |
---|
35 | AC_MSG_CHECKING([for Python distutils]) |
---|
36 | PYTHON_DISTUTILS="" |
---|
37 | ${PYTHON} -c "from distutils.core import setup; setup(name='test')" \ |
---|
38 | build build_ext 2>&1 > /dev/null |
---|
39 | if test $? = 0 ; then |
---|
40 | PYTHON_DISTUTILS="yes" |
---|
41 | fi |
---|
42 | AC_MSG_RESULT([$PYTHON_DISTUTILS]) |
---|
43 | if test "${PYTHON_DISTUTILS}" = "yes" ; then |
---|
44 | PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"` |
---|
45 | # |
---|
46 | # Check for Python include path |
---|
47 | # |
---|
48 | AC_MSG_CHECKING([path to Python headers]) |
---|
49 | PYTHON_INCDIR=`${PYTHON} -c "import distutils.sysconfig; \ |
---|
50 | print distutils.sysconfig.get_python_inc();"` |
---|
51 | AC_MSG_RESULT([$PYTHON_INCDIR]) |
---|
52 | # |
---|
53 | # Python distutils found, get settings from python directly |
---|
54 | # |
---|
55 | PYTHON_SITE_DIR="`${PYTHON} -c 'from distutils import sysconfig; print sysconfig.get_python_lib(0);'`" |
---|
56 | |
---|
57 | PYTHON_CFLAGS="`$PYTHON -c 'from distutils import sysconfig; flags = [[\"-I\" + sysconfig.get_python_inc(0), \"-I\" + sysconfig.get_python_inc(1), \" \".join(sysconfig.get_config_var(\"CFLAGS\").split())]]; print \" \".join(flags);'`" |
---|
58 | PYTHON_LDFLAGS="`$PYTHON -c 'from distutils import sysconfig; libs = sysconfig.get_config_var(\"LIBS\").split() + sysconfig.get_config_var(\"SYSLIBS\").split(); libs.append(\"-lpython\"+sysconfig.get_config_var(\"VERSION\")); print \" \".join(libs);'`" |
---|
59 | PYTHON_LIB="`$PYTHON -c 'from distutils import sysconfig; print \"python\" + sysconfig.get_config_var(\"VERSION\");'`" |
---|
60 | PYTHON_LIBDIR="`$PYTHON -c 'from distutils import sysconfig; print sysconfig.get_config_var(\"LIBDIR\");'`" |
---|
61 | save_CPPFLAGS=$CPPFLAGS |
---|
62 | CPPFLAGS="$CPPFLAGS -I${PYTHON_INCDIR}" |
---|
63 | AC_CHECK_HEADERS([Python.h], [found=yes], [found=no]) |
---|
64 | CPPFLAGS=$save_CPPFLAGS |
---|
65 | if test "$found" = "no" ; then |
---|
66 | PYTHON_DISTUTILS="" |
---|
67 | fi |
---|
68 | fi |
---|
69 | fi |
---|
70 | ]) |
---|