Fix tests.
[jelmer/samba4-debian.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 AC_DEFUN([TRY_LINK_PYTHON],
17 [
18         if test $working_python = no; then
19                 ac_save_LIBS="$LIBS"
20                 ac_save_CFLAGS="$CFLAGS"
21                 LIBS="$LIBS $1"
22                 CFLAGS="$CFLAGS $2"
23
24                 AC_TRY_LINK([
25                                 #include <Python.h>
26                                 #include <stdlib.h>
27                         ],[
28                                 Py_InitModule(NULL, NULL);
29                         ],[
30                                 PYTHON_LDFLAGS="$1"
31                                 PYTHON_CFLAGS="$2"
32                                 working_python=yes
33                         ])
34                 LIBS="$ac_save_LIBS"
35                 CFLAGS="$ac_save_CFLAGS"
36         fi
37 ])
38
39 dnl assume no working python
40 working_python=no
41
42 if test -z "$PYTHON_VERSION"; then 
43         AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config])
44 else 
45         AC_PATH_PROG([PYTHON_CONFIG], [python[$PYTHON_VERSION]-config])
46 fi
47
48 if test -z "$PYTHON_CONFIG"; then
49         AC_MSG_WARN([No python-config found])
50 else
51         TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --includes`])
52         TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --cflags`])
53 fi
54
55 if test x$PYTHON != x
56 then
57         DISTUTILS_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'))"`
58         DISTUTILS_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'))"`
59         TRY_LINK_PYTHON($DISTUTILS_LDFLAGS, $DISTUTILS_CFLAGS)
60 fi
61
62 SMB_EXT_LIB(EXT_LIB_PYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CFLAGS])
63
64 AC_MSG_CHECKING(working python module support)
65 if test $working_python = yes; then
66         SMB_ENABLE(EXT_LIB_PYTHON,YES)
67         SMB_ENABLE(smbpython,YES)
68         SMB_ENABLE(LIBPYTHON,YES)
69         AC_DEFINE(HAVE_WORKING_PYTHON, 1, [Whether we have working python support])
70         AC_MSG_RESULT([yes])
71 else
72         SMB_ENABLE(EXT_LIB_PYTHON,NO)
73         SMB_ENABLE(LIBPYTHONyy,NO)
74         SMB_ENABLE(smbpython,NO)
75         AC_MSG_RESULT([no])
76 fi
77