Update NEWS
[geda-gaf.git] / m4 / python2.m4
blob784b6ad5a472c4e3fdbf7c9a909c800ca9abc803
1 ## ------------------------                                 -*- Autoconf -*-
2 ## Python file handling
3 ## From Andrew Dalke
4 ## Updated by James Henstridge
5 ## ------------------------
6 # Copyright (C) 1999-2013 Free Software Foundation, Inc.
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.
12 # This is a modified version of the original python.m4 file which only
13 # tries to use Python 2.x.
16 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
17 # ---------------------------------------------------------------------------
18 # Adds support for distributing Python modules and packages.  To
19 # install modules, copy them to $(pythondir), using the python_PYTHON
20 # automake variable.  To install a package with the same name as the
21 # automake package, install to $(pkgpythondir), or use the
22 # pkgpython_PYTHON automake variable.
24 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
25 # locations to install python extension modules (shared libraries).
26 # Another macro is required to find the appropriate flags to compile
27 # extension modules.
29 # If your package is configured with a different prefix to python,
30 # users will have to add the install directory to the PYTHONPATH
31 # environment variable, or create a .pth file (see the python
32 # documentation for details).
34 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
35 # cause an error if the version of python installed on the system
36 # doesn't meet the requirement.  MINIMUM-VERSION should consist of
37 # numbers and dots only.
38 AC_DEFUN([AM_PATH_PYTHON],
39  [
40   dnl Find a Python interpreter.  Python versions prior to 2.0 are not
41   dnl supported. (2.0 was released on October 16, 2000).
42   m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
43 [python2 python2.7 dnl
44  python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0])
46   AC_ARG_VAR([PYTHON], [the Python interpreter])
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   ])
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
89   dnl Query Python for its version number.  Getting [:3] seems to be
90   dnl the best way to do this; it's what "site.py" does in the standard
91   dnl library.
93   AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
94     [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
95   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
97   dnl Use the values of $prefix and $exec_prefix for the corresponding
98   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
99   dnl distinct variables so they can be overridden if need be.  However,
100   dnl general consensus is that you shouldn't need this ability.
102   AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
103   AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
105   dnl At times (like when building shared libraries) you may want
106   dnl to know which OS platform Python thinks this is.
108   AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
109     [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
110   AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
112   # Just factor out some code duplication.
113   am_python_setup_sysconfig="\
114 import sys
115 # Prefer sysconfig over distutils.sysconfig, for better compatibility
116 # with python 3.x.  See automake bug#10227.
117 try:
118     import sysconfig
119 except ImportError:
120     can_use_sysconfig = 0
121 else:
122     can_use_sysconfig = 1
123 # Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
124 # <https://github.com/pypa/virtualenv/issues/118>
125 try:
126     from platform import python_implementation
127     if python_implementation() == 'CPython' and sys.version[[:3]] == '2.7':
128         can_use_sysconfig = 0
129 except ImportError:
130     pass"
132   dnl Set up 4 directories:
134   dnl pythondir -- where to install python scripts.  This is the
135   dnl   site-packages directory, not the python standard library
136   dnl   directory like in previous automake betas.  This behavior
137   dnl   is more consistent with lispdir.m4 for example.
138   dnl Query distutils for this directory.
139   AC_CACHE_CHECK([for $am_display_PYTHON script directory],
140     [am_cv_python_pythondir],
141     [if test "x$prefix" = xNONE
142      then
143        am_py_prefix=$ac_default_prefix
144      else
145        am_py_prefix=$prefix
146      fi
147      am_cv_python_pythondir=`$PYTHON -c "
148 $am_python_setup_sysconfig
149 if can_use_sysconfig:
150     sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
151 else:
152     from distutils import sysconfig
153     sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
154 sys.stdout.write(sitedir)"`
155      case $am_cv_python_pythondir in
156      $am_py_prefix*)
157        am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
158        am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
159        ;;
160      *)
161        case $am_py_prefix in
162          /usr|/System*) ;;
163          *)
164           am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
165           ;;
166        esac
167        ;;
168      esac
169     ])
170   AC_SUBST([pythondir], [$am_cv_python_pythondir])
172   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
173   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
174   dnl   more consistent with the rest of automake.
176   AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
178   dnl pyexecdir -- directory for installing python extension modules
179   dnl   (shared libraries)
180   dnl Query distutils for this directory.
181   AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
182     [am_cv_python_pyexecdir],
183     [if test "x$exec_prefix" = xNONE
184      then
185        am_py_exec_prefix=$am_py_prefix
186      else
187        am_py_exec_prefix=$exec_prefix
188      fi
189      am_cv_python_pyexecdir=`$PYTHON -c "
190 $am_python_setup_sysconfig
191 if can_use_sysconfig:
192     sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
193 else:
194     from distutils import sysconfig
195     sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
196 sys.stdout.write(sitedir)"`
197      case $am_cv_python_pyexecdir in
198      $am_py_exec_prefix*)
199        am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
200        am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
201        ;;
202      *)
203        case $am_py_exec_prefix in
204          /usr|/System*) ;;
205          *)
206            am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
207            ;;
208        esac
209        ;;
210      esac
211     ])
212   AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
214   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
216   AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
218   dnl Run any user-specified action.
219   $2
220   fi
225 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
226 # ---------------------------------------------------------------------------
227 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
228 # Run ACTION-IF-FALSE otherwise.
229 # This test uses sys.hexversion instead of the string equivalent (first
230 # word of sys.version), in order to cope with versions such as 2.2c1.
231 # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
232 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
233  [prog="import sys
234 # split strings by '.' and convert to numeric.  Append some zeros
235 # because we need at least 4 digits for the hex conversion.
236 # map returns an iterator in Python 3.0 and a list in 2.x
237 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
238 minverhex = 0
239 # xrange is not present in Python 3.0 and range returns an iterator
240 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
241 sys.exit(sys.hexversion < minverhex)"
242   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])