| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
10.5 Python
Automake provides support for Python compilation with the
PYTHON primary. A typical setup is to call
AM_PATH_PYTHON in ‘configure.ac’ and use a line like the
following in ‘Makefile.am’:
python_PYTHON = tree.py leave.py
Any files listed in a _PYTHON variable will be byte-compiled
with py-compile at install time. py-compile
actually creates both standard (‘.pyc’) and optimized
(‘.pyo’) byte-compiled versions of the source files. Note that
because byte-compilation occurs at install time, any files listed in
noinst_PYTHON will not be compiled. Python source files are
included in the distribution by default, prepend nodist_ (as in
nodist_python_PYTHON) to omit them.
Automake ships with an Autoconf macro called AM_PATH_PYTHON
that will determine some Python-related directory variables (see
below). If you have called AM_PATH_PYTHON from
‘configure.ac’, then you may use the variables
python_PYTHON or pkgpython_PYTHON to list Python source
files in your ‘Makefile.am’, depending on where you want your files
installed (see the definitions of pythondir and
pkgpythondir below).
- Macro: AM_PATH_PYTHON ([version], [action-if-found],
[action-if-not-found])
Search for a Python interpreter on the system. This macro takes three optional arguments. The first argument, if present, is the minimum version of Python required for this package:
AM_PATH_PYTHONwill skip any Python interpreter that is older than version. If an interpreter is found and satisfies version, then action-if-found is run. Otherwise, action-if-not-found is run.If action-if-not-found is not specified, as in the following example, the default is to abort
configure.AM_PATH_PYTHON([2.2])
This is fine when Python is an absolute requirement for the package. If Python >= 2.5 was only optional to the package,
AM_PATH_PYTHONcould be called as follows.AM_PATH_PYTHON([2.5],, [:])
If the
PYTHONvariable is set whenAM_PATH_PYTHONis called, then that will be the only Python interpreter that is tried.AM_PATH_PYTHONcreates the following output variables based on the Python installation found during configuration.
PYTHONThe name of the Python executable, or ‘:’ if no suitable interpreter could be found.
Assuming action-if-not-found is used (otherwise ‘./configure’ will abort if Python is absent), the value of
PYTHONcan be used to setup a conditional in order to disable the relevant part of a build as follows.AM_PATH_PYTHON(,, [:]) AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
PYTHON_VERSIONThe Python version number, in the form major.minor (e.g., ‘2.5’). This is currently the value of ‘sys.version[:3]’.
PYTHON_PREFIXThe string ‘${prefix}’. This term may be used in future work that needs the contents of Python’s ‘sys.prefix’, but general consensus is to always use the value from
configure.PYTHON_EXEC_PREFIXThe string ‘${exec_prefix}’. This term may be used in future work that needs the contents of Python’s ‘sys.exec_prefix’, but general consensus is to always use the value from
configure.PYTHON_PLATFORMThe canonical name used by Python to describe the operating system, as given by ‘sys.platform’. This value is sometimes needed when building Python extensions.
pythondirThe directory name for the ‘site-packages’ subdirectory of the standard Python install tree.
pkgpythondirThis is the directory under
pythondirthat is named after the package. That is, it is ‘$(pythondir)/$(PACKAGE)’. It is provided as a convenience.pyexecdirThis is the directory where Python extension modules (shared libraries) should be installed. An extension module written in C could be declared as follows to Automake:
pyexec_LTLIBRARIES = quaternion.la quaternion_la_SOURCES = quaternion.c support.c support.h quaternion_la_LDFLAGS = -avoid-version -module
pkgpyexecdirThis is a convenience variable that is defined as ‘$(pyexecdir)/$(PACKAGE)’.
All of these directory variables have values that start with either ‘${prefix}’ or ‘${exec_prefix}’ unexpanded. This works fine in ‘Makefiles’, but it makes these variables hard to use in ‘configure’. This is mandated by the GNU coding standards, so that the user can run ‘make prefix=/foo install’. The Autoconf manual has a section with more details on this topic (see Installation Directory Variables in The Autoconf Manual). See also Installing to Hard-Coded Locations.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on January 25, 2014 using texi2html 5.0.
