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