Blame common/m4/as-python.m4

Packit 971217
## ------------------------
Packit 971217
## Python file handling
Packit 971217
## From Andrew Dalke
Packit 971217
## Updated by James Henstridge
Packit 971217
## Updated by Andy Wingo to loop through possible pythons
Packit 971217
## ------------------------
Packit 971217
Packit 971217
# AS_PATH_PYTHON([MINIMUM-VERSION])
Packit 971217
Packit 971217
# Adds support for distributing Python modules and packages.  To
Packit 971217
# install modules, copy them to $(pythondir), using the python_PYTHON
Packit 971217
# automake variable.  To install a package with the same name as the
Packit 971217
# automake package, install to $(pkgpythondir), or use the
Packit 971217
# pkgpython_PYTHON automake variable.
Packit 971217
Packit 971217
# The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
Packit 971217
# locations to install python extension modules (shared libraries).
Packit 971217
# Another macro is required to find the appropriate flags to compile
Packit 971217
# extension modules.
Packit 971217
Packit 971217
# If your package is configured with a different prefix to python,
Packit 971217
# users will have to add the install directory to the PYTHONPATH
Packit 971217
# environment variable, or create a .pth file (see the python
Packit 971217
# documentation for details).
Packit 971217
Packit 971217
# If the MINIMUM-VERSION argument is passed, AS_PATH_PYTHON will
Packit 971217
# cause an error if the version of python installed on the system
Packit 971217
# doesn't meet the requirement.  MINIMUM-VERSION should consist of
Packit 971217
# numbers and dots only.
Packit 971217
Packit 971217
# Updated to loop over all possible python binaries by Andy Wingo
Packit 971217
# <wingo@pobox.com>
Packit 971217
# Updated to only warn and unset PYTHON if no good one is found
Packit 971217
Packit 971217
AC_DEFUN([AS_PATH_PYTHON],
Packit 971217
 [
Packit 971217
  dnl Find a version of Python.  I could check for python versions 1.4
Packit 971217
  dnl or earlier, but the default installation locations changed from
Packit 971217
  dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
Packit 971217
  dnl in 1.5, and I don't want to maintain that logic.
Packit 971217
Packit 971217
  dnl should we do the version check?
Packit 971217
  PYTHON_CANDIDATES="python python2.2 python2.1 python2.0 python2 \
Packit 971217
                     python1.6 python1.5"
Packit 971217
  ifelse([$1],[],
Packit 971217
         [AC_PATH_PROG(PYTHON, $PYTHON_CANDIDATES)],
Packit 971217
         [
Packit 971217
     AC_MSG_NOTICE(Looking for Python version >= $1)
Packit 971217
    changequote(<<, >>)dnl
Packit 971217
    prog="
Packit 971217
import sys, string
Packit 971217
minver = '$1'
Packit 971217
# split string by '.' and convert to numeric
Packit 971217
minver_info = map(string.atoi, string.split(minver, '.'))
Packit 971217
# we can now do comparisons on the two lists:
Packit 971217
if sys.version_info >= tuple(minver_info):
Packit 971217
	sys.exit(0)
Packit 971217
else:
Packit 971217
	sys.exit(1)"
Packit 971217
    changequote([, ])dnl
Packit 971217
Packit 971217
    python_good=false
Packit 971217
    for python_candidate in $PYTHON_CANDIDATES; do
Packit 971217
      unset PYTHON
Packit 971217
      AC_PATH_PROG(PYTHON, $python_candidate) 1> /dev/null 2> /dev/null
Packit 971217
Packit 971217
      if test "x$PYTHON" = "x"; then continue; fi
Packit 971217
Packit 971217
      if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC; then
Packit 971217
        AC_MSG_CHECKING(["$PYTHON":])
Packit 971217
	AC_MSG_RESULT([okay])
Packit 971217
        python_good=true
Packit 971217
        break;
Packit 971217
      else
Packit 971217
        dnl clear the cache val
Packit 971217
        unset ac_cv_path_PYTHON
Packit 971217
      fi
Packit 971217
    done
Packit 971217
  ])
Packit 971217
Packit 971217
  if test "$python_good" != "true"; then
Packit 971217
    AC_MSG_WARN([No suitable version of python found])
Packit 971217
    PYTHON=
Packit 971217
  else
Packit 971217
Packit 971217
  AC_MSG_CHECKING([local Python configuration])
Packit 971217
Packit 971217
  dnl Query Python for its version number.  Getting [:3] seems to be
Packit 971217
  dnl the best way to do this; it's what "site.py" does in the standard
Packit 971217
  dnl library.  Need to change quote character because of [:3]
Packit 971217
Packit 971217
  AC_SUBST(PYTHON_VERSION)
Packit 971217
  changequote(<<, >>)dnl
Packit 971217
  PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
Packit 971217
  changequote([, ])dnl
Packit 971217
Packit 971217
Packit 971217
  dnl Use the values of $prefix and $exec_prefix for the corresponding
Packit 971217
  dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
Packit 971217
  dnl distinct variables so they can be overridden if need be.  However,
Packit 971217
  dnl general consensus is that you shouldn't need this ability.
Packit 971217
Packit 971217
  AC_SUBST(PYTHON_PREFIX)
Packit 971217
  PYTHON_PREFIX='${prefix}'
Packit 971217
Packit 971217
  AC_SUBST(PYTHON_EXEC_PREFIX)
Packit 971217
  PYTHON_EXEC_PREFIX='${exec_prefix}'
Packit 971217
Packit 971217
  dnl At times (like when building shared libraries) you may want
Packit 971217
  dnl to know which OS platform Python thinks this is.
Packit 971217
Packit 971217
  AC_SUBST(PYTHON_PLATFORM)
Packit 971217
  PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
Packit 971217
Packit 971217
Packit 971217
  dnl Set up 4 directories:
Packit 971217
Packit 971217
  dnl pythondir -- where to install python scripts.  This is the
Packit 971217
  dnl   site-packages directory, not the python standard library
Packit 971217
  dnl   directory like in previous automake betas.  This behaviour
Packit 971217
  dnl   is more consistent with lispdir.m4 for example.
Packit 971217
  dnl
Packit 971217
  dnl Also, if the package prefix isn't the same as python's prefix,
Packit 971217
  dnl then the old $(pythondir) was pretty useless.
Packit 971217
Packit 971217
  AC_SUBST(pythondir)
Packit 971217
  pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
Packit 971217
Packit 971217
  dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
Packit 971217
  dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
Packit 971217
  dnl   more consistent with the rest of automake.
Packit 971217
  dnl   Maybe this should be put in python.am?
Packit 971217
Packit 971217
  AC_SUBST(pkgpythondir)
Packit 971217
  pkgpythondir=\${pythondir}/$PACKAGE
Packit 971217
Packit 971217
  dnl pyexecdir -- directory for installing python extension modules
Packit 971217
  dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
Packit 971217
Packit 971217
  AC_SUBST(pyexecdir)
Packit 971217
  pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
Packit 971217
Packit 971217
  dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
Packit 971217
  dnl   Maybe this should be put in python.am?
Packit 971217
Packit 971217
  AC_SUBST(pkgpyexecdir)
Packit 971217
  pkgpyexecdir=\${pyexecdir}/$PACKAGE
Packit 971217
Packit 971217
  AC_MSG_RESULT([looks good])
Packit 971217
Packit 971217
  fi
Packit 971217
])