Blame m4/python.m4

Packit Service 672cf4
## ------------------------                                 -*- Autoconf -*-
Packit Service 672cf4
## Python file handling
Packit Service 672cf4
## From Andrew Dalke
Packit Service 672cf4
## Updated by James Henstridge
Packit Service 6c01f9
## ------------------------
Packit Service 672cf4
# Copyright (C) 1999-2017 Free Software Foundation, Inc.
Packit Service 672cf4
#
Packit Service 672cf4
# This file is free software; the Free Software Foundation
Packit Service 672cf4
# gives unlimited permission to copy and/or distribute it,
Packit Service 672cf4
# with or without modifications, as long as this notice is preserved.
Packit Service 672cf4
Packit Service 672cf4
Packit Service 6c01f9
# AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
Packit Service 672cf4
# ---------------------------------------------------------------------------
Packit Service 672cf4
# Adds support for distributing Python modules and packages.  To
Packit Service 672cf4
# install modules, copy them to $(pythondir), using the python_PYTHON
Packit Service 672cf4
# automake variable.  To install a package with the same name as the
Packit Service 672cf4
# automake package, install to $(pkgpythondir), or use the
Packit Service 672cf4
# pkgpython_PYTHON automake variable.
Packit Service 672cf4
#
Packit Service 672cf4
# The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
Packit Service 672cf4
# locations to install python extension modules (shared libraries).
Packit Service 672cf4
# Another macro is required to find the appropriate flags to compile
Packit Service 672cf4
# extension modules.
Packit Service 672cf4
#
Packit Service 672cf4
# If your package is configured with a different prefix to python,
Packit Service 672cf4
# users will have to add the install directory to the PYTHONPATH
Packit Service 672cf4
# environment variable, or create a .pth file (see the python
Packit Service 672cf4
# documentation for details).
Packit Service 672cf4
#
Packit Service 672cf4
# If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
Packit Service 672cf4
# cause an error if the version of python installed on the system
Packit Service 672cf4
# doesn't meet the requirement.  MINIMUM-VERSION should consist of
Packit Service 672cf4
# numbers and dots only.
Packit Service 672cf4
AC_DEFUN([AM_PATH_PYTHON],
Packit Service 672cf4
 [
Packit Service 672cf4
  dnl Find a Python interpreter.  Python versions prior to 2.0 are not
Packit Service 6c01f9
  dnl supported. (2.0 was released on October 16, 2000).
Packit Service 672cf4
  m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
Packit Service 672cf4
[python2 python2.7 dnl
Packit Service 672cf4
 python dnl
Packit Service 6c01f9
 python3 python3.0 python3.1 python3.2 python3.3  dnl
Packit Service 6c01f9
 python3.4 python3.5 python3.6 python3.7 python3.8])
Packit Service 672cf4
Packit Service 672cf4
  AC_ARG_VAR([PYTHON], [the Python interpreter])
Packit Service 672cf4
Packit Service 672cf4
  m4_if([$1],[],[
Packit Service 672cf4
    dnl No version check is needed.
Packit Service 672cf4
    # Find any Python interpreter.
Packit Service 672cf4
    if test -z "$PYTHON"; then
Packit Service 672cf4
      AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
Packit Service 672cf4
    fi
Packit Service 672cf4
    am_display_PYTHON=python
Packit Service 672cf4
  ], [
Packit Service 672cf4
    dnl A version check is needed.
Packit Service 672cf4
    if test -n "$PYTHON"; then
Packit Service 672cf4
      # If the user set $PYTHON, use it and don't search something else.
Packit Service 672cf4
      AC_MSG_CHECKING([whether $PYTHON version is >= $1])
Packit Service 672cf4
      AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
Packit Service 672cf4
			      [AC_MSG_RESULT([yes])],
Packit Service 672cf4
			      [AC_MSG_RESULT([no])
Packit Service 672cf4
			       AC_MSG_ERROR([Python interpreter is too old])])
Packit Service 672cf4
      am_display_PYTHON=$PYTHON
Packit Service 672cf4
    else
Packit Service 672cf4
      # Otherwise, try each interpreter until we find one that satisfies
Packit Service 672cf4
      # VERSION.
Packit Service 672cf4
      AC_CACHE_CHECK([for a Python interpreter with version >= $1],
Packit Service 672cf4
	[am_cv_pathless_PYTHON],[
Packit Service 6c01f9
	for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
Packit Service 672cf4
	  test "$am_cv_pathless_PYTHON" = none && break
Packit Service 672cf4
	  AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
Packit Service 672cf4
	done])
Packit Service 672cf4
      # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
Packit Service 672cf4
      if test "$am_cv_pathless_PYTHON" = none; then
Packit Service 672cf4
	PYTHON=:
Packit Service 672cf4
      else
Packit Service 672cf4
        AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
Packit Service 672cf4
      fi
Packit Service 672cf4
      am_display_PYTHON=$am_cv_pathless_PYTHON
Packit Service 672cf4
    fi
Packit Service 672cf4
  ])
Packit Service 672cf4
Packit Service 672cf4
  if test "$PYTHON" = :; then
Packit Service 672cf4
  dnl Run any user-specified action, or abort.
Packit Service 672cf4
    m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
Packit Service 672cf4
  else
Packit Service 672cf4
Packit Service 672cf4
  dnl Query Python for its version number.  Getting [:3] seems to be
Packit Service 672cf4
  dnl the best way to do this; it's what "site.py" does in the standard
Packit Service 672cf4
  dnl library.
Packit Service 672cf4
Packit Service 672cf4
  AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
Packit Service 672cf4
    [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
Packit Service 672cf4
  AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
Packit Service 672cf4
Packit Service 672cf4
  dnl Use the values of $prefix and $exec_prefix for the corresponding
Packit Service 672cf4
  dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
Packit Service 672cf4
  dnl distinct variables so they can be overridden if need be.  However,
Packit Service 672cf4
  dnl general consensus is that you shouldn't need this ability.
Packit Service 672cf4
Packit Service 672cf4
  AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
Packit Service 672cf4
  AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
Packit Service 672cf4
Packit Service 672cf4
  dnl At times (like when building shared libraries) you may want
Packit Service 672cf4
  dnl to know which OS platform Python thinks this is.
Packit Service 672cf4
Packit Service 672cf4
  AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
Packit Service 672cf4
    [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
Packit Service 672cf4
  AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
Packit Service 672cf4
Packit Service 672cf4
  # Just factor out some code duplication.
Packit Service 672cf4
  am_python_setup_sysconfig="\
Packit Service 672cf4
import sys
Packit Service 672cf4
# Prefer sysconfig over distutils.sysconfig, for better compatibility
Packit Service 672cf4
# with python 3.x.  See automake bug#10227.
Packit Service 672cf4
try:
Packit Service 672cf4
    import sysconfig
Packit Service 672cf4
except ImportError:
Packit Service 672cf4
    can_use_sysconfig = 0
Packit Service 672cf4
else:
Packit Service 672cf4
    can_use_sysconfig = 1
Packit Service 672cf4
# Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
Packit Service 672cf4
# <https://github.com/pypa/virtualenv/issues/118>
Packit Service 672cf4
try:
Packit Service 672cf4
    from platform import python_implementation
Packit Service 672cf4
    if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
Packit Service 672cf4
        can_use_sysconfig = 0
Packit Service 672cf4
except ImportError:
Packit Service 672cf4
    pass"
Packit Service 672cf4
Packit Service 672cf4
  dnl Set up 4 directories:
Packit Service 672cf4
Packit Service 672cf4
  dnl pythondir -- where to install python scripts.  This is the
Packit Service 672cf4
  dnl   site-packages directory, not the python standard library
Packit Service 672cf4
  dnl   directory like in previous automake betas.  This behavior
Packit Service 672cf4
  dnl   is more consistent with lispdir.m4 for example.
Packit Service 672cf4
  dnl Query distutils for this directory.
Packit Service 672cf4
  AC_CACHE_CHECK([for $am_display_PYTHON script directory],
Packit Service 672cf4
    [am_cv_python_pythondir],
Packit Service 672cf4
    [if test "x$prefix" = xNONE
Packit Service 672cf4
     then
Packit Service 672cf4
       am_py_prefix=$ac_default_prefix
Packit Service 672cf4
     else
Packit Service 672cf4
       am_py_prefix=$prefix
Packit Service 672cf4
     fi
Packit Service 672cf4
     am_cv_python_pythondir=`$PYTHON -c "
Packit Service 672cf4
$am_python_setup_sysconfig
Packit Service 672cf4
if can_use_sysconfig:
Packit Service 672cf4
    sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
Packit Service 672cf4
else:
Packit Service 672cf4
    from distutils import sysconfig
Packit Service 672cf4
    sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
Packit Service 672cf4
sys.stdout.write(sitedir)"`
Packit Service 672cf4
     case $am_cv_python_pythondir in
Packit Service 672cf4
     $am_py_prefix*)
Packit Service 672cf4
       am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
Packit Service 672cf4
       am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
Packit Service 672cf4
       ;;
Packit Service 672cf4
     *)
Packit Service 672cf4
       case $am_py_prefix in
Packit Service 672cf4
         /usr|/System*) ;;
Packit Service 672cf4
         *)
Packit Service 672cf4
	  am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
Packit Service 672cf4
	  ;;
Packit Service 672cf4
       esac
Packit Service 672cf4
       ;;
Packit Service 672cf4
     esac
Packit Service 672cf4
    ])
Packit Service 672cf4
  AC_SUBST([pythondir], [$am_cv_python_pythondir])
Packit Service 672cf4
Packit Service 672cf4
  dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
Packit Service 672cf4
  dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
Packit Service 672cf4
  dnl   more consistent with the rest of automake.
Packit Service 672cf4
Packit Service 672cf4
  AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
Packit Service 672cf4
Packit Service 672cf4
  dnl pyexecdir -- directory for installing python extension modules
Packit Service 672cf4
  dnl   (shared libraries)
Packit Service 672cf4
  dnl Query distutils for this directory.
Packit Service 672cf4
  AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
Packit Service 672cf4
    [am_cv_python_pyexecdir],
Packit Service 672cf4
    [if test "x$exec_prefix" = xNONE
Packit Service 672cf4
     then
Packit Service 672cf4
       am_py_exec_prefix=$am_py_prefix
Packit Service 672cf4
     else
Packit Service 672cf4
       am_py_exec_prefix=$exec_prefix
Packit Service 672cf4
     fi
Packit Service 672cf4
     am_cv_python_pyexecdir=`$PYTHON -c "
Packit Service 672cf4
$am_python_setup_sysconfig
Packit Service 672cf4
if can_use_sysconfig:
Packit Service 672cf4
    sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
Packit Service 672cf4
else:
Packit Service 672cf4
    from distutils import sysconfig
Packit Service 672cf4
    sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
Packit Service 672cf4
sys.stdout.write(sitedir)"`
Packit Service 672cf4
     case $am_cv_python_pyexecdir in
Packit Service 672cf4
     $am_py_exec_prefix*)
Packit Service 672cf4
       am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
Packit Service 672cf4
       am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
Packit Service 672cf4
       ;;
Packit Service 672cf4
     *)
Packit Service 672cf4
       case $am_py_exec_prefix in
Packit Service 672cf4
         /usr|/System*) ;;
Packit Service 672cf4
         *)
Packit Service 672cf4
	   am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
Packit Service 672cf4
	   ;;
Packit Service 672cf4
       esac
Packit Service 672cf4
       ;;
Packit Service 672cf4
     esac
Packit Service 672cf4
    ])
Packit Service 672cf4
  AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
Packit Service 672cf4
Packit Service 672cf4
  dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
Packit Service 672cf4
Packit Service 672cf4
  AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
Packit Service 672cf4
Packit Service 672cf4
  dnl Run any user-specified action.
Packit Service 672cf4
  $2
Packit Service 672cf4
  fi
Packit Service 672cf4
Packit Service 672cf4
])
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
# AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
Packit Service 672cf4
# ---------------------------------------------------------------------------
Packit Service 672cf4
# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
Packit Service 672cf4
# Run ACTION-IF-FALSE otherwise.
Packit Service 672cf4
# This test uses sys.hexversion instead of the string equivalent (first
Packit Service 672cf4
# word of sys.version), in order to cope with versions such as 2.2c1.
Packit Service 672cf4
# This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
Packit Service 672cf4
AC_DEFUN([AM_PYTHON_CHECK_VERSION],
Packit Service 672cf4
 [prog="import sys
Packit Service 672cf4
# split strings by '.' and convert to numeric.  Append some zeros
Packit Service 672cf4
# because we need at least 4 digits for the hex conversion.
Packit Service 672cf4
# map returns an iterator in Python 3.0 and a list in 2.x
Packit Service 672cf4
minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
Packit Service 672cf4
minverhex = 0
Packit Service 672cf4
# xrange is not present in Python 3.0 and range returns an iterator
Packit Service 672cf4
for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
Packit Service 672cf4
sys.exit(sys.hexversion < minverhex)"
Packit Service 672cf4
  AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])