1 | ## ------------------------
|
---|
2 | ## Python file handling
|
---|
3 | ## From Andrew Dalke
|
---|
4 | ## Updated by James Henstridge
|
---|
5 | ## ------------------------
|
---|
6 |
|
---|
7 | # Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
---|
8 |
|
---|
9 | # This program is free software; you can redistribute it and/or modify
|
---|
10 | # it under the terms of the GNU General Public License as published by
|
---|
11 | # the Free Software Foundation; either version 2, or (at your option)
|
---|
12 | # any later version.
|
---|
13 |
|
---|
14 | # This program is distributed in the hope that it will be useful,
|
---|
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | # GNU General Public License for more details.
|
---|
18 |
|
---|
19 | # You should have received a copy of the GNU General Public License
|
---|
20 | # along with this program; if not, write to the Free Software
|
---|
21 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
---|
22 | # 02111-1307, USA.
|
---|
23 |
|
---|
24 | # AM_PATH_PYTHON([MINIMUM-VERSION])
|
---|
25 |
|
---|
26 | # Adds support for distributing Python modules and packages. To
|
---|
27 | # install modules, copy them to $(pythondir), using the python_PYTHON
|
---|
28 | # automake variable. To install a package with the same name as the
|
---|
29 | # automake package, install to $(pkgpythondir), or use the
|
---|
30 | # pkgpython_PYTHON automake variable.
|
---|
31 |
|
---|
32 | # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
|
---|
33 | # locations to install python extension modules (shared libraries).
|
---|
34 | # Another macro is required to find the appropriate flags to compile
|
---|
35 | # extension modules.
|
---|
36 |
|
---|
37 | # If your package is configured with a different prefix to python,
|
---|
38 | # users will have to add the install directory to the PYTHONPATH
|
---|
39 | # environment variable, or create a .pth file (see the python
|
---|
40 | # documentation for details).
|
---|
41 |
|
---|
42 | # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
|
---|
43 | # cause an error if the version of python installed on the system
|
---|
44 | # doesn't meet the requirement. MINIMUM-VERSION should consist of
|
---|
45 | # numbers and dots only.
|
---|
46 |
|
---|
47 | AC_DEFUN([AM_PATH_PYTHON],
|
---|
48 | [
|
---|
49 | dnl Find a Python interpreter. Python versions prior to 1.5 are not
|
---|
50 | dnl supported because the default installation locations changed from
|
---|
51 | dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
|
---|
52 | dnl in 1.5.
|
---|
53 | m4_define([_AM_PYTHON_INTERPRETER_LIST],
|
---|
54 | [python python2 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5])
|
---|
55 |
|
---|
56 | m4_if([$1],[],[
|
---|
57 | dnl No version check is needed.
|
---|
58 | # Find any Python interpreter.
|
---|
59 | AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST)
|
---|
60 | am_display_PYTHON=python
|
---|
61 | ], [
|
---|
62 | dnl A version check is needed.
|
---|
63 | if test -n "$PYTHON"; then
|
---|
64 | # If the user set $PYTHON, use it and don't search something else.
|
---|
65 | AC_MSG_CHECKING([whether $PYTHON version >= $1])
|
---|
66 | AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
|
---|
67 | [AC_MSG_RESULT(yes)],
|
---|
68 | [AC_MSG_ERROR(too old)])
|
---|
69 | else
|
---|
70 | # Otherwise, try each interpreter until we find one that satisfies
|
---|
71 | # VERSION.
|
---|
72 | AC_CACHE_CHECK([for a Python interpreter with version >= $1],
|
---|
73 | [am_cv_pathless_PYTHON],[
|
---|
74 | for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST : ; do
|
---|
75 | if test "$am_cv_pathless_PYTHON" = : ; then
|
---|
76 | AC_MSG_ERROR([no suitable Python interpreter found])
|
---|
77 | fi
|
---|
78 | AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
|
---|
79 | done])
|
---|
80 | # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
|
---|
81 | AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
|
---|
82 | am_display_PYTHON=$am_cv_pathless_PYTHON
|
---|
83 | fi
|
---|
84 | ])
|
---|
85 |
|
---|
86 | dnl Query Python for its version number. Getting [:3] seems to be
|
---|
87 | dnl the best way to do this; it's what "site.py" does in the standard
|
---|
88 | dnl library.
|
---|
89 |
|
---|
90 | AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
|
---|
91 | [am_cv_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"`])
|
---|
92 | AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
|
---|
93 |
|
---|
94 | dnl Use the values of $prefix and $exec_prefix for the corresponding
|
---|
95 | dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
|
---|
96 | dnl distinct variables so they can be overridden if need be. However,
|
---|
97 | dnl general consensus is that you shouldn't need this ability.
|
---|
98 |
|
---|
99 | AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
|
---|
100 | AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
|
---|
101 |
|
---|
102 | dnl At times (like when building shared libraries) you may want
|
---|
103 | dnl to know which OS platform Python thinks this is.
|
---|
104 |
|
---|
105 | AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
|
---|
106 | [am_cv_python_platform=`$PYTHON -c "import sys; print sys.platform"`])
|
---|
107 | AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
|
---|
108 |
|
---|
109 |
|
---|
110 | dnl Set up 4 directories:
|
---|
111 |
|
---|
112 | dnl pythondir -- where to install python scripts. This is the
|
---|
113 | dnl site-packages directory, not the python standard library
|
---|
114 | dnl directory like in previous automake betas. This behavior
|
---|
115 | dnl is more consistent with lispdir.m4 for example.
|
---|
116 | dnl Query distutils for this directory. distutils does not exist in
|
---|
117 | dnl Python 1.5, so we fall back to the hardcoded directory if it
|
---|
118 | dnl doesn't work.
|
---|
119 | AC_CACHE_CHECK([for $am_display_PYTHON script directory],
|
---|
120 | [am_cv_python_pythondir],
|
---|
121 | [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
|
---|
122 | echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
|
---|
123 | AC_SUBST([pythondir], [$am_cv_python_pythondir])
|
---|
124 |
|
---|
125 | dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
|
---|
126 | dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
|
---|
127 | dnl more consistent with the rest of automake.
|
---|
128 |
|
---|
129 | AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
|
---|
130 |
|
---|
131 | dnl pyexecdir -- directory for installing python extension modules
|
---|
132 | dnl (shared libraries)
|
---|
133 | dnl Query distutils for this directory. distutils does not exist in
|
---|
134 | dnl Python 1.5, so we fall back to the hardcoded directory if it
|
---|
135 | dnl doesn't work.
|
---|
136 | AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
|
---|
137 | [am_cv_python_pyexecdir],
|
---|
138 | [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
|
---|
139 | echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
|
---|
140 | AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
|
---|
141 |
|
---|
142 | dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
|
---|
143 |
|
---|
144 | AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
|
---|
145 | ])
|
---|
146 |
|
---|
147 |
|
---|
148 | # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
|
---|
149 | # ---------------------------------------------------------------------------
|
---|
150 | # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
|
---|
151 | # Run ACTION-IF-FALSE otherwise.
|
---|
152 | # This test uses sys.hexversion instead of the string equivalent (first
|
---|
153 | # word of sys.version), in order to cope with versions such as 2.2c1.
|
---|
154 | # hexversion has been introduced in Python 1.5.2; it's probably not
|
---|
155 | # worth to support older versions (1.5.1 was released on October 31, 1998).
|
---|
156 | AC_DEFUN([AM_PYTHON_CHECK_VERSION],
|
---|
157 | [prog="import sys, string
|
---|
158 | # split strings by '.' and convert to numeric. Append some zeros
|
---|
159 | # because we need at least 4 digits for the hex conversion.
|
---|
160 | minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
|
---|
161 | minverhex = 0
|
---|
162 | for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
|
---|
163 | sys.exit(sys.hexversion < minverhex)"
|
---|
164 | AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
|
---|