summaryrefslogtreecommitdiffabout
diff options
context:
space:
mode:
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>2013-12-04 22:59:43 (GMT)
committer Thomas Petazzoni <thomas.petazzoni@free-electrons.com>2013-12-04 22:59:43 (GMT)
commit5880956ce258b15887049ca5850007395cfd1857 (patch)
tree492523c2abdcb9aa3c73e79e62205b42f1d35f42
parent7af351d8da750fd7e3052459b2b2dd9f7041ff25 (diff)
downloadbuildroot-5880956ce258b15887049ca5850007395cfd1857.zip
buildroot-5880956ce258b15887049ca5850007395cfd1857.tar.bz2
package: introduce Python package infrastructure
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
-rw-r--r--docs/manual/adding-packages-python.txt110
-rw-r--r--docs/manual/adding-packages.txt2
-rw-r--r--package/Makefile.in1
-rw-r--r--package/pkg-python.mk141
4 files changed, 254 insertions, 0 deletions
diff --git a/docs/manual/adding-packages-python.txt b/docs/manual/adding-packages-python.txt
new file mode 100644
index 0000000..f878c38
--- /dev/null
+++ b/docs/manual/adding-packages-python.txt
@@ -0,0 +1,110 @@
+// -*- mode:doc; -*-
+// vim: set syntax=asciidoc:
+
+Infrastructure for Python packages
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This infrastructure applies to Python packages that use the standard
+Python setuptools mechanism as their build system, generally
+recognizable as the usage of a +setup.py+ script.
+
+[[python-package-tutorial]]
+
++python-package+ tutorial
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+First, let's see how to write a +.mk+ file for a Python package,
+with an example :
+
+------------------------
+01: ################################################################################
+02: #
+03: # python-foo
+04: #
+05: ################################################################################
+06:
+07: PYTHON_FOO_VERSION = 1.0
+08: PYTHON_FOO_SOURCE = python-foo-$(LIBFOO_VERSION).tar.xz
+09: PYTHON_FOO_SITE = http://www.foosoftware.org/download
+10: LIBFOO_BUILD_ENV = SOME_VAR=1
+11: LIBFOO_DEPENDENCIES = libmad
+12:
+13: $(eval $(python-package))
+------------------------
+
+On line 7, we declare the version of the package.
+
+On line 8 and 9, we declare the name of the tarball (xz-ed tarball
+recommended) and the location of the tarball on the Web. Buildroot
+will automatically download the tarball from this location.
+
+On line 10, we tell Buildroot to pass custom options to the Python
++setup.py+ script when it is configuring the package.
+
+On line 11, we declare our dependencies, so that they are built
+before the build process of our package starts.
+
+Finally, on line line 13, we invoke the +python-package+ macro that
+generates all the Makefile rules that actually allows the package to
+be built.
+
+[[python-package-reference]]
+
++python-package+ reference
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The main macro of the Python package infrastructure is
++python-package+. It is similar to the +generic-package+ macro. The
+ability to have target and host packages is also available, with the
++host-python-package+ macro.
+
+Just like the generic infrastructure, the Python infrastructure works
+by defining a number of variables before calling the +python-package+
+macro.
+
+First, all the package metadata information variables that exist in
+the generic infrastructure also exist in the Python infrastructure:
++PYTHON_FOO_VERSION+, +PYTHON_FOO_SOURCE+, +PYTHON_FOO_PATCH+,
++PYTHON_FOO_SITE+, +PYTHON_FOO_SUBDIR+, +PYTHON_FOO_DEPENDENCIES+,
++PYTHON_FOO_INSTALL_STAGING+, +PYTHON_FOO_INSTALL_TARGET+.
+
+Note however that setting +PYTHON_FOO_INSTALL_STAGING+ to +YES+ has no
+effect, since Python modules generally don't need to be installed to
+the staging directory.
+
+A few additional variables, specific to the Python infrastructure, can
+also be defined. Many of them are only useful in very specific cases,
+typical packages will therefore only use a few of them.
+
+* +PYTHON_FOO_BUILD_ENV+, to specify additional environment variables
+ to pass to the Python +setup.py+ script (for both the build and
+ install steps). Note that the infrastructure is already passing
+ several standard variables: defined in +PKG_PYTHON_BUILD_ENV+ for
+ target packages, and in +HOST_PKG_PYTHON_BUILD_ENV+ for host
+ packages.
+
+* +PYTHON_FOO_BUILD_OPT+, to specify additional options to pass to the
+ Python +setup.py+ script during the build step. Note that when
+ building Python packages for the target, the infrastructure is
+ already passing several standard variables, defined in the
+ +PKG_PYTHON_BUILD_OPT+ variable.
+
+* +PYTHON_FOO_INSTALL_OPT+, to specify additional options to pass to
+ the Python +setup.py+ script during the installation step. Note that
+ when building Python packages for the target, the infrastructure is
+ already passing several standard variables, defined in the
+ +PKG_PYTHON_INSTALL_OPT+ variable.
+
+With the Python infrastructure, all the steps required to build and
+install the packages are already defined, and they generally work well
+for most Python-based packages. However, when required, it is still
+possible to customize what is done in any particular step:
+
+* By adding a post-operation hook (after extract, patch, configure,
+ build or install). See xref:hooks[] for details.
+
+* By overriding one of the steps. For example, even if the Python
+ infrastructure is used, if the package +.mk+ file defines its own
+ +PYTHON_FOO_BUILD_CMDS+ variable, it will be used instead of the
+ default Python one. However, using this method should be restricted
+ to very specific cases. Do not use it in the general case.
diff --git a/docs/manual/adding-packages.txt b/docs/manual/adding-packages.txt
index ae76e74..01277d8 100644
--- a/docs/manual/adding-packages.txt
+++ b/docs/manual/adding-packages.txt
@@ -18,6 +18,8 @@ include::adding-packages-autotools.txt[]
include::adding-packages-cmake.txt[]
+include::adding-packages-python.txt[]
+
include::adding-packages-hooks.txt[]
include::adding-packages-gettext.txt[]
diff --git a/package/Makefile.in b/package/Makefile.in
index 7bc0606..f5d6289 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -371,4 +371,5 @@ include package/pkg-utils.mk
include package/pkg-download.mk
include package/pkg-autotools.mk
include package/pkg-cmake.mk
+include package/pkg-python.mk
include package/pkg-generic.mk
diff --git a/package/pkg-python.mk b/package/pkg-python.mk
new file mode 100644
index 0000000..309ae01
--- /dev/null
+++ b/package/pkg-python.mk
@@ -0,0 +1,141 @@
+################################################################################
+# Python package infrastructure
+#
+# This file implements an infrastructure that eases development of
+# package .mk files for Python packages. It should be used for all
+# packages that use Python setup.py/setuptools as their build system.
+#
+# See the Buildroot documentation for details on the usage of this
+# infrastructure
+#
+# In terms of implementation, this Python infrastructure requires the
+# .mk file to only specify metadata informations about the package:
+# name, version, download URL, etc.
+#
+# We still allow the package .mk file to override what the different
+# steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
+# already defined, it is used as the list of commands to perform to
+# build the package, instead of the default Python behaviour. The
+# package can also define some post operation hooks.
+#
+################################################################################
+
+################################################################################
+# inner-python-package -- defines how the configuration, compilation
+# and installation of a Python package should be done, implements a
+# few hooks to tune the build process and calls the generic package
+# infrastructure to generate the necessary make targets
+#
+# argument 1 is the lowercase package name
+# argument 2 is the uppercase package name, including an HOST_ prefix
+# for host packages
+# argument 3 is the uppercase package name, without the HOST_ prefix
+# for host packages
+# argument 4 is the package directory prefix
+# argument 5 is the type (target or host)
+################################################################################
+
+PKG_PYTHON_BUILD_ENV = \
+ $(TARGET_CONFIGURE_OPTS) \
+ LDSHARED="$(TARGET_CROSS)gcc -shared" \
+ CROSS_COMPILING=yes \
+ PYTHONPATH="$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages" \
+ _python_sysroot=$(STAGING_DIR) \
+ _python_srcdir=$(BUILD_DIR)/python$(PYTHON_VERSION) \
+ _python_prefix=/usr \
+ _python_exec_prefix=/usr
+
+HOST_PKG_PYTHON_BUILD_ENV = \
+ $(HOST_CONFIGURE_OPTS) \
+ PYTHONXCPREFIX="$(HOST_DIR)/usr/"
+
+PKG_PYTHON_BUILD_OPT = \
+ --executable=/usr/bin/python
+
+# This might be only for setuptools
+PKG_PYTHON_INSTALL_OPT = \
+ --executable=/usr/bin/python
+
+define inner-python-package
+
+$(2)_SRCDIR = $$($(2)_DIR)/$($(2)_SUBDIR)
+$(2)_BUILDDIR = $$($(2)_SRCDIR)
+
+$(2)_BUILD_ENV ?=
+$(2)_BUILD_OPT ?=
+$(2)_INSTALL_OPT ?=
+
+# This must be repeated from inner-generic-package, otherwise we only get
+# host-python in _DEPENDENCIES because of the following line
+$(2)_DEPENDENCIES ?= $(filter-out $(1),$(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))
+
+$(2)_DEPENDENCIES += host-python python
+
+#
+# Build step. Only define it if not already defined by the package .mk
+# file.
+#
+ifndef $(2)_BUILD_CMDS
+ifeq ($(5),target)
+define $(2)_BUILD_CMDS
+ (cd $$($$(PKG)_BUILDDIR)/; \
+ $(PKG_PYTHON_BUILD_ENV) \
+ $$($$(PKG)_BUILD_ENV) \
+ $(HOST_DIR)/usr/bin/python setup.py build \
+ $(PKG_PYTHON_BUILD_OPT) \
+ $$($$(PKG)_BUILD_OPT))
+endef
+else
+define $(2)_BUILD_CMDS
+ (cd $$($$(PKG)_BUILDDIR)/; \
+ $(HOST_PKG_PYTHON_BUILD_ENV) \
+ $$($$(PKG)_BUILD_ENV) \
+ $(HOST_DIR)/usr/bin/python setup.py build \
+ $$($$(PKG)_BUILD_OPT))
+endef
+endif
+endif
+
+#
+# Host installation step. Only define it if not already defined by the
+# package .mk file.
+#
+ifndef $(2)_INSTALL_CMDS
+define $(2)_INSTALL_CMDS
+ (cd $$($$(PKG)_BUILDDIR)/; \
+ $(HOST_PKG_PYTHON_BUILD_ENV) \
+ $$($$(PKG)_BUILD_ENV) \
+ $(HOST_DIR)/usr/bin/python setup.py install \
+ --prefix=$(HOST_DIR)/usr \
+ $$($$(PKG)_INSTALL_OPT))
+endef
+endif
+
+#
+# Target installation step. Only define it if not already defined by
+# the package .mk file.
+#
+ifndef $(2)_INSTALL_TARGET_CMDS
+define $(2)_INSTALL_TARGET_CMDS
+ (cd $$($$(PKG)_BUILDDIR)/; \
+ $(PKG_PYTHON_BUILD_ENV) \
+ $$($$(PKG)_BUILD_ENV) \
+ $(HOST_DIR)/usr/bin/python setup.py install \
+ --prefix=$(TARGET_DIR)/usr \
+ $(PKG_PYTHON_INSTALL_OPT) \
+ $$($$(PKG)_INSTALL_OPT))
+endef
+endif
+
+# Call the generic package infrastructure to generate the necessary
+# make targets
+$(call inner-generic-package,$(1),$(2),$(3),$(4),$(5))
+
+endef
+
+################################################################################
+# python-package -- the target generator macro for Python packages
+################################################################################
+
+python-package = $(call inner-python-package,$(call pkgname),$(call UPPERCASE,$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),target)
+host-python-package = $(call inner-python-package,host-$(call pkgname),$(call UPPERCASE,host-$(call pkgname)),$(call UPPERCASE,$(call pkgname)),$(call pkgparentdir),host)