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