Use Python's distutils to determine include and site-packages directories.
authorHilko Bengen <bengen@hilluzination.de>
Tue, 3 May 2011 22:29:39 +0000 (00:29 +0200)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 9 May 2011 13:26:12 +0000 (14:26 +0100)
The code has been taken from specifically ac_python_devel.m4 published
at <http://ac-archive.sf.net/>, it has turned out to be less
error-prone on my Debian system.

configure.ac

index b82a841..5805ddd 100644 (file)
@@ -232,47 +232,25 @@ AC_CHECK_PROG([PYTHON],[python],[python],[no])
 
 PYTHON_PREFIX=
 PYTHON_VERSION=
-PYTHON_INCLUDEDIR=
-PYTHON_SITE_PACKAGES=
 
 if test "x$PYTHON" != "xno"; then
     PYTHON_PREFIX=`$PYTHON -c "import sys; print sys.prefix"`
     PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
-    for d in \
-        $PYTHON_PREFIX/include/python$PYTHON_VERSION \
-        /usr/include/python$PYTHON_VERSION \
-        /usr/local/include/python$PYTHON_VERSION
-    do
-        AC_MSG_CHECKING([Python.h in $d])
-        if test -r "$d/Python.h"; then
-            AC_MSG_RESULT([found])
-            PYTHON_INCLUDEDIR=$d
-            break
-        fi
-        AC_MSG_RESULT([not found])
-    done
-    if test "x$PYTHON_INCLUDEDIR" = "x"; then
-        AC_MSG_WARN([Python include directory not found])
+
+    AC_MSG_CHECKING([for Python include path])
+    if test -z "$PYTHON_INCLUDEDIR"; then
+        python_path=`$PYTHON -c "import distutils.sysconfig; \
+                                 print (distutils.sysconfig.get_python_inc ());"`
+        PYTHON_INCLUDEDIR=$python_path
     fi
+    AC_MSG_RESULT([$PYTHON_INCLUDEDIR])
 
-    for d in \
-        $PYTHON_PREFIX/lib64/python$PYTHON_VERSION/site-packages \
-        $PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages \
-        /usr/lib64/python$PYTHON_VERSION/site-packages \
-        /usr/lib/python$PYTHON_VERSION/site-packages \
-        /usr/local/lib/python$PYTHON_VERSION/site-packages
-    do
-        AC_MSG_CHECKING([for $d])
-        if test -d "$d"; then
-            AC_MSG_RESULT([found])
-            PYTHON_SITE_PACKAGES=$d
-            break
-        fi
-        AC_MSG_RESULT([not found])
-    done
-    if test "x$PYTHON_SITE_PACKAGES" = "x"; then
-        AC_MSG_WARN([Python site-packages directory not found])
+    AC_MSG_CHECKING([for Python site-packages path])
+    if test -z "$PYTHON_SITE_PACKAGES"; then
+        PYTHON_SITE_PACKAGES=`$PYTHON -c "import distutils.sysconfig; \
+                print (distutils.sysconfig.get_python_lib(0,0));"`
     fi
+    AC_MSG_RESULT([$PYTHON_SITE_PACKAGES])
 
     old_LIBS="$LIBS"
     LIBS="$LIBS -lpython$PYTHON_VERSION"