pyconfigure

(Brandon Invergo)
2012-09-11: separate PC_PYTHON_PATH into smaller macros

separate PC_PYTHON_PATH into smaller macros

diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -8,35 +8,61 @@ AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I .")
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE([-Wall -Werror gnu])
 
-PC_PYTHON_PATH(python_min_ver)
+AC_PROG_PYTHON()
 
-# check if we are building for python 3
+# check that the Python version is at least python_min_ver (2.7.2, above)
+PC_PYTHON_VERIFY_VERSION([$PYTHON], python_min_ver, ,
+			 AC_MSG_ERROR(Python interpreter too old))
+
+# check if we are building for Python 3
 PC_PYTHON_CHECK_VERSION([$PYTHON], [3.0],
-                         build_py3k=true,
-                         build_py3k=false)
+                          build_py3k=true,
+                          build_py3k=false)
 
-# if building for python 3 make sure we have the minimum version supported
-if test $build_py3k = true ; then
-  AC_MSG_CHECKING([for $PYTHON >=] python3_min_ver)
-  PC_PYTHON_CHECK_VERSION([$PYTHON], python3_min_ver,
-                          [AC_MSG_RESULT(yes)],
-                          [AC_MSG_ERROR(too old)])
-fi
+PC_PYTHON_CHECK_PREFIX
+
+PC_PYTHON_CHECK_EXECPREFIX
+
+PC_PYTHON_CHECK_INCLUDES
+
+PC_PYTHON_CHECK_LIBS
+
+PC_PYTHON_CHECK_CFLAGS
+
+PC_PYTHON_CHECK_LDFLAGS
+
+PC_PYTHON_CHECK_EXTENSION_SUFFIX
+
+PC_PYTHON_CHECK_ABI_FLAGS
+
+PC_PYTHON_CHECK_PLATFORM
+
+PC_PYTHON_CHECK_SITE_DIR
+
+PC_PYTHON_SITE_PACKAGE_DIR
+
+PC_PYTHON_CHECK_EXEC_DIR
+
+PC_PYTHON_EXEC_PACKAGE_DIR
+
+# # if building for python 3 make sure we have the minimum version supported
+# if test $build_py3k = true ; then
+#   AC_MSG_CHECKING([for $PYTHON >=] python3_min_ver)
+#   PC_PYTHON_CHECK_VERSION([$PYTHON], python3_min_ver,
+#                           [AC_MSG_RESULT(yes)],
+#                           [AC_MSG_ERROR(too old)])
+# fi
 
 # check for python.h
 #AC_MSG_CHECKING([for python.h])
 #AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
-AC_CHECK_HEADER([Python.h], , [AC_MSG_ERROR(could not find Python headers)])
+#AC_CHECK_HEADER([Python.h], , [AC_MSG_ERROR(could not find Python headers)])
 
 # check if Python library foo exists
-PC_PYTHON_CHECK_LIB([dbus],
-                    [AC_MSG_RESULT(yes)],
-                    [AC_MSG_ERROR(missing)])
+PC_PYTHON_CHECK_LIB([dbus],, [AC_MSG_ERROR(missing)])
 
 # test if Python library foo can do bar()
-PC_PYTHON_CHECK_FUNC([dbus], [get_default_main_loop], , 
-                     [AC_MSG_RESULT(yes)],
-                     [AC_MSG_RESULT(no)])
+PC_PYTHON_CHECK_FUNC([dbus], [get_default_main_loop], , , [AC_MSG_RESULT(no)])
 
 AC_CONFIG_FILES([])
 AC_OUTPUT
diff --git a/m4/python.m4 b/m4/python.m4
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -12,7 +12,7 @@
 # the Automake namespace and to fit naming conventions for Autoconf
 # language definitions.
 
-# The remaining macros were written by Brandon Invergo and distributed
+# The remaining macros were written or adapted by Brandon Invergo and distributed
 # under the same terms. 
 
 
@@ -25,6 +25,8 @@
 #
 # 3. Looking for a compiler
 #    And possibly the associated preprocessor.
+#
+# 4. Looking for specific libs & functionality
 
 
 ## ----------------------- ##
@@ -57,8 +59,8 @@ AU_DEFUN([AC_LANG_PYTHON], [AC_LANG(Pyth
 m4_define([AC_LANG_PROGRAM(Python)], [dnl
 @%:@!$PYTHON
 $1
-if __name__ == "__main__":
-    $2
+if __name__ == '__main__':
+$2
 ])
 
 
@@ -69,13 +71,15 @@ m4_define([_AC_LANG_IO_PROGRAM(Python)],
 [AC_LANG_PROGRAM([dnl
 import sys
 try:
-    h = open("conftest.out")
+    h = open('conftest.out')
 except:
     sys.exit(1)
 else:
     close(h)
     sys.exit(0)
-], [pass])])
+], [
+    pass
+])])
 
 
 # _AC_LANG_CALL(Python)([PROLOGUE], [FUNCTION])
@@ -90,184 +94,321 @@ m4_define([_AC_LANG_CALL(Python)],
 ## -------------------------------------------- ##
 
 
-# PC_PYTHON_PATH_PY([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
-# ---------------------------------------------------------------------------
-AC_DEFUN([PC_PYTHON_PATH],
- [
-  dnl Find a Python interpreter.  Python versions prior to 2.0 are not
-  dnl supported. (2.0 was released on October 16, 2000).
-  m4_define_default([_PC_PYTHON_INTERPRETER_LIST],
-[python python2 python3 python3.2 python3.1 python3.0 python2.7 dnl
- python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
+AC_DEFUN([AC_LANG_COMPILER(Python)],
+[AC_REQUIRE([AC_PROG_PYTHON])])
 
-  AC_ARG_VAR([PYTHON], [the Python interpreter])
 
-  m4_if([$1],[],[
-    dnl No version check is needed.
-    # Find any Python interpreter.
-    if test -z "$PYTHON"; then
-      AC_PATH_PROGS([PYTHON], _PC_PYTHON_INTERPRETER_LIST, :)
-    fi
-    pc_display_PYTHON=python
-  ], [
-    dnl A version check is needed.
-    if test -n "$PYTHON"; then
-      # If the user set $PYTHON, use it and don't search something else.
-      AC_MSG_CHECKING([whether $PYTHON version is >= $1])
-      PC_PYTHON_CHECK_VERSION([$PYTHON], [$1],
-			      [AC_MSG_RESULT([yes])],
-			      [AC_MSG_RESULT([no])
-			       AC_MSG_ERROR([Python interpreter is too old])])
-      pc_display_PYTHON=$PYTHON
-    else
-      # Otherwise, try each interpreter until we find one that satisfies
-      # VERSION.
-      AC_CACHE_CHECK([for a Python interpreter with version >= $1],
-	[pc_cv_pathless_PYTHON],[
-	for pc_cv_pathless_PYTHON in _PC_PYTHON_INTERPRETER_LIST none; do
-	  test "$pc_cv_pathless_PYTHON" = none && break
-	  PC_PYTHON_CHECK_VERSION([$pc_cv_pathless_PYTHON], [$1], [break])
-	done])
-      # Set $PYTHON to the absolute path of $pc_cv_pathless_PYTHON.
-      if test "$pc_cv_pathless_PYTHON" = none; then
-	PYTHON=:
-      else
-        AC_PATH_PROG([PYTHON], [$pc_cv_pathless_PYTHON])
-      fi
-      pc_display_PYTHON=$pc_cv_pathless_PYTHON
-    fi
-  ])
+# AC_PROG_PYTHON(PROG-TO-CHECK-FOR)
+# ---------------------------------
+# Find a Python interpreter.  Python versions prior to 2.0 are not
+# supported. (2.0 was released on October 16, 2000).
+AC_DEFUN([AC_PROG_PYTHON],
+[AC_ARG_VAR([PYTHON], [the Python interpreter])
+m4_define_default([_PC_PYTHON_INTERPRETER_LIST],
+                  [python python2 python3 python3.2 python3.1 python3.0 python2.7 dnl
+                   python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
+m4_ifval([$1],
+	[AC_PATH_PROGS(PYTHON, [$1 _PC_PYTHON_INTERPRETER_LIST])],
+	[AC_PATH_PROGS(PYTHON, [_PC_PYTHON_INTERPRETER_LIST])])
+])
+  
 
-  if test "$PYTHON" = :; then
-  dnl Run any user-specified action, or abort.
-    m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
-  else
+# PC_PYTHON_PROG_PYTHONCONFIG(PROG-TO-CHECK-FOR)
+# ----------------------------------------------
+# Find the python-config program
+AC_DEFUN([PC_PYTHON_PROG_PYTHONCONFIG],
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
+AC_ARG_VAR([PYTHONCONFIG], [the Python-config program])
+m4_define([_PYTHON_BASENAME], [`basename $PYTHON`])
+m4_ifval([$1],
+	[AC_PATH_PROGS(PYTHONCONFIG, [$1 _PYTHON_BASENAME-config])],
+	[AC_PATH_PROG(PYTHONCONFIG, _PYTHON_BASENAME-config)])
+dnl if test -n "$PYTHONCONFIG"; then
+dnl    m4_define_default([_PC_PYTHON_VER_STR],
+dnl                      [python python2 python3 python3.2 python3.1 python3.0 python2.7 dnl
+dnl                       python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
+dnl    m4_define(_PC_PYTHON_VER_LIST, m4_split(_PC_PYTHON_VER_STR))
+dnl    m4_define(_PC_PYTHON_CONFIG_LIST, m4_combine([ ],
+dnl        _PC_PYTHON_CONFIG_LIST, [-], [config]))
+dnl    m4_ifval([$1],
+dnl  	[AC_PATH_PROGS(PYTHONCONFIG, [$1 _PC_PYTHON_CONFIG_LIST])],
+dnl 	[AC_PATH_PROG(PYTHONCONFIG, _PC_PYTHON_CONFIG_LIST)])
+dnl fi
+]) # PC_PYTHON_PROG_PYTHONCONFIG
 
-  dnl Query Python for its version number.  Getting [:3] seems to be
-  dnl the best way to do this; it's what "site.py" does in the standard
-  dnl library.
 
-  AC_CACHE_CHECK([for $pc_display_PYTHON version], [pc_cv_python_version],
-    [pc_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
-  AC_SUBST([PYTHON_VERSION], [$pc_cv_python_version])
-
-  dnl Use the values of $prefix and $exec_prefix for the corresponding
-  dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
-  dnl distinct variables so they can be overridden if need be.  However,
-  dnl general consensus is that you shouldn't need this ability.
-
-  AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
-  AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
-
-  dnl At times (like when building shared libraries) you may want
-  dnl to know which OS platform Python thinks this is.
-
-  AC_CACHE_CHECK([for $pc_display_PYTHON platform], [pc_cv_python_platform],
-    [pc_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
-  AC_SUBST([PYTHON_PLATFORM], [$pc_cv_python_platform])
-
-
-  dnl Set up 4 directories:
-
-  dnl pythondir -- where to install python scripts.  This is the
-  dnl   site-packages directory, not the python standard library
-  dnl   directory like in previous automake betas.  This behavior
-  dnl   is more consistent with lispdir.m4 for example.
-  dnl Query distutils for this directory.
-  AC_CACHE_CHECK([for $pc_display_PYTHON script directory],
-    [pc_cv_python_pythondir],
-    [if test "x$prefix" = xNONE
-     then
-       pc_py_prefix=$ac_default_prefix
-     else
-       pc_py_prefix=$prefix
-     fi
-     pc_cv_python_pythondir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(0,0,prefix='$pc_py_prefix'))" 2>/dev/null`
-     case $pc_cv_python_pythondir in
-     $pc_py_prefix*)
-       pc__strip_prefix=`echo "$pc_py_prefix" | sed 's|.|.|g'`
-       pc_cv_python_pythondir=`echo "$pc_cv_python_pythondir" | sed "s,^$pc__strip_prefix,$PYTHON_PREFIX,"`
-       ;;
-     *)
-       case $pc_py_prefix in
-         /usr|/System*) ;;
-         *)
-	  pc_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
-	  ;;
-       esac
-       ;;
-     esac
-    ])
-  AC_SUBST([pythondir], [$pc_cv_python_pythondir])
-
-  dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
-  dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
-  dnl   more consistent with the rest of automake.
-
-  AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
-
-  dnl pyexecdir -- directory for installing python extension modules
-  dnl   (shared libraries)
-  dnl Query distutils for this directory.
-  AC_CACHE_CHECK([for $pc_display_PYTHON extension module directory],
-    [pc_cv_python_pyexecdir],
-    [if test "x$exec_prefix" = xNONE
-     then
-       pc_py_exec_prefix=$pc_py_prefix
-     else
-       pc_py_exec_prefix=$exec_prefix
-     fi
-     pc_cv_python_pyexecdir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(1,0,prefix='$pc_py_exec_prefix'))" 2>/dev/null`
-     case $pc_cv_python_pyexecdir in
-     $pc_py_exec_prefix*)
-       pc__strip_prefix=`echo "$pc_py_exec_prefix" | sed 's|.|.|g'`
-       pc_cv_python_pyexecdir=`echo "$pc_cv_python_pyexecdir" | sed "s,^$pc__strip_prefix,$PYTHON_EXEC_PREFIX,"`
-       ;;
-     *)
-       case $pc_py_exec_prefix in
-         /usr|/System*) ;;
-         *)
-	   pc_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
-	   ;;
-       esac
-       ;;
-     esac
-    ])
-  AC_SUBST([pyexecdir], [$pc_cv_python_pyexecdir])
-
-  dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
-
-  AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
-
-  dnl Run any user-specified action.
-  $2
-  fi
-
-])
-
-
+# PC_PYTHON_VERIFY_VERSION(PYTHON-PROGRAM, VERSION, [ACTION-IF-TRUE], [ACTION-IF-NOT-FOUND])
 # ---------------------------------------------------------------------------
 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
 # Run ACTION-IF-FALSE otherwise.
 # This test uses sys.hexversion instead of the string equivalent (first
 # word of sys.version), in order to cope with versions such as 2.2c1.
 # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
+AC_DEFUN([PC_PYTHON_VERIFY_VERSION],
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
+AC_CACHE_CHECK([that Python > '$2'],
+    [pc_cv_python_min_version],
+    [AC_LANG_PUSH(Python)[]dnl
+     AC_RUN_IFELSE(
+        [AC_LANG_PROGRAM([dnl
+import sys
+], [dnl
+    # split strings by '.' and convert to numeric.  Append some zeros
+    # because we need at least 4 digits for the hex conversion.
+    # map returns an iterator in Python 3.0 and a list in 2.x
+    minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
+    minverhex = 0
+    # xrange is not present in Python 3.0 and range returns an iterator
+    for i in list(range(0, 4)):
+        minverhex = (minverhex << 8) + minver[[i]]
+    sys.exit(sys.hexversion < minverhex)
+])], 
+         [pc_cv_python_min_version="yes"], 
+         [pc_cv_python_min_version="no"])
+     AC_LANG_POP(Python)[]dnl
+    ])
+AS_IF([test "$pc_cv_python_min_version" = "no"], [$4], [$3])
+])# PC_PYTHON_VERIFY_VERSION
+
+
+# PC_PYTHON_CHECK_VERSION
+# -----------------------
+# Query Python for its version number.  Getting [:3] seems to be
+# the best way to do this; it's what "site.py" does in the standard
+# library.
 AC_DEFUN([PC_PYTHON_CHECK_VERSION],
- [prog="import sys
-# split strings by '.' and convert to numeric.  Append some zeros
-# because we need at least 4 digits for the hex conversion.
-# map returns an iterator in Python 3.0 and a list in 2.x
-minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
-minverhex = 0
-# xrange is not present in Python 3.0 and range returns an iterator
-for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
-sys.exit(sys.hexversion < minverhex)"
-  AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
+AC_CACHE_CHECK([for $1 version], 
+    [pc_cv_python_version],
+    [AC_LANG_PUSH(Python)[]dnl
+     AC_LANG_CONFTEST([
+         AC_LANG_PROGRAM([dnl
+import sys
+], [dnl
+    sys.stdout.write(sys.version[[:3]])
+])])
+     pc_cv_python_version=`$PYTHON conftest.py`
+     AC_LANG_POP(Python)[]dnl
+    ])
+AC_SUBST([PYTHON_VERSION], [$pc_cv_python_version])
+])# PC_PYTHON_CHECK_VERSION
 
-AC_DEFUN([AC_PROG_PYTHON], [PC_PYTHON_PATH])
 
-AC_DEFUN([AC_LANG_COMPILER(Python)],
-[AC_REQUIRE([AC_PROG_PYTHON])])
+# PC_PYTHON_CHECK_PREFIX
+# ----------------------
+# Use the value of $prefix for the corresponding value of
+# PYTHON_PREFIX. This is made a distinct variable so it can be
+# overridden if need be.  However, general consensus is that you
+# shouldn't need this ability.
+AC_DEFUN([PC_PYTHON_CHECK_PREFIX],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python prefix], [pc_cv_python_prefix],
+    [pc_cv_python_prefix=`$PYTHONCONFIG --prefix`])
+AC_SUBST([PYTHON_PREFIX], [$pc_cv_python_prefix])])
+
+
+# PC_PYTHON_CHECK_EXECPREFIX
+# --------------------------
+# Like above, but for $exec_prefix
+AC_DEFUN([PC_PYTHON_CHECK_EXECPREFIX],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python exec-prefix], [pc_cv_python_exec_prefix],
+    [pc_cv_python_exec_prefix=`$PYTHONCONFIG --exec-prefix`])
+AC_SUBST([PYTHON_EXEC_PREFIX], [$pc_cv_python_exec_prefix])])
+
+
+# PC_PYTHON_CHECK_INCLUDES
+# ------------------------
+# Find the Python header file include flags (ie
+# '-I/usr/include/python')
+AC_DEFUN([PC_PYTHON_CHECK_INCLUDES],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python includes], [pc_cv_python_includes],
+    [pc_cv_python_includes=`$PYTHONCONFIG --includes`])
+AC_SUBST([PYTHON_INCLUDES], [$pc_cv_python_includes])])
+
+
+# PC_PYTHON_CHECK_LIBS
+# --------------------
+# Find the Python lib flags (ie '-lpython')
+AC_DEFUN([PC_PYTHON_CHECK_LIBS],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python libs], [pc_cv_python_libs],
+    [pc_cv_python_libs=`$PYTHONCONFIG --libs`])
+AC_SUBST([PYTHON_LIBS], [$pc_cv_python_libs])])
+
+
+# PC_PYTHON_CHECK_CFLAGS
+# ----------------------
+# Find the Python CFLAGS
+AC_DEFUN([PC_PYTHON_CHECK_CFLAGS],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python CFLAGS], [pc_cv_python_CFLAGS],
+    [pc_cv_python_cflags=`$PYTHONCONFIG --cflags`])
+AC_SUBST([PYTHON_CFLAGS], [$pc_cv_python_cflags])])
+
+
+# PC_PYTHON_CHECK_LDFLAGS
+# -----------------------
+# Find the Python LDFLAGS
+AC_DEFUN([PC_PYTHON_CHECK_LDFLAGS],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python LDFLAGS], [pc_cv_python_LDFLAGS],
+    [pc_cv_python_cflags=`$PYTHONCONFIG --ldflags`])
+AC_SUBST([PYTHON_LDFLAGS], [$pc_cv_python_ldflags])])
+
+
+# PC_PYTHON_CHECK_EXTENSION_SUFFIX
+# --------------------------------
+# Find the Python extension suffix (i.e. '.cpython-32.so')
+AC_DEFUN([PC_PYTHON_CHECK_EXTENSION_SUFFIX],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python extension suffix], [pc_cv_python_extension_suffix],
+    [pc_cv_python_extension_suffix=`$PYTHONCONFIG --extension-suffix`])
+AC_SUBST([PYTHON_EXTENSION_SUFFIX], [$pc_cv_python_extension_suffix])])
+
+
+# PC_PYTHON_CHECK_ABI_FLAGS
+# -------------------------
+# Find the Python ABI flags
+AC_DEFUN([PC_PYTHON_CHECK_ABI_FLAGS],
+[AC_REQUIRE([PC_PYTHON_PROG_PYTHONCONFIG])[]dnl
+AC_CACHE_CHECK([for Python ABI flags], [pc_cv_python_abi_flags],
+    [pc_cv_python_abi_flags=`$PYTHONCONFIG --abiflags`])
+AC_SUBST([PYTHON_ABI_FLAGS], [$pc_cv_python_abi_flags])])
+
+
+# PC_PYTHON_CHECK_PLATFORM
+# ------------------------
+# At times (like when building shared libraries) you may want
+# to know which OS platform Python thinks this is.
+AC_DEFUN([PC_PYTHON_CHECK_PLATFORM],
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
+AC_CACHE_CHECK([for Python platform], 
+    [pc_cv_python_platform],
+    [AC_LANG_PUSH(Python)[]dnl
+     AC_LANG_CONFTEST([
+         AC_LANG_PROGRAM([dnl
+import sys
+], [dnl
+    sys.stdout.write(sys.platform)
+])])
+    pc_cv_python_platform=`$PYTHON conftest.py`
+    AC_LANG_POP(Python)[]dnl
+   ])
+AC_SUBST([PYTHON_PLATFORM], [$pc_cv_python_platform])
+])
+
+
+# PC_PYTHON_CHECK_SITE_DIR
+# ---------------------
+# The directory to which new libraries are installed (i.e. the
+# "site-packages" directory.
+AC_DEFUN([PC_PYTHON_CHECK_SITE_DIR],
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
+AC_CACHE_CHECK([for Python site-packages directory],
+    [pc_cv_python_site_dir],
+    [AC_LANG_PUSH(Python)[]dnl
+    if test "x$prefix" = xNONE
+     then
+       pc_py_prefix=$ac_default_prefix
+     else
+       pc_py_prefix=$prefix
+     fi
+     AC_LANG_CONFTEST([
+         AC_LANG_PROGRAM([dnl
+import sys
+try:
+    import sysconfig
+except:
+    from distutils import sysconfig
+    sitedir = sysconfig.get_python_lib(False, False, prefix='$pc_py_prefix')
+else:
+    sitedir = sysconfig.get_path('purelib', vars={'base':'$pc_py_prefix'})
+], [dnl
+    sys.stdout.write(sitedir)
+])])
+     pc_cv_python_site_dir=`$PYTHON conftest.py`
+     AC_LANG_POP(Python)[]dnl
+     case $pc_cv_python_site_dir in
+     $pc_py_prefix*)
+       pc__strip_prefix=`echo "$pc_py_prefix" | sed 's|.|.|g'`
+       pc_cv_python_site_dir=`echo "$pc_cv_python_site_dir" | sed "s,^$pc__strip_prefix,$PYTHON_PREFIX,"`
+       ;;
+     *)
+       case $pc_py_prefix in
+         /usr|/System*) ;;
+         *)
+	  pc_cv_python_site_dir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
+	  ;;
+       esac
+       ;;
+     esac
+     ])
+AC_SUBST([PYTHON_SITE_DIR], [$pc_cv_python_site_dir])])# PC_PYTHON_CHECK_SITE_DIR
+])
+
+# PC_PYTHON_SITE_PACKAGE_DIR
+# --------------------------
+# $PACKAGE directory under PYTHON_SITE_DIR
+AC_DEFUN([PC_PYTHON_SITE_PACKAGE_DIR],
+[AC_REQUIRE([PC_PYTHON_CHECK_SITE_DIR])[]dnl
+AC_SUBST([PYTHON_SITE_PACKAGE_DIR], [$PYTHON_SITE_DIR/$PACKAGE])])
+
+
+# PC_PYTHON_CHECK_EXEC_DIR
+# ------------------------
+# directory for installing python extension modules (shared libraries)
+AC_DEFUN([PC_PYTHON_CHECK_EXEC_DIR],
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
+  AC_CACHE_CHECK([for Python extension module directory],
+    [pc_cv_python_exec_dir],
+    [AC_LANG_PUSH(Python)[]dnl
+    if test "x$pc_cv_python_exec_prefix" = xNONE
+     then
+       pc_py_exec_prefix=$pc_cv_python_prefix
+     else
+       pc_py_exec_prefix=$pc_cv_python_exec_prefix
+     fi
+     AC_LANG_CONFTEST([
+         AC_LANG_PROGRAM([dnl
+import sys
+try:
+    import sysconfig
+except:
+    from distutils import sysconfig
+    sitedir = sysconfig.get_python_lib(True, False, prefix='$pc_py_exec_prefix')
+else:
+    sitedir = sysconfig.get_path('platlib', vars={'platbase':'$pc_py_exec_prefix'})
+], [dnl
+    sys.stdout.write(sitedir)
+])])
+     pc_cv_python_exec_dir=`$PYTHON conftest.py`
+     AC_LANG_POP(Python)[]dnl
+     case $pc_cv_python_exec_dir in
+     $pc_py_exec_prefix*)
+       pc__strip_prefix=`echo "$pc_py_exec_prefix" | sed 's|.|.|g'`
+       pc_cv_python_pyexecdir=`echo "$pc_cv_python_exec_dir" | sed "s,^$pc__strip_prefix,$PYTHON_EXEC_PREFIX,"`
+       ;;
+     *)
+       case $pc_py_exec_prefix in
+         /usr|/System*) ;;
+         *)
+	   pc_cv_python_exec_dir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
+	   ;;
+       esac
+       ;;
+     esac
+    ])
+AC_SUBST([PYTHON_EXEC_DIR], [$pc_cv_python_pyexecdir])]) #PY_PYTHON_CHECK_EXEC_LIB_DIR
+])
+
+# PC_PYTHON_EXEC_PACKAGE_DIR
+# --------------------------
+# $PACKAGE directory under PYTHON_SITE_DIR
+AC_DEFUN([PC_PYTHON_EXEC_PACKAGE_DIR],
+[AC_REQUIRE([PC_PYTHON_CHECK_EXEC_DIR])[]dnl
+AC_SUBST([PYTHON_EXEC_PACKAGE_DIR], [PYTHON_EXEC_DIR/$PACKAGE])])
 
 
 ## -------------------------------------------- ##
@@ -279,7 +420,7 @@ AC_DEFUN([AC_LANG_COMPILER(Python)],
 # ----------------------------------------------------------------------
 # Macro for checking if a Python library is installed
 AC_DEFUN([PC_PYTHON_CHECK_LIB],
-[AC_REQUIRE([PC_PYTHON_PATH])[]dnl
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
 AC_CACHE_CHECK([for Python '$1' library],
     [pc_cv_python_lib_$1],
     [AC_LANG_PUSH(Python)[]dnl
@@ -292,7 +433,9 @@ except:
     sys.exit(1)
 else:
     sys.exit(0)
-], [pass])],
+], [
+    pass
+])],
 	[pc_cv_python_lib_$1="yes"],
 	[pc_cv_python_lib_$1="no"])
      AC_LANG_POP(Python)[]dnl
@@ -303,7 +446,7 @@ AS_IF([test "$pc_cv_python_lib_$1" = "no
 
 # PC_PYTHON_CHECK_FUNC(LIBRARY, FUNCTION, ARGS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
 AC_DEFUN([PC_PYTHON_CHECK_FUNC],
-[AC_REQUIRE([PC_PYTHON_PATH])[]dnl
+[AC_REQUIRE([AC_PROG_PYTHON])[]dnl
 AC_CACHE_CHECK([for Python m4_ifnblank($1, '$1.$2()', '$2()') function],
     [pc_cv_python_func_$1_$2],
     [AC_LANG_PUSH(Python)[]dnl