tagging release
[dasher.git] / trunk / m4 / python.m4
blob6014902e4cbfbcac1d5865ed675d4f724b6d17c7
1 ## ------------------------
2 ## Python file handling
3 ## From Andrew Dalke
4 ## Updated by James Henstridge
5 ## ------------------------
7 # Copyright 1999, 2000, 2001, 2002  Free Software Foundation, Inc.
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.
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.
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.
24 # AM_PATH_PYTHON([MINIMUM-VERSION])
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.
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.
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).
42 # If the MINIUMUM-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.
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.2 python2.1 python2.0 python1.6 python1.5])
56   m4_if([$1],[],[
57     dnl No version check is needed.
58     # Find any Python interpreter.
59     AC_PATH_PROG([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   ])
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.
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])
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.
99   AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
100   AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
102   dnl At times (like when building shared libraries) you may want
103   dnl to know which OS platform Python thinks this is.
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])
110   dnl Set up 4 directories:
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 behaviour
115   dnl   is more consistent with lispdir.m4 for example.
116   dnl
117   dnl Also, if the package prefix isn't the same as python's prefix,
118   dnl then the old $(pythondir) was pretty useless.
120   AC_SUBST([pythondir],
121            [$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages])
123   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
124   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
125   dnl   more consistent with the rest of automake.
126   dnl   Maybe this should be put in python.am?
128   AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
130   dnl pyexecdir -- directory for installing python extension modules
131   dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
133   AC_SUBST([pyexecdir],
134            [${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages])
136   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
137   dnl   Maybe this should be put in python.am?
139   AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
143 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
144 # ---------------------------------------------------------------------------
145 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
146 # Run ACTION-IF-FALSE otherwise.
147 # This test uses sys.hexversion instead of the string equivalant (first
148 # word of sys.version), in order to cope with versions such as 2.2c1.
149 # hexversion has been introduced in Python 1.5.2; it's probably not
150 # worth to support older versions (1.5.1 was released on October 31, 1998).
151 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
152  [prog="import sys, string
153 # split strings by '.' and convert to numeric.  Append some zeros
154 # because we need at least 4 digits for the hex conversion.
155 minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
156 minverhex = 0
157 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
158 sys.exit(sys.hexversion < minverhex)"
159   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])