1 AC_DEFUN([RFX_CHECK_PYTHON],
3 AC_MSG_CHECKING([for Python version])
5 if test "x$PYTHON_LIB" '!=' "x" -a "x$PYTHON_INCLUDES" '!=' "x";then
6 # you can override the python detection by putting PYTHON_LIB
7 # and PYTHON_INCLUDES into the environment
8 case "$PYTHON_INCLUDES" in
9 *python2.4*) PY_VERSION=2.4
11 *python2.5*) PY_VERSION=2.5
13 *python2.6*) PY_VERSION=2.6
15 *python2.7*) PY_VERSION=2.7
17 *python3.0*) PY_VERSION=3.0
19 *python3.1*) PY_VERSION=3.1
21 *python3.2*) PY_VERSION=3.2
23 *python3.3*) PY_VERSION=3.3
29 if test "x$PYTHON_LIB" '!=' "x" -o "x$PYTHON_INCLUDES" '!=' "x";then
30 echo "Set both PYTHON_LIB and PYTHON_INCLUDES, or none at all"
32 # iterate through version 2.4 to 3.3
33 VERSIONS="2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3"
35 2*) VERSIONS="2.4 2.5 2.6 2.7 $PYTHON"
37 3*) VERSIONS="3.0 3.1 3.2 3.3 $PYTHON"
40 for v in $VERSIONS; do
42 if test -f "/usr/include/python$v/Python.h";then
44 PYTHON_LIB="-lpython$PY_VERSION"
45 if test -f "/usr/lib/python$v/site-packages/PIL/_imaging.so";then
46 PYTHON_LIB2="$PYTHON_LIB /usr/lib/python$v/site-packages/PIL/_imaging.so"
47 HAVE_PYTHON_IMAGING_LIB=1
49 PYTHON_LIB2="$PYTHON_LIB"
51 PYTHON_INCLUDES="-I/usr/include/python$PY_VERSION"
53 elif test -f "/Library/Frameworks/Python.framework/Versions/$v/include/python$v/Python.h";then
55 PYTHON_LIB="-framework Python"
56 if test -f "/Library/Frameworks/Python.framework/Versions/$v/site-packages/PIL/_imaging.so";then
57 PYTHON_LIB2="$PYTHON_LIB /Library/Python/$v/PIL/_imaging.so"
58 HAVE_PYTHON_IMAGING_LIB=1
60 PYTHON_LIB2="$PYTHON_LIB"
62 PYTHON_INCLUDES="-I/Library/Frameworks/Python.framework/Versions/$v/include/python$v/"
64 elif test "(" -f "/sw/lib/python$v/config/libpython$v.dylib" \
65 -o -f "/sw/lib/python$v/config/libpython$v.a" \
66 -o -f "/sw/lib/python$v/config/libpython$v.so" \
68 -a -f "/sw/include/python$v/Python.h"; then
70 PYTHON_LIB="-L /sw/lib/python$v/config/ -lpython$PY_VERSION /sw/lib/python$v/site-packages/PIL/_imaging.so"
71 if test -f "/sw/lib/python$v/site-packages/PIL/_imaging.so";then
72 PYTHON_LIB2="$PYTHON_LIB /sw/lib/python$v/site-packages/PIL/_imaging.so"
73 HAVE_PYTHON_IMAGING_LIB=1
75 PYTHON_LIB2="$PYTHON_LIB"
77 PYTHON_INCLUDES="-I /sw/include/python$v/"
81 AC_MSG_RESULT($PY_VERSION)
83 if test "x$PY_VERSION" "!=" "x"; then
84 AC_MSG_CHECKING([for Python executable])
85 if python$PY_VERSION -V 2>&5;then
86 PYTHON_EXECUTABLE=python$PY_VERSION
87 AC_SUBST(PYTHON_EXECUTABLE)
88 AC_MSG_RESULT([$PYTHON_EXECUTABLE])
89 elif python -V >&5 2>&5;then
90 if python -V 2>&1 | grep -q "\b$PY_VERSION"; then
91 PYTHON_EXECUTABLE=python
92 AC_SUBST(PYTHON_EXECUTABLE)
93 AC_MSG_RESULT([$PYTHON_EXECUTABLE])
95 AC_MSG_RESULT(["'python' executable is not version $PY_VERSION"])
98 AC_MSG_RESULT([failed])
102 if test "x$PY_VERSION" "!=" "x" -a "x$PYTHON_EXECUTABLE" "!=" "x"; then
103 export PYTHON_INCLUDES PYTHON_LIB
105 AC_SUBST(PYTHON_INCLUDES)
106 AC_MSG_CHECKING([whether we can compile the Python test program])
108 cat > conftest.c << EOF
115 int x; // check also for gcc 2.95.x incompatibilities
120 ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS $PYTHON_LIB $LIBS -o conftest${ac_exeext}'
121 if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
125 echo "configure: failed program was:" >&5
131 AC_MSG_CHECKING([for Python install path])
132 cat > _pypath.py << EOF
134 import distutils.sysconfig
136 sys.stdout.write(distutils.sysconfig.get_python_lib(plat_specific=0,standard_lib=0))
138 echo $PYTHON_EXECUTABLE _pypath.py 1>&5
139 if $PYTHON_EXECUTABLE _pypath.py >_pypath.txt 2>&5;then
140 PYTHON_INSTALL_PATH=`cat _pypath.txt`
141 AC_SUBST(PYTHON_INSTALL_PATH)
142 AC_MSG_RESULT($PYTHON_INSTALL_PATH)
144 AC_MSG_RESULT([failed])
146 #rm -f _pypath.txt _pypath.py
148 if test "x$PYTHON_OK" = "xyes";then
149 AC_MSG_CHECKING([for Python-Imaging])
150 cat > conftest.c << EOF
152 # include <Imaging.h>
160 if test "$HAVE_PYTHON_IMAGING_LIB"; then
161 ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS ${PYTHON_LIB2} $LIBS -o conftest${ac_exeext}'
162 if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
163 PYTHON_LIB="${PYTHON_LIB2}"
164 AC_DEFINE([HAVE_PYTHON_IMAGING], [1], [whether Python-Imaging was found])
165 HAVE_PYTHON_IMAGING=yes
166 export HAVE_PYTHON_IMAGING
167 AC_SUBST(HAVE_PYTHON_IMAGING)
170 echo "configure: failed program was:" >&5
175 echo "(didn't find the Python-Imaging libraries)" >&5