gfx module for Python3
[swftools.git] / m4 / python.m4
blobc3d01f9fe21e01c28681c01cd0b89c6bdb2e7171
1 AC_DEFUN([RFX_CHECK_PYTHON],
3 AC_MSG_CHECKING([for Python.h])
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 3.2
12     for v in 2.2 2.3 2.4 2.5 2.6 3.0 3.1 3.2; do
13         # Linux
14         if test -f "/usr/include/python$v/Python.h";then
15             PY_VERSION=$v
16             PYTHON_LIB="-lpython$PY_VERSION"
17             if test -f "/usr/lib/python$v/site-packages/PIL/_imaging.so";then 
18                 PYTHON_LIB2="$PYTHON_LIB /usr/lib/python$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/$v/include/python$v/Python.h";then
26             PY_VERSION=$v
27             PYTHON_LIB="-framework Python" 
28             if test -f "/Library/Frameworks/Python.framework/Versions/$v/site-packages/PIL/_imaging.so";then
29                 PYTHON_LIB2="$PYTHON_LIB /Library/Python/$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/$v/include/python$v/"
35         # Mac OS X [Fink]:
36         elif test "(" -f "/sw/lib/python$v/config/libpython$v.dylib" \
37                    -o -f "/sw/lib/python$v/config/libpython$v.a" \
38                    -o -f "/sw/lib/python$v/config/libpython$v.so" \
39                   ")" \
40                -a -f "/sw/include/python$v/Python.h"; then
41             PY_VERSION=$v
42             PYTHON_LIB="-L /sw/lib/python$v/config/ -lpython$PY_VERSION /sw/lib/python$v/site-packages/PIL/_imaging.so"
43             if test -f "/sw/lib/python$v/site-packages/PIL/_imaging.so";then
44                 PYTHON_LIB2="$PYTHON_LIB /sw/lib/python$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/python$v/"
50         fi
51     done
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>
64 int main()
66     int ret;
67     ret = Py_Main(0, 0);
68     int x; // check also for gcc 2.95.x incompatibilities
69     return ret;
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>
89 int main()
91     Py_Main(0, 0);
92     return 0;
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])