r26100: Also check for SWIG.
[jelmer/samba4-debian.git] / source / scripting / python / config.m4
1 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
2         version to use, for example '2.3'. This string 
3         will be appended to the Python interpreter
4         canonical name.])
5
6 AC_PATH_PROG(SWIG,swig,no)
7 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
8 if test -z "$PYTHON"; then
9         working_python=no
10         AC_MSG_WARN([No python found])
11 fi
12
13 #
14 # Check for a version of Python >= 2.1.0
15 #
16 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
17 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
18         ver = string.split(sys.version)[[0]]; \
19         print ver >= '2.1.0'"`
20 if test "$ac_supports_python_ver" != "True"; then
21         working_python=no
22         AC_MSG_RESULT([no])
23 else 
24         AC_MSG_RESULT([yes])
25 fi
26
27 #
28 # Check if you have distutils, else fail
29 #
30 AC_MSG_CHECKING([for the distutils Python package])
31 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
32 if test -z "$ac_distutils_result"; then
33         AC_MSG_RESULT([yes])
34         working_python=yes
35 else
36         AC_MSG_RESULT([no])
37         working_python=no
38 fi
39
40 #
41 # Check for Python include path
42 #
43 AC_MSG_CHECKING([for Python include path])
44 if test -z "$PYTHON_CPPFLAGS"; then
45         python_path=`$PYTHON -c "import distutils.sysconfig; \
46                         print distutils.sysconfig.get_python_inc();"`
47         if test -n "${python_path}"; then
48                 python_path="-I$python_path"
49         fi
50         PYTHON_CPPFLAGS=$python_path
51 fi
52 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
53 AC_SUBST([PYTHON_CPPFLAGS])
54
55 #
56 # Check for Python library path
57 #
58 AC_MSG_CHECKING([for Python library path])
59 if test -z "$PYTHON_LDFLAGS"; then
60         # (makes two attempts to ensure we've got a version number
61         # from the interpreter)
62         py_version=`$PYTHON -c "from distutils.sysconfig import *; \
63                 from string import join; \
64                 print join(get_config_vars('VERSION'))"`
65         if test "$py_version" == "[None]"; then
66                 if test -n "$PYTHON_VERSION"; then
67                         py_version=$PYTHON_VERSION
68                 else
69                         py_version=`$PYTHON -c "import sys; \
70                                 print sys.version[[:3]]"`
71                 fi
72         fi
73
74         PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
75                 from string import join; \
76                 print '-L' + get_python_lib(0,1), \
77                         '-lpython';"`$py_version
78 fi              
79 AC_MSG_RESULT([$PYTHON_LDFLAGS])
80 AC_SUBST([PYTHON_LDFLAGS])
81
82 #
83 # Check for site packages
84 #
85 AC_MSG_CHECKING([for Python site-packages path])
86 if test -z "$PYTHON_SITE_PKG"; then
87         PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
88                         print distutils.sysconfig.get_python_lib(0,0);"`
89 fi
90 AC_MSG_RESULT([$PYTHON_SITE_PKG])
91 AC_SUBST([PYTHON_SITE_PKG])
92
93 #
94 # libraries which must be linked in when embedding
95 #
96 AC_MSG_CHECKING(python extra libraries)
97 if test -z "$PYTHON_EXTRA_LIBS"; then
98    PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
99                         conf = distutils.sysconfig.get_config_var; \
100                         print conf('LOCALMODLIBS'), conf('LIBS')"`
101 fi
102 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
103 AC_SUBST(PYTHON_EXTRA_LIBS)
104
105 #
106 # linking flags needed when embedding
107 #
108 AC_MSG_CHECKING(python extra linking flags)
109 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
110         PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
111                 conf = distutils.sysconfig.get_config_var; \
112                 print conf('LINKFORSHARED')"`
113 fi
114 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
115 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
116
117 SMB_EXT_LIB(LIBPYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CPPFLAGS])
118
119 if test x$working_python = xyes && test x$SWIG != xno
120 then
121         SMB_ENABLE(LIBPYTHON,YES)
122 else
123         SMB_ENABLE(LIBPYTHON,NO)
124 fi