applied swfrender --help patch from Sergey Vinokurov
[swftools.git] / m4 / python.m4
blob1d7c3d9e090062e029c50bddd1ac5613811a48c3
1 AC_DEFUN([RFX_CHECK_PYTHON],
3 AC_MSG_CHECKING([for Python version])
5 if test "x$PYTHON_LIB" '!=' "x" -a "x$PYTHON_INCLUDES" '!=' "x";then
6     # you can override the python detection by putting PYTHON_LIB
7     # and PYTHON_INCLUDES into the environment
8     case "$PYTHON_INCLUDES" in
9         *python2.4*) PY_VERSION=2.4
10                      ;;
11         *python2.5*) PY_VERSION=2.5
12                      ;;
13         *python2.6*) PY_VERSION=2.6
14                      ;;
15         *python2.7*) PY_VERSION=2.7
16                      ;;
17         *python3.0*) PY_VERSION=3.0
18                      ;;
19         *python3.1*) PY_VERSION=3.1
20                      ;;
21         *python3.2*) PY_VERSION=3.2
22                      ;;
23         *python3.3*) PY_VERSION=3.3
24                      ;;
25         *)           PY_VERSION=unknown
26                      ;;
27     esac
28 else
29     if test "x$PYTHON_LIB" '!=' "x" -o "x$PYTHON_INCLUDES" '!=' "x";then
30         echo "Set both PYTHON_LIB and PYTHON_INCLUDES, or none at all"
31     fi
32     # iterate through version 2.4 to 3.3
33     VERSIONS="2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3"
34     case "$PYTHON" in
35         2*) VERSIONS="2.4 2.5 2.6 2.7 $PYTHON"
36             ;;
37         3*) VERSIONS="3.0 3.1 3.2 3.3 $PYTHON"
38             ;;
39     esac
40     for v in $VERSIONS; do
41         # Linux
42         if test -f "/usr/include/python$v/Python.h";then
43             PY_VERSION=$v
44             PYTHON_LIB="-lpython$PY_VERSION"
45             if test -f "/usr/lib/python$v/site-packages/PIL/_imaging.so";then 
46                 PYTHON_LIB2="$PYTHON_LIB /usr/lib/python$v/site-packages/PIL/_imaging.so"
47                 HAVE_PYTHON_IMAGING_LIB=1
48             else
49                 PYTHON_LIB2="$PYTHON_LIB"
50             fi
51             PYTHON_INCLUDES="-I/usr/include/python$PY_VERSION"
52         # Mac OS X
53         elif test -f "/Library/Frameworks/Python.framework/Versions/$v/include/python$v/Python.h";then
54             PY_VERSION=$v
55             PYTHON_LIB="-framework Python" 
56             if test -f "/Library/Frameworks/Python.framework/Versions/$v/site-packages/PIL/_imaging.so";then
57                 PYTHON_LIB2="$PYTHON_LIB /Library/Python/$v/PIL/_imaging.so"
58                 HAVE_PYTHON_IMAGING_LIB=1
59             else
60                 PYTHON_LIB2="$PYTHON_LIB"
61             fi
62             PYTHON_INCLUDES="-I/Library/Frameworks/Python.framework/Versions/$v/include/python$v/"
63         # Mac OS X [Fink]:
64         elif test "(" -f "/sw/lib/python$v/config/libpython$v.dylib" \
65                    -o -f "/sw/lib/python$v/config/libpython$v.a" \
66                    -o -f "/sw/lib/python$v/config/libpython$v.so" \
67                   ")" \
68                -a -f "/sw/include/python$v/Python.h"; then
69             PY_VERSION=$v
70             PYTHON_LIB="-L /sw/lib/python$v/config/ -lpython$PY_VERSION /sw/lib/python$v/site-packages/PIL/_imaging.so"
71             if test -f "/sw/lib/python$v/site-packages/PIL/_imaging.so";then
72                 PYTHON_LIB2="$PYTHON_LIB /sw/lib/python$v/site-packages/PIL/_imaging.so"
73                 HAVE_PYTHON_IMAGING_LIB=1
74             else
75                 PYTHON_LIB2="$PYTHON_LIB"
76             fi
77             PYTHON_INCLUDES="-I /sw/include/python$v/"
78         fi
79     done
81 AC_MSG_RESULT($PY_VERSION)
82     
83 if test "x$PY_VERSION" "!=" "x"; then
84     AC_MSG_CHECKING([for Python executable])
85     if python$PY_VERSION -V 2>&5;then
86         PYTHON_EXECUTABLE=python$PY_VERSION
87         AC_SUBST(PYTHON_EXECUTABLE)
88         AC_MSG_RESULT([$PYTHON_EXECUTABLE])
89     else
90         AC_MSG_RESULT([failed])
91     fi
94 if test "x$PY_VERSION" "!=" "x" -a "x$PYTHON_EXECUTABLE" "!=" "x"; then
95     export PYTHON_INCLUDES PYTHON_LIB
96     AC_SUBST(PYTHON_LIB)
97     AC_SUBST(PYTHON_INCLUDES)
98     AC_MSG_CHECKING([whether we can compile the Python test program])
99     
100     cat > conftest.c << EOF
101 #   include <Python.h>
103     int main()
104     {
105         int ret;
106         ret = Py_Main(0, 0);
107         int x; // check also for gcc 2.95.x incompatibilities
108         return ret;
109     }
111     
112     ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS $PYTHON_LIB $LIBS -o conftest${ac_exeext}'
113     if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
114         AC_MSG_RESULT(yes)
115         PYTHON_OK=yes
116     else
117         echo "configure: failed program was:" >&5
118         cat conftest.c >&5
119         AC_MSG_RESULT(no)
120     fi
121     rm -f conftest*
122     
123     AC_MSG_CHECKING([for Python install path])
124 cat > _pypath.py << EOF
125 import distutils
126 import distutils.sysconfig
127 import sys
128 sys.stdout.write(distutils.sysconfig.get_python_lib(plat_specific=0,standard_lib=0))
129 EOF 
130     echo $PYTHON_EXECUTABLE _pypath.py 1>&5
131     if $PYTHON_EXECUTABLE _pypath.py >_pypath.txt 2>&5;then
132         PYTHON_INSTALL_PATH=`cat _pypath.txt`
133         AC_SUBST(PYTHON_INSTALL_PATH)
134         AC_MSG_RESULT($PYTHON_INSTALL_PATH)
135     else
136         AC_MSG_RESULT([failed])
137     fi
138     #rm -f _pypath.txt _pypath.py
140     if test "x$PYTHON_OK" = "xyes";then
141         AC_MSG_CHECKING([for Python-Imaging])
142     cat > conftest.c << EOF
143 #   include <Python.h>
144 #   include <Imaging.h>
146     int main()
147     {
148         Py_Main(0, 0);
149         return 0;
150     }
152         if test "$HAVE_PYTHON_IMAGING_LIB"; then
153             ac_link='$CC $CPPFLAGS $CFLAGS $PYTHON_INCLUDES conftest.c $LDFLAGS ${PYTHON_LIB2} $LIBS -o conftest${ac_exeext}'
154             if { (eval echo python.m4: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
155                 PYTHON_LIB="${PYTHON_LIB2}"
156                 AC_DEFINE([HAVE_PYTHON_IMAGING], [1], [whether Python-Imaging was found])
157                 HAVE_PYTHON_IMAGING=yes
158                 export HAVE_PYTHON_IMAGING
159                 AC_SUBST(HAVE_PYTHON_IMAGING)
160                 AC_MSG_RESULT(yes)
161             else
162                 echo "configure: failed program was:" >&5
163                 cat conftest.c >&5
164                 AC_MSG_RESULT(no)
165             fi
166         else
167             echo "(didn't find the Python-Imaging libraries)" >&5
168             AC_MSG_RESULT(no)
169         fi
170     fi
171     rm -f conftest*