don't requite autodetection to succeed if PYTHON_LIB and PYTHON_INCLUDES
[swftools.git] / m4 / python.m4
1 AC_DEFUN(RFX_CHECK_PYTHON,
2 [
3 AC_MSG_CHECKING([for Python.h and PIL])
4
5 if test "x$PYTHON_LIB" '!=' "x" -a "x$PYTHON_INCLUDES" '!=' "x";then
6     PY_VERSION=unknown
7 else
8     # should we support python versions below 2.2?
9     if test -f "/usr/lib/python2.2/site-packages/PIL/_imaging.so" -a -f "/usr/include/python2.2/Python.h";then
10         PY_VERSION=2.2
11     fi
12     if test -f "/usr/lib/python2.3/site-packages/PIL/_imaging.so" -a -f "/usr/include/python2.3/Python.h";then
13         PY_VERSION=2.3
14     fi
15     if test -f "/usr/lib/python2.4/site-packages/PIL/_imaging.so" -a -f "/usr/include/python2.4/Python.h";then
16         PY_VERSION=2.4
17     fi
18     # OS X:
19     # /System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3/Python.h
20     # /Library/Python/2.3/_imaging.so
21 fi
22
23 if test "x$PY_VERSION" "!=" "x"; then
24     AC_MSG_RESULT($PY_VERSION)
25     if test "x$PYTHON_LIB" = "x";then
26         PYTHON_LIB="-l$PY_VERSION /usr/lib/$PY_VERSION/site-packages/PIL/_imaging.so"
27     fi
28     if test "x$PYTHON_INCLUDES" = "x";then
29         PYTHON_INCLUDES="-I/usr/include/$PY_VERSION"
30     fi
31     export PYTHON_INCLUDES PYTHON_LIB
32     AC_SUBST(PYTHON_LIB)
33     AC_SUBST(PYTHON_INCLUDES)
34     AC_MSG_CHECKING([whether we can compile the python test program])
35     
36     cat > conftest.c << EOF
37 #include <Python.h>
38 #include <Imaging.h>
39
40 int main(int argn, char*argv[])
41 {
42     int ret;
43     ret = Py_Main(argn, argv);
44     int x; // check also for gcc 2.95.x incompatibilities
45     return ret;
46 }
47 EOF
48     ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS $PYTHON_LIB $LIBS -o conftest${ac_exeext}'
49     if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
50         AC_MSG_RESULT(yes)
51         PYTHON_OK=yes
52     else
53         echo "configure: failed program was:" >&5
54         cat conftest.c >&5
55         AC_MSG_RESULT(no)
56     fi
57     rm -f conftest*
58 else
59     AC_MSG_RESULT(nope)
60 fi
61 ])