pyconfigure

(Brandon Invergo)
2012-09-11: fix pseudo-linking and fix version verification

fix pseudo-linking and fix version verification

diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -10,15 +10,22 @@ AM_INIT_AUTOMAKE([-Wall -Werror gnu])
 
 AC_PROG_PYTHON()
 
-# 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],
+PC_PYTHON_VERIFY_VERSION([$PYTHON], 3.0,
                           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
+   PC_PYTHON_VERIFY_VERSION([$PYTHON], python3_min_ver,,
+                            [AC_MSG_ERROR(Python 3 interpreter too old)])
+else
+# otherwise check that the Python 2 version is sufficient
+   PC_PYTHON_VERIFY_VERSION([$PYTHON], python_min_ver, ,
+                            [AC_MSG_ERROR(Python interpreter too old)])
+fi
+
+
 PC_PYTHON_CHECK_PREFIX
 
 PC_PYTHON_CHECK_EXECPREFIX
@@ -45,13 +52,6 @@ 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])
@@ -59,10 +59,12 @@ PC_PYTHON_EXEC_PACKAGE_DIR
 #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_ERROR(missing)])
+PC_PYTHON_CHECK_LIB([dbus])
+PC_PYTHON_CHECK_LIB([foo])
 
 # test if Python library foo can do bar()
-PC_PYTHON_CHECK_FUNC([dbus], [get_default_main_loop], , , [AC_MSG_RESULT(no)])
+PC_PYTHON_CHECK_FUNC([dbus], [get_default_main_loop])
+PC_PYTHON_CHECK_FUNC([dbus], [bar])
 
 AC_CONFIG_FILES([])
 AC_OUTPUT
diff --git a/m4/python.m4 b/m4/python.m4
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -1,7 +1,9 @@
 # Python Autoconf macros
 
-# Some of these macros were written by Andrew Dalke and James Henstridge
-# and are included with the Automake utility under the following copyright terms:
+# Many of these macros were adapted from ones written by Andrew Dalke
+# and James Henstridge and are included with the Automake utility
+# under the following copyright terms:
+#
 # Copyright (C) 1999-2012 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
@@ -12,7 +14,7 @@
 # the Automake namespace and to fit naming conventions for Autoconf
 # language definitions.
 
-# The remaining macros were written or adapted by Brandon Invergo and distributed
+# The remaining macros were written by Brandon Invergo and distributed
 # under the same terms. 
 
 
@@ -39,7 +41,7 @@
 AC_LANG_DEFINE([Python], [py], [PY], [PYTHON], [],
 [ac_ext=py
 ac_compile='chmod +x conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
-ac_link='chmod +x conftest.$ac_ext && mv conftest.$ac_ext conftest >&AS_MESSAGE_LOG_FD'
+ac_link='chmod +x conftest.$ac_ext && cp conftest.$ac_ext conftest >&AS_MESSAGE_LOG_FD'
 ])
 
 
@@ -48,7 +50,6 @@ ac_link='chmod +x conftest.$ac_ext && mv
 AU_DEFUN([AC_LANG_PYTHON], [AC_LANG(Python)])
 
 
-
 ## ----------------------- ##
 ## 2. Producing programs.  ##
 ## ----------------------- ##
@@ -89,6 +90,7 @@ m4_define([_AC_LANG_CALL(Python)],
 [AC_LANG_PROGRAM([$1], [$2])])
 
 
+
 ## -------------------------------------------- ##
 ## 3. Looking for Compilers and Interpreters.   ##
 ## -------------------------------------------- ##
@@ -146,8 +148,9 @@ dnl fi
 # 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],
+m4_define([pc_python_safe_ver], m4_bpatsubsts($2, [\.], [_]))
+AC_CACHE_CHECK([if Python >= '$2'],
+    [[pc_cv_python_min_version_]pc_python_safe_ver],
     [AC_LANG_PUSH(Python)[]dnl
      AC_RUN_IFELSE(
         [AC_LANG_PROGRAM([dnl
@@ -159,15 +162,15 @@ import sys
     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)):
+    for i in list(range(4)):
         minverhex = (minverhex << 8) + minver[[i]]
     sys.exit(sys.hexversion < minverhex)
 ])], 
-         [pc_cv_python_min_version="yes"], 
-         [pc_cv_python_min_version="no"])
+         [[pc_cv_python_min_version_]pc_python_safe_ver="yes"], 
+         [[pc_cv_python_min_version_]pc_python_safe_ver="no"])
      AC_LANG_POP(Python)[]dnl
     ])
-AS_IF([test "$pc_cv_python_min_version" = "no"], [$4], [$3])
+AS_IF([test "$[pc_cv_python_min_version_]pc_python_safe_ver" = "no"], [$4], [$3])
 ])# PC_PYTHON_VERIFY_VERSION