Also move \linebreaksign to the samba LaTeX package.
[Samba.git] / m4 / check_python.m4
blob94537663137c647f50d49ebe632265b1335c2a74
1 dnl Autoconf macros for finding a Python development environment
2 dnl
3 dnl Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
4 dnl Published under the GNU GPL, v3 or later
5 dnl
6 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
7         version to use, for example '2.3'. This string 
8         will be appended to the Python interpreter
9         canonical name.])
11 AC_DEFUN([TRY_LINK_PYTHON],
13         if test $working_python = no; then
14                 ac_save_LIBS="$LIBS"
15                 ac_save_CFLAGS="$CFLAGS"
16                 LIBS="$LIBS $1"
17                 CFLAGS="$CFLAGS $2"
19                 AC_TRY_LINK([
20                                 /* we have our own configure tests */
21                                 #include <Python.h>
22                         ],[
23                                 Py_InitModule(NULL, NULL);
24                         ],[
25                                 PYTHON_LDFLAGS="$1"
26                                 PYTHON_CFLAGS="$2"
27                                 working_python=yes
28                         ])
29                 LIBS="$ac_save_LIBS"
30                 CFLAGS="$ac_save_CFLAGS"
31         fi
34 dnl Try to find a Python implementation including header files
35 dnl AC_SAMBA_PYTHON_DEVEL(RUN-IF-FOUND, RUN-IF-NOT-FOUND)
36 dnl
37 dnl Will set the following variables:
38 dnl $PYTHON
39 dnl $PYTHON_CONFIG (if found)
40 dnl $PYTHON_CFLAGS
41 dnl $PYTHON_LDFLAGS
42 AC_DEFUN([AC_SAMBA_PYTHON_DEVEL],
44         if test -z "$PYTHON_VERSION"; then
45                 AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python])
46         else
47                 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
48         fi
49         if test -z "$PYTHON"; then
50                 working_python=no
51                 AC_MSG_WARN([No python found])
52         fi
54         dnl assume no working python
55         working_python=no
57         if test -z "$PYTHON_VERSION"; then 
58                 AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config])
59         else 
60                 AC_PATH_PROG([PYTHON_CONFIG], [python[$PYTHON_VERSION]-config])
61         fi
63         if test -z "$PYTHON_CONFIG"; then
64                 AC_MSG_WARN([No python-config found])
65         else
66                 TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --includes`])
67                 TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --cflags`])
68                 if test x$working_python = xno; then
69                         # It seems the library path isn't included on some systems
70                         base=`$PYTHON_CONFIG --prefix`
71                         TRY_LINK_PYTHON([`echo -n -L${base}/lib " "; $PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --includes`])
72                         TRY_LINK_PYTHON([`echo -n -L${base}/lib " "; $PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --cflags`])
73                 fi
74         fi
76         if test x$PYTHON != x
77         then
78                 DISTUTILS_CFLAGS=`$PYTHON -c "from distutils import sysconfig; \
79                                               print '-I%s -I%s %s' % ( \
80                                                         sysconfig.get_python_inc(), \
81                                                         sysconfig.get_python_inc(plat_specific=1), \
82                                                         sysconfig.get_config_var('CFLAGS'))"`
83                 DISTUTILS_LDFLAGS=`$PYTHON -c "from distutils import sysconfig; \
84                                                print '%s %s -lpython%s -L%s %s -L%s' % ( \
85                                                         sysconfig.get_config_var('LIBS'), \
86                                                         sysconfig.get_config_var('SYSLIBS'), \
87                                                         sysconfig.get_config_var('VERSION'), \
88                                                         sysconfig.get_config_var('LIBDIR'), \
89                                                         sysconfig.get_config_var('LDFLAGS'), \
90                                                         sysconfig.get_config_var('LIBPL'))"`
91                 TRY_LINK_PYTHON($DISTUTILS_LDFLAGS, $DISTUTILS_CFLAGS)
92         fi
94         AC_MSG_CHECKING(working python module support)
95         if test $working_python = yes; then
96                 AC_MSG_RESULT([yes])
97                 $1
98         else
99                 AC_MSG_RESULT([no])
100                 $2
101         fi