r26666: python: Prefer newer Python versions as they use const properly.
[ira/wip.git] / source / scripting / python / config.m4
1 m4_include(scripting/python/ac_pkg_swig.m4)
2
3 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
4         version to use, for example '2.3'. This string 
5         will be appended to the Python interpreter
6         canonical name.])
7
8 AC_PROG_SWIG(1.3.31)
9
10 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
11 if test -z "$PYTHON"; then
12         working_python=no
13         AC_MSG_WARN([No python found])
14 fi
15
16 if test -z "$PYTHON_VERSION"; then 
17         AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config])
18 else 
19         AC_PATH_PROG([PYTHON_CONFIG], [python[$PYTHON_VERSION]-config])
20 fi
21
22 if test -z "$PYTHON_CONFIG"; then
23         working_python=no
24         AC_MSG_WARN([No python-config found])
25 else
26         working_python=yes
27         PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
28         PYTHON_CFLAGS=`$PYTHON_CONFIG --cflags`
29 fi
30
31 if test $working_python = no && test x$PYTHON != x
32 then
33         PYTHON_CFLAGS=`$PYTHON -c "from distutils import sysconfig; print '-I%s -I%s %s' % (sysconfig.get_python_inc(), sysconfig.get_python_inc(plat_specific=True), sysconfig.get_config_var('CFLAGS'))"`
34         PYTHON_LDFLAGS=`$PYTHON -c "from distutils import sysconfig; print '%s %s -lpython%s -L%s' % (sysconfig.get_config_var('LIBS'), sysconfig.get_config_var('SYSLIBS'), sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('LIBPL'))"`
35         working_python=yes
36 fi
37
38 SMB_EXT_LIB(EXT_LIB_PYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CFLAGS])
39
40 AC_MSG_CHECKING(working python module support)
41 if test x$working_python = xyes
42 then
43         ac_save_LIBS="$LIBS"
44         ac_save_CFLAGS="$CFLAGS"
45         LIBS="$LIBS $PYTHON_LDFLAGS"
46         CFLAGS="$CFLAGS $PYTHON_CFLAGS"
47
48         AC_TRY_LINK([
49                         #include <Python.h>
50                         #include <stdlib.h>
51                 ],[
52                         Py_InitModule(NULL, NULL);
53                 ],[
54                         SMB_ENABLE(EXT_LIB_PYTHON,YES)
55                         SMB_ENABLE(smbpython,YES)
56                         SMB_ENABLE(LIBPYTHON,YES)
57                         AC_MSG_RESULT([yes])
58                 ],[
59                         SMB_ENABLE(EXT_LIB_PYTHON,NO)
60                         SMB_ENABLE(LIBPYTHON,NO)
61                         SMB_ENABLE(smbpython,NO)
62                         AC_MSG_RESULT([no])
63                 ])
64
65         LIBS="$ac_save_LIBS"
66         CFLAGS="$ac_save_CFLAGS"
67 else
68         SMB_ENABLE(EXT_LIB_PYTHON,NO)
69         SMB_ENABLE(LIBPYTHONyy,NO)
70         SMB_ENABLE(smbpython,NO)
71         AC_MSG_RESULT([no])
72 fi