Blame common/m4/as-python.m4

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