1 ## ------------------------
2 ## Python file handling
4 ## Updated by James Henstridge
5 ## Updated by Andy Wingo to loop through possible pythons
6 ## ------------------------
8 # AS_PATH_PYTHON([MINIMUM-VERSION])
10 # Adds support for distributing Python modules and packages. To
11 # install modules, copy them to $(pythondir), using the python_PYTHON
12 # automake variable. To install a package with the same name as the
13 # automake package, install to $(pkgpythondir), or use the
14 # pkgpython_PYTHON automake variable.
16 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
17 # locations to install python extension modules (shared libraries).
18 # Another macro is required to find the appropriate flags to compile
21 # If your package is configured with a different prefix to python,
22 # users will have to add the install directory to the PYTHONPATH
23 # environment variable, or create a .pth file (see the python
24 # documentation for details).
26 # If the MINIMUM-VERSION argument is passed, AS_PATH_PYTHON will
27 # cause an error if the version of python installed on the system
28 # doesn't meet the requirement. MINIMUM-VERSION should consist of
29 # numbers and dots only.
31 # Updated to loop over all possible python binaries by Andy Wingo
33 # Updated to only warn and unset PYTHON if no good one is found
35 AC_DEFUN([AS_PATH_PYTHON],
37 dnl Find a version of Python. I could check for python versions 1.4
38 dnl or earlier, but the default installation locations changed from
39 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
40 dnl in 1.5, and I don't want to maintain that logic.
42 dnl should we do the version check?
43 PYTHON_CANDIDATES="python python2.2 python2.1 python2.0 python2 \
46 [AC_PATH_PROG(PYTHON, $PYTHON_CANDIDATES)],
48 AC_MSG_NOTICE(Looking for Python version >= $1)
49 changequote(<<, >>)dnl
53 # split string by '.' and convert to numeric
54 minver_info = map(string.atoi, string.split(minver, '.'))
55 # we can now do comparisons on the two lists:
56 if sys.version_info >= tuple(minver_info):
63 for python_candidate in $PYTHON_CANDIDATES; do
65 AC_PATH_PROG(PYTHON, $python_candidate) 1> /dev/null 2> /dev/null
67 if test "x$PYTHON" = "x"; then continue; fi
69 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC; then
70 AC_MSG_CHECKING(["$PYTHON":])
75 dnl clear the cache val
76 unset ac_cv_path_PYTHON
81 if test "$python_good" != "true"; then
82 AC_MSG_WARN([No suitable version of python found])
86 AC_MSG_CHECKING([local Python configuration])
88 dnl Query Python for its version number. Getting [:3] seems to be
89 dnl the best way to do this; it's what "site.py" does in the standard
90 dnl library. Need to change quote character because of [:3]
92 AC_SUBST(PYTHON_VERSION)
93 changequote(<<, >>)dnl
94 PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
98 dnl Use the values of $prefix and $exec_prefix for the corresponding
99 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
100 dnl distinct variables so they can be overridden if need be. However,
101 dnl general consensus is that you shouldn't need this ability.
103 AC_SUBST(PYTHON_PREFIX)
104 PYTHON_PREFIX='${prefix}'
106 AC_SUBST(PYTHON_EXEC_PREFIX)
107 PYTHON_EXEC_PREFIX='${exec_prefix}'
109 dnl At times (like when building shared libraries) you may want
110 dnl to know which OS platform Python thinks this is.
112 AC_SUBST(PYTHON_PLATFORM)
113 PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
116 dnl Set up 4 directories:
118 dnl pythondir -- where to install python scripts. This is the
119 dnl site-packages directory, not the python standard library
120 dnl directory like in previous automake betas. This behaviour
121 dnl is more consistent with lispdir.m4 for example.
123 dnl Also, if the package prefix isn't the same as python's prefix,
124 dnl then the old $(pythondir) was pretty useless.
127 pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
129 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
130 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
131 dnl more consistent with the rest of automake.
132 dnl Maybe this should be put in python.am?
134 AC_SUBST(pkgpythondir)
135 pkgpythondir=\${pythondir}/$PACKAGE
137 dnl pyexecdir -- directory for installing python extension modules
138 dnl (shared libraries) Was PYTHON_SITE_EXEC in previous betas.
141 pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
143 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
144 dnl Maybe this should be put in python.am?
146 AC_SUBST(pkgpyexecdir)
147 pkgpyexecdir=\${pyexecdir}/$PACKAGE
149 AC_MSG_RESULT([looks good])