Beruflich Dokumente
Kultur Dokumente
_ref-build-system:
The Build System
================
.. module:: sipconfig
.. note::
This should not be used for new projects as it will not be supported by SIP
v5.
The purpose of the build system is to make it easy for you to write
configuration scripts in Python for your own bindings. The build system takes
care of the details of particular combinations of platform and compiler. It
supports over 50 different platform/compiler combinations.
The build system is implemented as a pure Python module called :mod:`sipconfig`
that contains a number of classes and functions. Using this module you can
write bespoke configuration scripts (e.g. PyQt4's ``configure.py``) or use it
with other Python based build systems (e.g.
`Distutils <http://www.python.org/sigs/distutils-sig/distutils.html>`_ and
`SCons <http://www.scons.org>`_).
An important feature of SIP is the ability to generate bindings that are built
on top of existing bindings. For example, both
`PyKDE <http://www.riverbankcomputing.com/software/pykde/>`_ and
`PyQwt <http://pyqwt.sourceforge.net/>`_ are built on top of PyQt4 but all
three packages are maintained by different developers. To make this easier
PyQt4 includes its own configuration module, ``pyqtconfig``, that contains
additional classes intended to be used by the configuration scripts of bindings
built on top of PyQt4. The SIP build system includes facilities that do a lot
of the work of creating these additional configuration modules.
.. function:: create_config_module(module, template, content[, macros=None])
This creates a configuration module (e.g. ``pyqtconfig``) from a template
file and a string.
:param module:
the name of the configuration module file to create.
:param template:
the name of the template file.
:param content:
a string which replaces every occurence of the pattern
``@SIP_CONFIGURATION@`` in the template file. The content string is
usually created from a Python dictionary using
:func:`sipconfig.create_content()`. *content* may also be a
dictionary, in which case :func:`sipconfig.create_content()` is
automatically called to convert it to a string.
:param macros:
an optional dictionary of platform specific build macros. It is only
used if :func:`sipconfig.create_content()` is called automatically to
convert a *content* dictionary to a string.
.. function:: create_content(dict[, macros=None]) -> string
This converts a Python dictionary to a string that can be parsed by the
the text of the message and should not include any newline characters.
.. function:: parse_build_macros(filename, names[, overrides=None[, properties=N
one]]) -> dict
This parses a ``qmake`` compatible file of build system macros and converts
it to a dictionary. A macro is a name/value pair. Individual macros may
be augmented or replaced.
:param filename:
the name of the file to parse.
:param names:
the list of the macro names to extract from the file.
:param overrides:
the optional list of macro names and values that modify those found in
the file. They are of the form ``name=value`` (in which case the value
replaces the value found in the file) or ``name+=value`` (in which case
the value is appended to the value found in the file).
:param properties:
the optional dictionary of property name and values that are used to
resolve any expressions of the form ``$[name]`` in the file.
:return:
the dictionary of parsed macros or ``None`` if any of the overrides
were invalid.
.. function:: read_version(filename, description[, numdefine=None[, strdefine=No
ne]]) -> integer, string
This extracts version information for a package from a file, usually a C or
C++ header file. The version information must each be specified as a
``#define`` of a numeric (hexadecimal or decimal) value and/or a string
value.
:param filename:
the name of the file to read.
:param description:
a descriptive name of the package used in error messages.
:param numdefine:
the optional name of the ``#define`` of the version as a number. If it
is ``None`` then the numeric version is ignored.
:param strdefine:
the optional name of the ``#define`` of the version as a string. If it
is ``None`` then the string version is ignored.
:return:
a tuple of the numeric and string versions. :func:`sipconfig.error()`
is called if either were required but could not be found.
.. function:: version_to_sip_tag(version, tags, description) -> string
This converts a version number to a SIP version tag. SIP uses the
:directive:`%Timeline` directive to define the chronology of the different
versions of the C/C++ library being wrapped. Typically it is not necessary
to define a version tag for every version of the library, but only for
those versions that affect the library's API as SIP sees it.
:param version:
the numeric version number of the C/C++ library being wrapped. If it
.. method:: generate_target_default(mfile)
This is the default implementation of the Makefile default target
generation.
:param mfile:
the Python file object of the Makefile.
.. method:: generate_target_install(mfile)
This is the default implementation of the Makefile install target
generation.
:param mfile:
the Python file object of the Makefile.
.. method:: install_file(mfile, src, dst[, strip=0])
This generates the Makefile commands to install one or more files to a
directory.
:param mfile:
the Python file object of the Makefile.
:param src:
the name of a single file to install or a list of a number of files
to install.
:param dst:
the name of the destination directory.
:param strip:
is set if the files should be stripped of unneeded symbols after
having been installed.
.. method:: optional_list(name) -> list
This returns an optional Makefile macro as a list.
:param name:
the name of the macro.
:return:
the macro as a list.
.. method:: optional_string(name[, default=""])
This returns an optional Makefile macro as a string.
:param name:
the name of the macro.
:param default:
the optional default value of the macro.
:return:
the macro as a string.
.. method:: parse_build_file(filename) -> dict
This parses a build file (created with the :option:`-b <sip -b>` SIP
command line option) and converts it to a dictionary. It can also
validate an existing dictionary created through other means.
:param filename: is the name of the build file, or is a dictionary to
be validated. A valid dictionary will contain the name of the
:param opengl:
see :meth:`sipconfig.Makefile.__init__`.
:param threaded:
see :meth:`sipconfig.Makefile.__init__`.
:param warnings:
see :meth:`sipconfig.Makefile.__init__`.
:param debug:
see :meth:`sipconfig.Makefile.__init__`.
:param dir:
see :meth:`sipconfig.Makefile.__init__`.
:param makefile:
see :meth:`sipconfig.Makefile.__init__`.
:param installs:
see :meth:`sipconfig.Makefile.__init__`.
:param strip:
is set if the module should be stripped of unneeded symbols after
installation. It is ignored if either *debug* or *static* is set,
or if the platform doesn't support it.
:param export_all:
is set if all of the module's symbols should be exported rather
than just the module's initialisation function. Exporting all
symbols increases the size of the module and slows down module load
times but may avoid problems with modules that use C++ exceptions.
All symbols are exported if either *debug* or *static* is set, or
if the platform doesn't support it.
:param universal:
see :meth:`sipconfig.Makefile.__init__`.
:param arch:
see :meth:`sipconfig.Makefile.__init__`.
:param deployment_target:
see :meth:`sipconfig.Makefile.__init__`.
.. method:: finalise()
This is a reimplementation of :meth:`sipconfig.Makefile.finalise`.
.. method:: generate_macros_and_rules(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_macros_and_rules`.
.. method:: generate_target_clean(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_clean`.
.. method:: generate_target_default(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_default`.
.. method:: generate_target_install(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_install`.
.. method:: module_as_lib(mname) -> string
This gets the name of a SIP v3.x module for when it is used as a
library to be linked against. An exception will be raised if it is
:param configuration:
see :meth:`sipconfig.Makefile.__init__`.
:param build_file:
the name of the optional build file. Build files are generated
using the :option:`-b <sip -b>` SIP command line option.
:param install_dir:
the name of the directory where the executable program will be
optionally installed.
:param console:
see :meth:`sipconfig.Makefile.__init__`.
:param qt:
see :meth:`sipconfig.Makefile.__init__`.
:param opengl:
see :meth:`sipconfig.Makefile.__init__`.
:param python:
see :meth:`sipconfig.Makefile.__init__`.
:param threaded:
see :meth:`sipconfig.Makefile.__init__`.
:param warnings:
see :meth:`sipconfig.Makefile.__init__`.
:param debug:
see :meth:`sipconfig.Makefile.__init__`.
:param dir:
see :meth:`sipconfig.Makefile.__init__`.
:param makefile:
see :meth:`sipconfig.Makefile.__init__`.
:param installs:
see :meth:`sipconfig.Makefile.__init__`.
:param universal:
see :meth:`sipconfig.Makefile.__init__`.
:param arch:
see :meth:`sipconfig.Makefile.__init__`.
:param deployment_target:
see :meth:`sipconfig.Makefile.__init__`.
.. method:: build_command(source) -> string, string
This creates a single command line that will create an executable
program from a single source file.
:param source:
the name of the source file.
:return:
a tuple of the name of the executable that will be created and the
command line.
.. method:: finalise()
This is a reimplementation of :meth:`sipconfig.Makefile.finalise`.
.. method:: generate_macros_and_rules(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_macros_and_rules`.
.. method:: generate_target_clean(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_clean`.
.. method:: generate_target_default(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_default`.
.. method:: generate_target_install(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_install`.
.. class:: PythonModuleMakefile
This class is derived from :class:`sipconfig.Makefile`.
This class encapsulates a Makefile that installs a pure Python module.
.. method:: __init__(self, configuration, dstdir[, srcdir=None[, dir=None[,
makefile="Makefile"[, installs=None]]]])
:param configuration:
see :meth:`sipconfig.Makefile.__init__`.
:param dstdir:
the name of the directory in which the module's Python code will be
installed.
:param srcdir:
the name of the directory (relative to *dir*) containing the
module's Python code. It defaults to the same directory.
:param dir:
see :meth:`sipconfig.Makefile.__init__`.
:param makefile:
see :meth:`sipconfig.Makefile.__init__`.
:param installs:
see :meth:`sipconfig.Makefile.__init__`.
.. method:: generate_macros_and_rules(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_macros_and_rules`.
.. method:: generate_target_install(mfile)
This is a reimplementation of
:meth:`sipconfig.Makefile.generate_target_install`.
.. class:: SIPModuleMakefile
This class is derived from :class:`sipconfig.ModuleMakefile`.
This class encapsulates a Makefile to build a SIP generated Python
extension module.
.. method:: __init__(self, configuration, build_file[, install_dir=None[, st
atic=0[, console=0[, opengl=0[, threaded=0[, warnings=None[, debug=0[, dir=None[
, makefile="Makefile"[, installs=None[, strip=1[, export_all=0[, universal=None[
, arch=None[, prot_is_public=0[, deployment_target=None]]]]]]]]]]]]]]]])
:param configuration:
see :meth:`sipconfig.Makefile.__init__`.
:param build_file:
see :meth:`sipconfig.ModuleMakefile.__init__`.
:param install_dir:
see :meth:`sipconfig.ModuleMakefile.__init__`.
:param static:
see :meth:`sipconfig.ModuleMakefile.__init__`.
:param console:
see :meth:`sipconfig.Makefile.__init__`.
:param qt:
see :meth:`sipconfig.Makefile.__init__`.
:param opengl:
see :meth:`sipconfig.Makefile.__init__`.
:param threaded:
see :meth:`sipconfig.Makefile.__init__`.
:param warnings:
see :meth:`sipconfig.Makefile.__init__`.
:param debug:
see :meth:`sipconfig.Makefile.__init__`.
:param dir:
see :meth:`sipconfig.Makefile.__init__`.
:param makefile:
see :meth:`sipconfig.Makefile.__init__`.
:param installs:
see :meth:`sipconfig.Makefile.__init__`.
:param strip:
see :meth:`sipconfig.ModuleMakefile.__init__`.
:param export_all:
see :meth:`sipconfig.ModuleMakefile.__init__`.
:param universal:
see :meth:`sipconfig.Makefile.__init__`.
:param arch:
see :meth:`sipconfig.Makefile.__init__`.
:param prot_is_public:
is set if ``protected`` should be redefined as ``public`` when
compiling the generated module.
:param deployment_target:
see :meth:`sipconfig.Makefile.__init__`.
.. method:: finalise()
This is a reimplementation of :meth:`sipconfig.Makefile.finalise`.