python.m4 revision 03e9d9d6c1d8768a6f70217bababd82de29bc770
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl Check for python-config and substitute needed CFLAGS and LDFLAGS
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl Usage:
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl AM_PYTHON_CONFIG
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonyAC_DEFUN([AM_PYTHON_CONFIG],
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony[ AC_SUBST(PYTHON_CFLAGS)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_SUBST(PYTHON_LIBS)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl We need to check for python build flags using distutils.sysconfig
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl We cannot use python-config, as it was not available on older
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl versions of python
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_PATH_PROG(PYTHON, python)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_MSG_CHECKING([for working python])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if test -x "$PYTHON"; then
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony PYTHON_CFLAGS="`$PYTHON -c \"from distutils import sysconfig; \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony print('-I' + sysconfig.get_python_inc() + \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ' -I' + sysconfig.get_python_inc(plat_specific=True) + ' ' + \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony sysconfig.get_config_var('BASECFLAGS'))\"`"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony PYTHON_LIBS="`$PYTHON -c \"from distutils import sysconfig; \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony print(' '.join(sysconfig.get_config_var('LIBS').split() + \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony sysconfig.get_config_var('SYSLIBS').split()) + \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ' ' + sysconfig.get_config_var('BLDLIBRARY') + ' ' + \
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ' -L' + sysconfig.get_config_var('LIBDIR'))\"`"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_MSG_RESULT([yes])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony else
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_MSG_RESULT([no])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_MSG_ERROR([Please install python devel package])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony fi
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl Taken from GNOME sources
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl a macro to check for ability to create python extensions
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl function also defines PYTHON_INCLUDES
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonyAC_DEFUN([AM_CHECK_PYTHON_HEADERS],
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony[AC_REQUIRE([AM_PATH_PYTHON])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_MSG_CHECKING(for headers required to compile python extensions)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony dnl deduce PYTHON_INCLUDES
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony PYTHON_INCLUDES=-I`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'))"`
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
331e0914b4c54463a06069051f0245b4058a90c2nilgun AC_SUBST(PYTHON_INCLUDES)
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony dnl check if the headers exist:
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony save_CPPFLAGS="$CPPFLAGS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_TRY_CPP([#include <Python.h>],dnl
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony [AC_MSG_RESULT([found])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony $1],dnl
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony [AC_MSG_RESULT([not found])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony $2])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony CPPFLAGS="$save_CPPFLAGS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl Checks for a couple of functions we use that may not be defined
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonydnl in some older python versions used e.g. on RHEL5
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctonyAC_DEFUN([AM_CHECK_PYTHON_COMPAT],
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony[AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony save_CPPFLAGS="$CPPFLAGS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony save_LIBS="$LIBS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony LIBS="$LIBS $PYTHON_LIBS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_CHECK_FUNCS([PyErr_NewExceptionWithDoc])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AC_CHECK_DECLS([PyUnicode_FromString], [], [], [[#include <Python.h>]])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony CPPFLAGS="$save_CPPFLAGS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony LIBS="$save_LIBS"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony])
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony