1 ## ------------------------
2 ## Python file handling
4 ## Updated by James Henstridge
5 ## ------------------------
7 # AM_PATH_PYTHON([MINIMUM-VERSION])
9 # Adds support for distributing Python modules and packages. To
10 # install modules, copy them to $(pythondir), using the python_PYTHON
11 # automake variable. To install a package with the same name as the
12 # automake package, install to $(pkgpythondir), or use the
13 # pkgpython_PYTHON automake variable.
15 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
16 # locations to install python extension modules (shared libraries).
17 # Another macro is required to find the appropriate flags to compile
20 # If your package is configured with a different prefix to python,
21 # users will have to add the install directory to the PYTHONPATH
22 # environment variable, or create a .pth file (see the python
23 # documentation for details).
25 # If the MINIUMUM-VERSION argument is passed, AM_PATH_PYTHON will
26 # cause an error if the version of python installed on the system
27 # doesn't meet the requirement. MINIMUM-VERSION should consist of
28 # numbers and dots only.
31 AC_DEFUN([AM_PATH_PYTHON],
33 dnl Find a version of Python. I could check for python versions 1.4
34 dnl or earlier, but the default installation locations changed from
35 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
36 dnl in 1.5, and I don't want to maintain that logic.
38 AC_PATH_PROG(PYTHON, python2 python2.1 python2.0 python python1.6 python1.5)
40 dnl should we do the version check?
42 AC_MSG_CHECKING(if Python version >= $1)
43 changequote(<<, >>)dnl
47 pyver = string.split(sys.version)[0] # first word is version string
48 # split strings by '.' and convert to numeric
49 minver = map(string.atoi, string.split(minver, '.'))
50 pyver = map(string.atoi, string.split(pyver, '.'))
51 # we can now do comparisons on the two lists:
57 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
65 AC_MSG_CHECKING([local Python configuration])
67 dnl Query Python for its version number. Getting [:3] seems to be
68 dnl the best way to do this; it's what "site.py" does in the standard
69 dnl library. Need to change quote character because of [:3]
71 AC_SUBST(PYTHON_VERSION)
72 changequote(<<, >>)dnl
73 PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
77 dnl Use the values of $prefix and $exec_prefix for the corresponding
78 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
79 dnl distinct variables so they can be overridden if need be. However,
80 dnl general consensus is that you shouldn't need this ability.
82 AC_SUBST(PYTHON_PREFIX)
83 PYTHON_PREFIX='${prefix}'
85 AC_SUBST(PYTHON_EXEC_PREFIX)
86 PYTHON_EXEC_PREFIX='${exec_prefix}'
88 dnl At times (like when building shared libraries) you may want
89 dnl to know which OS platform Python thinks this is.
91 AC_SUBST(PYTHON_PLATFORM)
92 PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
95 dnl Set up 4 directories:
97 dnl pythondir -- where to install python scripts. This is the
98 dnl site-packages directory, not the python standard library
99 dnl directory like in previous automake betas. This behaviour
100 dnl is more consistent with lispdir.m4 for example.
102 dnl Also, if the package prefix isn't the same as python's prefix,
103 dnl then the old $(pythondir) was pretty useless.
106 pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
108 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
109 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
110 dnl more consistent with the rest of automake.
111 dnl Maybe this should be put in python.am?
113 AC_SUBST(pkgpythondir)
114 pkgpythondir=\${pythondir}/$PACKAGE
116 dnl pyexecdir -- directory for installing python extension modules
117 dnl (shared libraries) Was PYTHON_SITE_EXEC in previous betas.
120 pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
122 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
123 dnl Maybe this should be put in python.am?
125 AC_SUBST(pkgpyexecdir)
126 pkgpyexecdir=\${pyexecdir}/$PACKAGE
128 AC_MSG_RESULT([looks good])