1 dnl Autoconf macros for finding a Python development environment
3 dnl Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
4 dnl Published under the GNU GPL, v3 or later
6 AC_ARG_VAR([PYTHON_VER],[The installed Python
7 version to use, for example '2.3'. This string
8 will be appended to the Python interpreter
11 AC_DEFUN([TRY_LINK_PYTHON],
13 if test $working_python = no; then
15 ac_save_CFLAGS="$CFLAGS"
21 /* we have our own configure tests */
24 Py_InitModule(NULL, NULL);
31 CFLAGS="$ac_save_CFLAGS"
35 dnl Try to find a Python implementation including header files
36 dnl AC_SAMBA_PYTHON_DEVEL(RUN-IF-FOUND, RUN-IF-NOT-FOUND)
38 dnl Will set the following variables:
40 dnl $PYTHON_CONFIG (if found)
43 AC_DEFUN([AC_SAMBA_PYTHON_DEVEL],
45 if test -z "$PYTHON_VER"; then
46 AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python])
48 AC_PATH_PROG([PYTHON],[python[$PYTHON_VER]])
50 if test -z "$PYTHON"; then
52 AC_MSG_WARN([No python found])
55 dnl assume no working python
58 if test -z "$PYTHON_VER"; then
59 AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config])
61 AC_PATH_PROG([PYTHON_CONFIG], [python[$PYTHON_VER]-config])
64 if test -z "$PYTHON_CONFIG"; then
65 AC_MSG_WARN([No python-config found])
67 TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --includes`])
68 TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --cflags`])
69 if test x$working_python = xno; then
70 # It seems the library path isn't included on some systems
71 base=`$PYTHON_CONFIG --prefix`
72 TRY_LINK_PYTHON([`echo -n -L${base}/lib " "; $PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --includes`])
73 TRY_LINK_PYTHON([`echo -n -L${base}/lib " "; $PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --cflags`])
79 DISTUTILS_CFLAGS=`$PYTHON -c "from distutils import sysconfig; \
80 print '-I%s -I%s %s' % ( \
81 sysconfig.get_python_inc(), \
82 sysconfig.get_python_inc(plat_specific=1), \
83 sysconfig.get_config_var('CFLAGS'))"`
84 DISTUTILS_LDFLAGS=`$PYTHON -c "from distutils import sysconfig; \
85 print '%s %s -lpython%s -L%s %s -L%s' % ( \
86 sysconfig.get_config_var('LIBS'), \
87 sysconfig.get_config_var('SYSLIBS'), \
88 sysconfig.get_config_var('VERSION'), \
89 sysconfig.get_config_var('LIBDIR'), \
90 sysconfig.get_config_var('LDFLAGS'), \
91 sysconfig.get_config_var('LIBPL'))"`
92 TRY_LINK_PYTHON($DISTUTILS_LDFLAGS, $DISTUTILS_CFLAGS)
95 AC_MSG_CHECKING(working python module support)
96 if test $working_python = yes; then