From: stevenj Date: Wed, 7 Jul 2010 15:17:05 +0000 (-0400) Subject: better checking for Python and Numpy include directories; thanks to Nathaniel Smith... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8164b6e3b9f9f3854a50c6b5262fec8e7175d7a6;p=nlopt.git better checking for Python and Numpy include directories; thanks to Nathaniel Smith for the tip about numpy.get_include() darcs-hash:20100707151705-c8de0-ce47965d05109ef499e8cbe8b395a682818c0804.gz --- diff --git a/configure.ac b/configure.ac index 8a49f13..74520c3 100644 --- a/configure.ac +++ b/configure.ac @@ -153,24 +153,25 @@ else dnl Python: AM_PATH_PYTHON([],[have_python=yes],[have_python=no]) if test $have_python = yes; then - pdir=`dirname $pythondir | sed 's,/lib/,/include/,'` - pdir=`eval echo $pdir` AC_MSG_CHECKING([for Python include directory]) - for PYTHON_INCLUDE_DIR in "$pdir" /usr/include/python$PYTHON_VERSION /usr/local/include/python$PYTHON_VERSION unknown; do - test -d "$PYTHON_INCLUDE_DIR" && break - done - AC_MSG_RESULT([$PYTHON_INCLUDE_DIR]) - if test "x$PYTHON_INCLUDE_DIR" = xunknown; then - AC_MSG_WARN([disabling Python wrappers]) - have_python=no - else - save_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$CPPFLAGS -I$PYTHON_INCLUDE_DIR" - AC_CHECK_HEADER([numpy/arrayobject.h],[],[ - AC_MSG_WARN([disabling Python wrappers]) - have_python=no],[#include ]) - CPPFLAGS=$save_CPPFLAGS + pinc=`echo "import distutils.sysconfig; print distutils.sysconfig.get_python_inc()" | $PYTHON - 2>/dev/null` + AC_MSG_RESULT([${pinc:-unknown}]) + test -n "$pinc" && PYTHON_INCLUDES="-I$pinc" + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES" + AC_CHECK_HEADER([Python.h], [], [AC_MSG_WARN([disabling Python wrappers]) + have_python=no]) + if test $have_python = yes; then + AC_MSG_CHECKING([for Numpy include directory]) + pinc=`echo "import numpy; print numpy.get_include()" | $PYTHON - 2>/dev/null` + AC_MSG_RESULT([${pinc:-unknown}]) + test -n "$pinc" && PYTHON_INCLUDES="$PYTHON_INCLUDES -I$pinc" + CPPFLAGS="$save_CPPFLAGS $PYTHON_INCLUDES" + AC_CHECK_HEADER([numpy/arrayobject.h],[],[ + AC_MSG_WARN([disabling Python wrappers]) + have_python=no],[#include ]) fi + CPPFLAGS=$save_CPPFLAGS fi fi # with_python @@ -180,7 +181,7 @@ fi # if enable_shared AC_SUBST(GUILE_SITEDIR) AC_SUBST(GUILE_CPPFLAGS) AC_SUBST(GUILE_LIBS) -AC_SUBST(PYTHON_INCLUDE_DIR) +AC_SUBST(PYTHON_INCLUDES) AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown") AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes") diff --git a/swig/Makefile.am b/swig/Makefile.am index 2434d71..e22bb62 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -25,7 +25,7 @@ endif _nlopt_la_SOURCES = nlopt-python.cpp _nlopt_la_LIBADD = ../libnlopt@NLOPT_SUFFIX@.la _nlopt_la_LDFLAGS = -module -no-undefined -version-info @SHARED_VERSION_INFO@ -_nlopt_la_CPPFLAGS = -I$(PYTHON_INCLUDE_DIR) -I$(top_builddir)/api +_nlopt_la_CPPFLAGS = $(PYTHON_INCLUDES) -I$(top_builddir)/api if WITH_PYTHON python_PYTHON = nlopt.py