automake-1.16: Python
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 this in ‘Makefile.am’:
python_PYTHON = tree.py leave.py
Python source files are included in the distribution by default;
prepend ‘nodist_’ (as in ‘nodist_python_PYTHON’) to omit them.
At install time, any files listed in a ‘_PYTHON’ variable will be
byte-compiled with ‘py-compile’. ‘py-compile’ creates both standard
(‘.pyc’) and optimized (‘.pyo’) byte-compiled versions of the source
files. Because byte-compilation occurs at install time, files listed in
‘noinst_PYTHON’ will not be compiled.
Automake ships with an Autoconf macro named ‘AM_PATH_PYTHON’ that
determines 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’ and ‘pkgpython_PYTHON’ to list Python source
files in your ‘Makefile.am’, depending on whether you want your files
installed in ‘pythondir’ or ‘pkgpythondir’, respectively.
-- 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_PYTHON’ will 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.5])
This is fine when Python is an absolute requirement for the
package. If Python ≥ 2.5 was only _optional_ for the package,
‘AM_PATH_PYTHON’ could be called as follows.
AM_PATH_PYTHON([2.5],, [:])
If the ‘PYTHON’ variable is set when ‘AM_PATH_PYTHON’ is called,
then that will be the only Python interpreter that is tried.
‘AM_PATH_PYTHON’ creates the following output variables based on
the Python installation found during configuration:
‘PYTHON’
The 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 ‘PYTHON’ can be used to
set up a conditional in order to disable the relevant part of a
build as follows.
AM_PATH_PYTHON(,, [:])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
‘PYTHON_VERSION’
The Python version number, in the form MAJOR.MINOR (e.g., ‘2.5’).
This is set to be the value of ‘'%u.%u' % sys.version_info[:2]’.
‘PYTHON_PREFIX’
‘PYTHON_EXEC_PREFIX’
With no special options given, these have values ‘${prefix}’ and
‘${exec_prefix}’, respectively (unexpanded; see below).
The ‘configure’ options ‘--with-python_prefix’ and
‘--with-python_exec_prefix’ set them to an explicit value.
The ‘configure’ option ‘--with-python-sys-prefix’ set them to the
values of Python’s ‘sys.prefix’ and ‘sys.exec_prefix’ variables.
These often differ from ‘${prefix}’ and ‘${exec_prefix}’, e.g., on
platforms such as Mac OS x (where Python is usually installed as a
Framework).
‘PYTHON_PLATFORM’
The canonical name used by Python to describe the operating system,
as given by ‘sys.platform’. This value is sometimes needed when
building Python extensions.
‘pythondir’
The directory name for the ‘site-packages’ subdirectory of the
standard Python install tree.
‘pkgpythondir’
This is the directory under ‘pythondir’ that is named after the
package. That is, it is ‘$(pythondir)/$(PACKAGE)’. It is provided
as a convenience.
‘pyexecdir’
This 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
‘pkgpyexecdir’
This is a convenience variable that is defined as
‘$(pyexecdir)/$(PACKAGE)’.
All of these directory variables have values that can start with
either ‘${prefix}’ or ‘${exec_prefix}’, unexpanded. This works fine in
‘Makefile’s, 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
DONTPRINTYET details on this topic (⇒Installation Directory Variables
(autoconf)Installation Directory Variables.). See also *noteHard-Coded
DONTPRINTYET details on this topic (⇒Installation Directory Variables
(autoconf)Installation Directory Variables.). See also ⇒Hard-Coded
Install Paths.