From 5f3b60573e55d379b943a45159180196d27b2e90 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Wed, 21 Aug 2013 11:06:24 +0100 Subject: [PATCH] m4/am-check-python-headers.m4: Try python-config --includes Some systems (e.g. Arch Linux) put the Python C headers in a strange place, so try and run `$PYTHON-config --includes` first to find the -I options to pass to the C compiler. Fall back to the old method if it fails. Thanks to Darrell Enns for reporting the problem and suggesting a solution. I changed it a bit. --- m4/am-check-python-headers.m4 | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/m4/am-check-python-headers.m4 b/m4/am-check-python-headers.m4 index 4a97740..b9f1222 100644 --- a/m4/am-check-python-headers.m4 +++ b/m4/am-check-python-headers.m4 @@ -3,22 +3,30 @@ dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE]) dnl function also defines PYTHON_INCLUDES AC_DEFUN([AM_CHECK_PYTHON_HEADERS], [AC_REQUIRE([AM_PATH_PYTHON]) -AC_MSG_CHECKING(for headers required to compile python extensions) dnl deduce PYTHON_INCLUDES -py_prefix=`$PYTHON -c "import sys; print(sys.prefix)"` -py_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"` -PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}" -if test "$py_prefix" != "$py_exec_prefix"; then - PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}" +AC_MSG_CHECKING([for python headers using $PYTHON-config --includes]) +PYTHON_INCLUDES=`$PYTHON-config --includes` +if test $? = 0; then + AC_MSG_RESULT([$PYTHON_INCLUDES]) +else + AC_MSG_RESULT([failed, will try another way]) + py_prefix=`$PYTHON -c "import sys; print(sys.prefix)"` + py_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"` + PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}" + if test "$py_prefix" != "$py_exec_prefix"; then + PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}" + fi + AC_MSG_NOTICE([setting python headers to $PYTHON_INCLUDES]) fi -AC_SUBST(PYTHON_INCLUDES) dnl check if the headers exist: +AC_MSG_CHECKING([whether python headers are sufficient]) +AC_SUBST(PYTHON_INCLUDES) save_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES" AC_TRY_CPP([#include ],dnl -[AC_MSG_RESULT(found) +[AC_MSG_RESULT(yes) $1],dnl -[AC_MSG_RESULT(not found) +[AC_MSG_RESULT(no) $2]) CPPFLAGS="$save_CPPFLAGS" ])