"Fossies" - the Fresh Open Source Software Archive

Member "automake-1.16.3/m4/python.m4" (19 Nov 2020, 9345 Bytes) of package /linux/misc/automake-1.16.3.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "python.m4": 1.16.2_vs_1.16.3.

    1 ## ------------------------                                 -*- Autoconf -*-
    2 ## Python file handling
    3 ## From Andrew Dalke
    4 ## Updated by James Henstridge and other contributors.
    5 ## ------------------------
    6 # Copyright (C) 1999-2020 Free Software Foundation, Inc.
    7 #
    8 # This file is free software; the Free Software Foundation
    9 # gives unlimited permission to copy and/or distribute it,
   10 # with or without modifications, as long as this notice is preserved.
   11 
   12 
   13 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
   14 # ---------------------------------------------------------------------------
   15 # Adds support for distributing Python modules and packages.  To
   16 # install modules, copy them to $(pythondir), using the python_PYTHON
   17 # automake variable.  To install a package with the same name as the
   18 # automake package, install to $(pkgpythondir), or use the
   19 # pkgpython_PYTHON automake variable.
   20 #
   21 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
   22 # locations to install python extension modules (shared libraries).
   23 # Another macro is required to find the appropriate flags to compile
   24 # extension modules.
   25 #
   26 # If your package is configured with a different prefix to python,
   27 # users will have to add the install directory to the PYTHONPATH
   28 # environment variable, or create a .pth file (see the python
   29 # documentation for details).
   30 #
   31 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
   32 # cause an error if the version of python installed on the system
   33 # doesn't meet the requirement.  MINIMUM-VERSION should consist of
   34 # numbers and dots only.
   35 AC_DEFUN([AM_PATH_PYTHON],
   36  [
   37   dnl Find a Python interpreter.  Python versions prior to 2.0 are not
   38   dnl supported. (2.0 was released on October 16, 2000).
   39   m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
   40 [python python2 python3 dnl
   41  python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 dnl
   42  python3.2 python3.1 python3.0 dnl
   43  python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 dnl
   44  python2.0])
   45 
   46   AC_ARG_VAR([PYTHON], [the Python interpreter])
   47 
   48   m4_if([$1],[],[
   49     dnl No version check is needed.
   50     # Find any Python interpreter.
   51     if test -z "$PYTHON"; then
   52       AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
   53     fi
   54     am_display_PYTHON=python
   55   ], [
   56     dnl A version check is needed.
   57     if test -n "$PYTHON"; then
   58       # If the user set $PYTHON, use it and don't search something else.
   59       AC_MSG_CHECKING([whether $PYTHON version is >= $1])
   60       AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
   61 			      [AC_MSG_RESULT([yes])],
   62 			      [AC_MSG_RESULT([no])
   63 			       AC_MSG_ERROR([Python interpreter is too old])])
   64       am_display_PYTHON=$PYTHON
   65     else
   66       # Otherwise, try each interpreter until we find one that satisfies
   67       # VERSION.
   68       AC_CACHE_CHECK([for a Python interpreter with version >= $1],
   69 	[am_cv_pathless_PYTHON],[
   70 	for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
   71 	  test "$am_cv_pathless_PYTHON" = none && break
   72 	  AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
   73 	done])
   74       # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
   75       if test "$am_cv_pathless_PYTHON" = none; then
   76 	PYTHON=:
   77       else
   78         AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
   79       fi
   80       am_display_PYTHON=$am_cv_pathless_PYTHON
   81     fi
   82   ])
   83 
   84   if test "$PYTHON" = :; then
   85   dnl Run any user-specified action, or abort.
   86     m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
   87   else
   88 
   89   dnl Query Python for its version number.  Although site.py simply uses
   90   dnl sys.version[:3], printing that failed with Python 3.10, since the
   91   dnl trailing zero was eliminated. So now we output just the major
   92   dnl and minor version numbers, as numbers. Apparently the tertiary
   93   dnl version is not of interest.
   94 
   95   AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
   96     [am_cv_python_version=`$PYTHON -c "import sys; print('%u.%u' % sys.version_info[[:2]])"`])
   97   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
   98 
   99   dnl Use the values of $prefix and $exec_prefix for the corresponding
  100   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
  101   dnl distinct variables so they can be overridden if need be.  However,
  102   dnl general consensus is that you shouldn't need this ability.
  103 
  104   AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
  105   AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
  106 
  107   dnl At times (like when building shared libraries) you may want
  108   dnl to know which OS platform Python thinks this is.
  109 
  110   AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
  111     [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
  112   AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
  113 
  114   # Just factor out some code duplication.
  115   am_python_setup_sysconfig="\
  116 import sys
  117 # Prefer sysconfig over distutils.sysconfig, for better compatibility
  118 # with python 3.x.  See automake bug#10227.
  119 try:
  120     import sysconfig
  121 except ImportError:
  122     can_use_sysconfig = 0
  123 else:
  124     can_use_sysconfig = 1
  125 # Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
  126 # <https://github.com/pypa/virtualenv/issues/118>
  127 try:
  128     from platform import python_implementation
  129     if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
  130         can_use_sysconfig = 0
  131 except ImportError:
  132     pass"
  133 
  134   dnl Set up 4 directories:
  135 
  136   dnl pythondir -- where to install python scripts.  This is the
  137   dnl   site-packages directory, not the python standard library
  138   dnl   directory like in previous automake betas.  This behavior
  139   dnl   is more consistent with lispdir.m4 for example.
  140   dnl Query distutils for this directory.
  141   AC_CACHE_CHECK([for $am_display_PYTHON script directory],
  142     [am_cv_python_pythondir],
  143     [if test "x$prefix" = xNONE
  144      then
  145        am_py_prefix=$ac_default_prefix
  146      else
  147        am_py_prefix=$prefix
  148      fi
  149      am_cv_python_pythondir=`$PYTHON -c "
  150 $am_python_setup_sysconfig
  151 if can_use_sysconfig:
  152     sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
  153 else:
  154     from distutils import sysconfig
  155     sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
  156 sys.stdout.write(sitedir)"`
  157      case $am_cv_python_pythondir in
  158      $am_py_prefix*)
  159        am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
  160        am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
  161        ;;
  162      *)
  163        case $am_py_prefix in
  164          /usr|/System*) ;;
  165          *)
  166 	  am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
  167 	  ;;
  168        esac
  169        ;;
  170      esac
  171     ])
  172   AC_SUBST([pythondir], [$am_cv_python_pythondir])
  173 
  174   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
  175   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
  176   dnl   more consistent with the rest of automake.
  177 
  178   AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
  179 
  180   dnl pyexecdir -- directory for installing python extension modules
  181   dnl   (shared libraries)
  182   dnl Query distutils for this directory.
  183   AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
  184     [am_cv_python_pyexecdir],
  185     [if test "x$exec_prefix" = xNONE
  186      then
  187        am_py_exec_prefix=$am_py_prefix
  188      else
  189        am_py_exec_prefix=$exec_prefix
  190      fi
  191      am_cv_python_pyexecdir=`$PYTHON -c "
  192 $am_python_setup_sysconfig
  193 if can_use_sysconfig:
  194     sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
  195 else:
  196     from distutils import sysconfig
  197     sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
  198 sys.stdout.write(sitedir)"`
  199      case $am_cv_python_pyexecdir in
  200      $am_py_exec_prefix*)
  201        am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
  202        am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
  203        ;;
  204      *)
  205        case $am_py_exec_prefix in
  206          /usr|/System*) ;;
  207          *)
  208 	   am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
  209 	   ;;
  210        esac
  211        ;;
  212      esac
  213     ])
  214   AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
  215 
  216   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
  217 
  218   AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
  219 
  220   dnl Run any user-specified action.
  221   $2
  222   fi
  223 
  224 ])
  225 
  226 
  227 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
  228 # ---------------------------------------------------------------------------
  229 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
  230 # Run ACTION-IF-FALSE otherwise.
  231 # This test uses sys.hexversion instead of the string equivalent (first
  232 # word of sys.version), in order to cope with versions such as 2.2c1.
  233 # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
  234 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
  235  [prog="import sys
  236 # split strings by '.' and convert to numeric.  Append some zeros
  237 # because we need at least 4 digits for the hex conversion.
  238 # map returns an iterator in Python 3.0 and a list in 2.x
  239 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
  240 minverhex = 0
  241 # xrange is not present in Python 3.0 and range returns an iterator
  242 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
  243 sys.exit(sys.hexversion < minverhex)"
  244   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])