Cope with whitespace in $MISSING and $install_sh.
[automake/ericb.git] / m4 / python.m4
blob3adf87b8c950d760a828c5693e7606b5bba3bbbf
1 ## ------------------------                                 -*- Autoconf -*-
2 ## Python file handling
3 ## From Andrew Dalke
4 ## Updated by James Henstridge
5 ## ------------------------
6 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
7 # Free Software Foundation, Inc.
9 # This file is free software; the Free Software Foundation
10 # gives unlimited permission to copy and/or distribute it,
11 # with or without modifications, as long as this notice is preserved.
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.
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.
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).
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 python3.0 python2.5 python2.4 python2.3 python2.2 dnl
41 python2.1 python2.0])
43   m4_if([$1],[],[
44     dnl No version check is needed.
45     # Find any Python interpreter.
46     if test -z "$PYTHON"; then
47       AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST, :)
48     fi
49     am_display_PYTHON=python
50   ], [
51     dnl A version check is needed.
52     if test -n "$PYTHON"; then
53       # If the user set $PYTHON, use it and don't search something else.
54       AC_MSG_CHECKING([whether $PYTHON version >= $1])
55       AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
56                               [AC_MSG_RESULT(yes)],
57                               [AC_MSG_ERROR(too old)])
58       am_display_PYTHON=$PYTHON
59     else
60       # Otherwise, try each interpreter until we find one that satisfies
61       # VERSION.
62       AC_CACHE_CHECK([for a Python interpreter with version >= $1],
63         [am_cv_pathless_PYTHON],[
64         for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
65           test "$am_cv_pathless_PYTHON" = none && break
66           AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
67         done])
68       # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
69       if test "$am_cv_pathless_PYTHON" = none; then
70         PYTHON=:
71       else
72         AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
73       fi
74       am_display_PYTHON=$am_cv_pathless_PYTHON
75     fi
76   ])
78   if test "$PYTHON" = :; then
79   dnl Run any user-specified action, or abort.
80     m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
81   else
83   dnl Query Python for its version number.  Getting [:3] seems to be
84   dnl the best way to do this; it's what "site.py" does in the standard
85   dnl library.
87   AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
88     [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
89   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
91   dnl Use the values of $prefix and $exec_prefix for the corresponding
92   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
93   dnl distinct variables so they can be overridden if need be.  However,
94   dnl general consensus is that you shouldn't need this ability.
96   AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
97   AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
99   dnl At times (like when building shared libraries) you may want
100   dnl to know which OS platform Python thinks this is.
102   AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
103     [am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`])
104   AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
107   dnl Set up 4 directories:
109   dnl pythondir -- where to install python scripts.  This is the
110   dnl   site-packages directory, not the python standard library
111   dnl   directory like in previous automake betas.  This behavior
112   dnl   is more consistent with lispdir.m4 for example.
113   dnl Query distutils for this directory.  distutils does not exist in
114   dnl Python 1.5, so we fall back to the hardcoded directory if it
115   dnl doesn't work.
116   AC_CACHE_CHECK([for $am_display_PYTHON script directory],
117     [am_cv_python_pythondir],
118     [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
119      echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
120   AC_SUBST([pythondir], [$am_cv_python_pythondir])
122   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
123   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
124   dnl   more consistent with the rest of automake.
126   AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
128   dnl pyexecdir -- directory for installing python extension modules
129   dnl   (shared libraries)
130   dnl Query distutils for this directory.  distutils does not exist in
131   dnl Python 1.5, so we fall back to the hardcoded directory if it
132   dnl doesn't work.
133   AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
134     [am_cv_python_pyexecdir],
135     [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
136      echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
137   AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
139   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
141   AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
143   dnl Run any user-specified action.
144   $2
145   fi
150 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
151 # ---------------------------------------------------------------------------
152 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
153 # Run ACTION-IF-FALSE otherwise.
154 # This test uses sys.hexversion instead of the string equivalent (first
155 # word of sys.version), in order to cope with versions such as 2.2c1.
156 # This supports Python 2.0 or higher. (2.0 was released on October 16, 2000).
157 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
158  [prog="import sys
159 # split strings by '.' and convert to numeric.  Append some zeros
160 # because we need at least 4 digits for the hex conversion.
161 # map returns an iterator in Python 3.0 and a list in 2.x
162 minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
163 minverhex = 0
164 # xrange is not present in Python 3.0 and range returns an iterator
165 for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
166 sys.exit(sys.hexversion < minverhex)"
167   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])