Blame common/m4/as-python.m4

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