added Object.h fix
[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     if test "x$PYTHON_LIB" '!=' "x" -o "x$PYTHON_INCLUDES" '!=' "x";then
9         echo "Set both PYTHON_LIB and PYTHON_INCLUDES, or none at all"
10     fi
11     # iterate through version 2.2 to 2.5
12     for v in 2 3 4 5; do
13         # Linux
14         if test -f "/usr/lib/python2.$v/site-packages/PIL/_imaging.so" -a -f "/usr/include/python2.$v/Python.h";then
15             PY_VERSION=2.$v
16             PYTHON_LIB="-lpython$PY_VERSION /usr/lib/python$PY_VERSION/site-packages/PIL/_imaging.so"
17             PYTHON_INCLUDES="-I/usr/include/python$PY_VERSION"
18         # Mac OS X
19         elif test -f "/System/Library/Frameworks/Python.framework/Versions/2.$v/include/python2.$v/Python.h";then
20             #TODO: test for /System/Library/Frameworks/Python.framework/Versions/2.3/Python ?
21             PY_VERSION=2.$v
22             PYTHON_LIB="-framework Python" 
23             if test -f "/Library/Python/2.$v/PIL/_imaging.so";then
24                 PYTHON_LIB2="$PYTHON_LIB /Library/Python/2.$v/PIL/_imaging.so"
25             else
26                 PYTHON_LIB2="$PYTHON_LIB"
27             fi
28             PYTHON_INCLUDES="-I/System/Library/Frameworks/Python.framework/Versions/2.$v/include/python2.$v/"
29         # Mac OS X [Fink]:
30         elif test "(" -f "/sw/lib/python2.$v/config/libpython2.$v.dylib" \
31                    -o -f "/sw/lib/python2.$v/config/libpython2.$v.a" \
32                    -o -f "/sw/lib/python2.$v/config/libpython2.$v.so" \
33                   ")" \
34                -a -f "/sw/include/python2.$v/Python.h" \
35                -a -f "/sw/lib/python2.$v/site-packages/PIL/_imaging.so";then
36             PY_VERSION=2.$v
37             PYTHON_LIB="-L /sw/lib/python2.$v/config/ -lpython$PY_VERSION /sw/lib/python2.$v/site-packages/PIL/_imaging.so"
38             PYTHON_INCLUDES="-I /sw/include/python2.$v/"
39         fi
40     done
41 fi
42
43 if test "x$PY_VERSION" "!=" "x"; then
44     AC_MSG_RESULT($PY_VERSION)
45     export PYTHON_INCLUDES PYTHON_LIB
46     AC_SUBST(PYTHON_LIB)
47     AC_SUBST(PYTHON_INCLUDES)
48     AC_MSG_CHECKING([whether we can compile the python test program])
49     
50     cat > conftest.c << EOF
51 #include <Python.h>
52 #include <Imaging.h>
53
54 int main()
55 {
56     int ret;
57     ret = Py_Main(0, 0);
58     int x; // check also for gcc 2.95.x incompatibilities
59     return ret;
60 }
61 EOF
62     ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS $PYTHON_LIB $LIBS -o conftest${ac_exeext}'
63     if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
64         AC_MSG_RESULT(yes)
65         PYTHON_OK=yes
66     else
67         ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS ${PYTHON_LIB2} $LIBS -o conftest${ac_exeext}'
68         if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
69             AC_MSG_RESULT(yes)
70             PYTHON_LIB="${PYTHON_LIB2}"
71             PYTHON_OK=yes
72         else
73             echo "configure: failed program was:" >&5
74             cat conftest.c >&5
75             AC_MSG_RESULT(no)
76         fi
77     fi
78     rm -f conftest*
79 else
80     AC_MSG_RESULT(nope)
81 fi
82 ])