added finally keyword
[swftools.git] / m4 / python.m4
1 AC_DEFUN([RFX_CHECK_PYTHON],
2 [
3 AC_MSG_CHECKING([for Python.h])
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/include/python2.$v/Python.h";then
15             PY_VERSION=2.$v
16             PYTHON_LIB="-lpython$PY_VERSION"
17             if test -f "/usr/lib/python2.$v/site-packages/PIL/_imaging.so";then 
18                 PYTHON_LIB2="$PYTHON_LIB /usr/lib/python2.$v/site-packages/PIL/_imaging.so"
19                 HAVE_PYTHON_IMAGING_LIB=1
20             else
21                 PYTHON_LIB2="$PYTHON_LIB"
22             fi
23             PYTHON_INCLUDES="-I/usr/include/python$PY_VERSION"
24         # Mac OS X
25         elif test -f "/System/Library/Frameworks/Python.framework/Versions/2.$v/include/python2.$v/Python.h";then
26             #TODO: test for /System/Library/Frameworks/Python.framework/Versions/2.3/Python ?
27             PY_VERSION=2.$v
28             PYTHON_LIB="-framework Python" 
29             if test -f "/Library/Python/2.$v/PIL/_imaging.so";then
30                 PYTHON_LIB2="$PYTHON_LIB /Library/Python/2.$v/PIL/_imaging.so"
31                 HAVE_PYTHON_IMAGING_LIB=1
32             else
33                 PYTHON_LIB2="$PYTHON_LIB"
34             fi
35             PYTHON_INCLUDES="-I/System/Library/Frameworks/Python.framework/Versions/2.$v/include/python2.$v/"
36         # Mac OS X [Fink]:
37         elif test "(" -f "/sw/lib/python2.$v/config/libpython2.$v.dylib" \
38                    -o -f "/sw/lib/python2.$v/config/libpython2.$v.a" \
39                    -o -f "/sw/lib/python2.$v/config/libpython2.$v.so" \
40                   ")" \
41                -a -f "/sw/include/python2.$v/Python.h"; then
42             PY_VERSION=2.$v
43             PYTHON_LIB="-L /sw/lib/python2.$v/config/ -lpython$PY_VERSION /sw/lib/python2.$v/site-packages/PIL/_imaging.so"
44             if test -f "/sw/lib/python2.$v/site-packages/PIL/_imaging.so";then
45                 PYTHON_LIB2="$PYTHON_LIB /sw/lib/python2.$v/site-packages/PIL/_imaging.so"
46                 HAVE_PYTHON_IMAGING_LIB=1
47             else
48                 PYTHON_LIB2="$PYTHON_LIB"
49             fi
50             PYTHON_INCLUDES="-I /sw/include/python2.$v/"
51         fi
52     done
53 fi
54
55 if test "x$PY_VERSION" "!=" "x"; then
56     AC_MSG_RESULT([$PY_VERSION])
57     export PYTHON_INCLUDES PYTHON_LIB
58     AC_SUBST(PYTHON_LIB)
59     AC_SUBST(PYTHON_INCLUDES)
60     AC_MSG_CHECKING([whether we can compile the python test program])
61     
62     cat > conftest.c << EOF
63 #include <Python.h>
64
65 int main()
66 {
67     int ret;
68     ret = Py_Main(0, 0);
69     int x; // check also for gcc 2.95.x incompatibilities
70     return ret;
71 }
72 EOF
73     
74     ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS $PYTHON_LIB $LIBS -o conftest${ac_exeext}'
75     if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
76         AC_MSG_RESULT(yes)
77         PYTHON_OK=yes
78     else
79         echo "configure: failed program was:" >&5
80         cat conftest.c >&5
81         AC_MSG_RESULT(no)
82     fi
83     rm -f conftest*
84     if test "x$PYTHON_OK" = "xyes";then
85         AC_MSG_CHECKING([for Python-Imaging])
86     cat > conftest.c << EOF
87 #include <Python.h>
88 #include <Imaging.h>
89
90 int main()
91 {
92     Py_Main(0, 0);
93     return 0;
94 }
95 EOF
96         if test "$HAVE_PYTHON_IMAGING_LIB"; then
97             ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS ${PYTHON_LIB2} $LIBS -o conftest${ac_exeext}'
98             if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
99                 PYTHON_LIB="${PYTHON_LIB2}"
100                 AC_DEFINE([HAVE_PYTHON_IMAGING], [1], [whether python-imaging was found])
101                 HAVE_PYTHON_IMAGING=yes
102                 export HAVE_PYTHON_IMAGING
103                 AC_SUBST(HAVE_PYTHON_IMAGING)
104                 AC_MSG_RESULT(yes)
105             else
106                 echo "configure: failed program was:" >&5
107                 cat conftest.c >&5
108                 AC_MSG_RESULT(no)
109             fi
110         else
111             echo "(didn't find the Python-Imaging libraries)" >&5
112             AC_MSG_RESULT(no)
113         fi
114     fi
115     rm -f conftest*
116 else
117     AC_MSG_RESULT([nope])
118 fi
119 ])