350941e31d
We currently have $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages/ inside the PYTHON_PATH variable, which gets used to define PYTHONPATH, passed to the host Python interpreter when building/installing target packages. However, this is terribly wrong, as it causes the host interpreter to potentially import target Python packages. This is wrong for several reasons: - Some Python packages might need some Python modules to be installed on the host (described in setup_requires in setup.py), but their installation currently works because by luck the corresponding Python module is installed for the target. Some of those cases were happening for real, and fixed by previous patches. - Some Python packages include some native code, therefore built for a specific CPU architecture. When you point the host Python interpreter to native libraries built for the target, you get nice build failures, such as the one affecting the python-cffi related packages. Making this change allows to fix the python-cffi related build failures: http://autobuild.buildroot.net/results/a9af84f2d845ee25e2b7d8b92aef485112b46060/ (python-cryptography) http://autobuild.buildroot.net/results/b017c4f6b4d45c0afbf06a80dbd3f2ebe5d49d20/ (python-pynacl) http://autobuild.buildroot.net/results/25144ea191ad46d851b31d3a2f0ef939f215494b/ (python-smbus-cffi) This change has been verified with the following defconfig that enables a lot of Python packages: BR2_arm=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-arm-full-2017.05-834-gb595627.tar.bz2" BR2_TOOLCHAIN_EXTERNAL_GCC_4_9=y BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_10=y BR2_TOOLCHAIN_EXTERNAL_LOCALE=y BR2_TOOLCHAIN_EXTERNAL_CXX=y BR2_INIT_NONE=y BR2_SYSTEM_BIN_SH_NONE=y BR2_PACKAGE_PYTHON=y BR2_PACKAGE_PYTHON_ALSAAUDIO=y BR2_PACKAGE_PYTHON_ARROW=y BR2_PACKAGE_PYTHON_ATTRS=y BR2_PACKAGE_PYTHON_AUTOBAHN=y BR2_PACKAGE_PYTHON_BITSTRING=y BR2_PACKAGE_PYTHON_BOTTLE=y BR2_PACKAGE_PYTHON_CAN=y BR2_PACKAGE_PYTHON_CBOR=y BR2_PACKAGE_PYTHON_CHARDET=y BR2_PACKAGE_PYTHON_CHEETAH=y BR2_PACKAGE_PYTHON_CHERRYPY=y BR2_PACKAGE_PYTHON_CONFIGOBJ=y BR2_PACKAGE_PYTHON_CONFIGSHELL_FB=y BR2_PACKAGE_PYTHON_CRC16=y BR2_PACKAGE_PYTHON_CRCMOD=y BR2_PACKAGE_PYTHON_CSSSELECT=y BR2_PACKAGE_PYTHON_CSSUTILS=y BR2_PACKAGE_PYTHON_DAEMON=y BR2_PACKAGE_PYTHON_DIALOG=y BR2_PACKAGE_PYTHON_DICTTOXML=y BR2_PACKAGE_PYTHON_DJANGO=y BR2_PACKAGE_PYTHON_DOCOPT=y BR2_PACKAGE_PYTHON_DPKT=y BR2_PACKAGE_PYTHON_ECDSA=y BR2_PACKAGE_PYTHON_ENUM=y BR2_PACKAGE_PYTHON_FLASK_BABEL=y BR2_PACKAGE_PYTHON_FLASK_JSONRPC=y BR2_PACKAGE_PYTHON_FLASK_LOGIN=y BR2_PACKAGE_PYTHON_FLUP=y BR2_PACKAGE_PYTHON_GOBJECT=y BR2_PACKAGE_PYTHON_GUNICORN=y BR2_PACKAGE_PYTHON_HTML5LIB=y BR2_PACKAGE_PYTHON_HTTPLIB2=y BR2_PACKAGE_PYTHON_HUMANIZE=y BR2_PACKAGE_PYTHON_ID3=y BR2_PACKAGE_PYTHON_INIPARSE=y BR2_PACKAGE_PYTHON_IOWAIT=y BR2_PACKAGE_PYTHON_IPADDR=y BR2_PACKAGE_PYTHON_IPY=y BR2_PACKAGE_PYTHON_IPYTHON=y BR2_PACKAGE_PYTHON_JSON_SCHEMA_VALIDATOR=y BR2_PACKAGE_PYTHON_KEYRING=y BR2_PACKAGE_PYTHON_LIBCONFIG=y BR2_PACKAGE_PYTHON_LMDB=y BR2_PACKAGE_PYTHON_LXML=y BR2_PACKAGE_PYTHON_MAD=y BR2_PACKAGE_PYTHON_MARKDOWN=y BR2_PACKAGE_PYTHON_MELD3=y BR2_PACKAGE_PYTHON_MISTUNE=y BR2_PACKAGE_PYTHON_MSGPACK=y BR2_PACKAGE_PYTHON_MUTAGEN=y BR2_PACKAGE_PYTHON_MWSCRAPE=y BR2_PACKAGE_PYTHON_NETADDR=y BR2_PACKAGE_PYTHON_NETIFACES=y BR2_PACKAGE_PYTHON_NFC=y BR2_PACKAGE_PYTHON_NUMPY=y BR2_PACKAGE_PYTHON_PAHO_MQTT=y BR2_PACKAGE_PYTHON_PAM=y BR2_PACKAGE_PYTHON_PARAMIKO=y BR2_PACKAGE_PYTHON_PILLOW=y BR2_PACKAGE_PYTHON_POSIX_IPC=y BR2_PACKAGE_PYTHON_PSUTIL=y BR2_PACKAGE_PYTHON_PUDB=y BR2_PACKAGE_PYTHON_PYCLI=y BR2_PACKAGE_PYTHON_PYCPARSER=y BR2_PACKAGE_PYTHON_PYELFTOOLS=y BR2_PACKAGE_PYTHON_PYFTPDLIB=y BR2_PACKAGE_PYTHON_PYGAME=y BR2_PACKAGE_PYTHON_PYGAME_IMAGE=y BR2_PACKAGE_PYTHON_PYGAME_EXAMPLES=y BR2_PACKAGE_PYTHON_PYGAME_FONT=y BR2_PACKAGE_PYTHON_PYGAME_MIXER=y BR2_PACKAGE_PYTHON_PYINOTIFY=y BR2_PACKAGE_PYTHON_PYLIBFTDI=y BR2_PACKAGE_PYTHON_PYMYSQL=y BR2_PACKAGE_PYTHON_PYPARTED=y BR2_PACKAGE_PYTHON_PYPCAP=y BR2_PACKAGE_PYTHON_PYQRCODE=y BR2_PACKAGE_PYTHON_PYRATEMP=y BR2_PACKAGE_PYTHON_PYRO=y BR2_PACKAGE_PYTHON_PYROUTE2=y BR2_PACKAGE_PYTHON_PYSENDFILE=y BR2_PACKAGE_PYTHON_PYSMB=y BR2_PACKAGE_PYTHON_PYSNMP_APPS=y BR2_PACKAGE_PYTHON_PYSNMP_MIBS=y BR2_PACKAGE_PYTHON_PYSOCKS=y BR2_PACKAGE_PYTHON_PYTABLEWRITER=y BR2_PACKAGE_PYTHON_PYTRIE=y BR2_PACKAGE_PYTHON_PYUSB=y BR2_PACKAGE_PYTHON_PYXB=y BR2_PACKAGE_PYTHON_PYZMQ=y BR2_PACKAGE_PYTHON_REQUESTS_TOOLBELT=y BR2_PACKAGE_PYTHON_RPI_GPIO=y BR2_PACKAGE_PYTHON_RTSLIB_FB=y BR2_PACKAGE_PYTHON_SDNOTIFY=y BR2_PACKAGE_PYTHON_SERIAL=y BR2_PACKAGE_PYTHON_SETPROCTITLE=y BR2_PACKAGE_PYTHON_SH=y BR2_PACKAGE_PYTHON_SHUTILWHICH=y BR2_PACKAGE_PYTHON_SIMPLEJSON=y BR2_PACKAGE_PYTHON_SMBUS_CFFI=y BR2_PACKAGE_PYTHON_SOCKETIO=y BR2_PACKAGE_PYTHON_SORTEDCONTAINERS=y BR2_PACKAGE_PYTHON_SPIDEV=y BR2_PACKAGE_PYTHON_THRIFT=y BR2_PACKAGE_PYTHON_TOMAKO=y BR2_PACKAGE_PYTHON_TREQ=y BR2_PACKAGE_PYTHON_U_MSGPACK=y BR2_PACKAGE_PYTHON_UBJSON=y BR2_PACKAGE_PYTHON_UJSON=y BR2_PACKAGE_PYTHON_URLLIB3=y BR2_PACKAGE_PYTHON_VERSIONTOOLS=y BR2_PACKAGE_PYTHON_WATCHDOG=y BR2_PACKAGE_PYTHON_WEB2PY=y BR2_PACKAGE_PYTHON_WEBPY=y BR2_PACKAGE_PYTHON_WHOOSH=y BR2_PACKAGE_PYTHON_WS4PY=y BR2_PACKAGE_PYTHON_WSACCEL=y BR2_PACKAGE_PYTHON_XLUTILS=y Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Reviewed-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
287 lines
8.2 KiB
Makefile
287 lines
8.2 KiB
Makefile
################################################################################
|
|
#
|
|
# python
|
|
#
|
|
################################################################################
|
|
|
|
PYTHON_VERSION_MAJOR = 2.7
|
|
PYTHON_VERSION = $(PYTHON_VERSION_MAJOR).13
|
|
PYTHON_SOURCE = Python-$(PYTHON_VERSION).tar.xz
|
|
PYTHON_SITE = http://python.org/ftp/python/$(PYTHON_VERSION)
|
|
PYTHON_LICENSE = Python-2.0, others
|
|
PYTHON_LICENSE_FILES = LICENSE
|
|
PYTHON_LIBTOOL_PATCH = NO
|
|
|
|
# Python needs itself to be built, so in order to cross-compile
|
|
# Python, we need to build a host Python first. This host Python is
|
|
# also installed in $(HOST_DIR), as it is needed when cross-compiling
|
|
# third-party Python modules.
|
|
|
|
HOST_PYTHON_CONF_OPTS += \
|
|
--enable-static \
|
|
--without-cxx-main \
|
|
--disable-sqlite3 \
|
|
--disable-tk \
|
|
--with-expat=system \
|
|
--disable-curses \
|
|
--disable-codecs-cjk \
|
|
--disable-nis \
|
|
--enable-unicodedata \
|
|
--disable-dbm \
|
|
--disable-gdbm \
|
|
--disable-bsddb \
|
|
--disable-test-modules \
|
|
--disable-bz2 \
|
|
--disable-ssl \
|
|
--disable-ossaudiodev \
|
|
--disable-pyo-build
|
|
|
|
# Make sure that LD_LIBRARY_PATH overrides -rpath.
|
|
# This is needed because libpython may be installed at the same time that
|
|
# python is called.
|
|
# Make python believe we don't have 'hg' and 'svn', so that it doesn't
|
|
# try to communicate over the network during the build.
|
|
HOST_PYTHON_CONF_ENV += \
|
|
LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \
|
|
ac_cv_prog_HAS_HG=/bin/false \
|
|
ac_cv_prog_SVNVERSION=/bin/false
|
|
|
|
# Building host python in parallel sometimes triggers a "Bus error"
|
|
# during the execution of "./python setup.py build" in the
|
|
# installation step. It is probably due to the installation of a
|
|
# shared library taking place in parallel to the execution of
|
|
# ./python, causing spurious Bus error. Building host-python with
|
|
# MAKE1 has shown to workaround the problem.
|
|
HOST_PYTHON_MAKE = $(MAKE1)
|
|
|
|
PYTHON_DEPENDENCIES = host-python libffi $(TARGET_NLS_DEPENDENCIES)
|
|
|
|
HOST_PYTHON_DEPENDENCIES = host-expat host-zlib
|
|
|
|
PYTHON_INSTALL_STAGING = YES
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_READLINE),y)
|
|
PYTHON_DEPENDENCIES += readline
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-readline
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_CURSES),y)
|
|
PYTHON_DEPENDENCIES += ncurses
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-curses
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_PYEXPAT),y)
|
|
PYTHON_DEPENDENCIES += expat
|
|
PYTHON_CONF_OPTS += --with-expat=system
|
|
else
|
|
PYTHON_CONF_OPTS += --with-expat=none
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_BSDDB),y)
|
|
PYTHON_DEPENDENCIES += berkeleydb
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-bsddb
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_SQLITE),y)
|
|
PYTHON_DEPENDENCIES += sqlite
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-sqlite3
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_SSL),y)
|
|
PYTHON_DEPENDENCIES += openssl
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-ssl
|
|
endif
|
|
|
|
ifneq ($(BR2_PACKAGE_PYTHON_CODECSCJK),y)
|
|
PYTHON_CONF_OPTS += --disable-codecs-cjk
|
|
endif
|
|
|
|
ifneq ($(BR2_PACKAGE_PYTHON_UNICODEDATA),y)
|
|
PYTHON_CONF_OPTS += --disable-unicodedata
|
|
endif
|
|
|
|
# Default is UCS2 w/o a conf opt
|
|
ifeq ($(BR2_PACKAGE_PYTHON_UCS4),y)
|
|
# host-python must have the same UCS2/4 configuration as the target
|
|
# python
|
|
HOST_PYTHON_CONF_OPTS += --enable-unicode=ucs4
|
|
PYTHON_CONF_OPTS += --enable-unicode=ucs4
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_BZIP2),y)
|
|
PYTHON_DEPENDENCIES += bzip2
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-bz2
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_ZLIB),y)
|
|
PYTHON_DEPENDENCIES += zlib
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-zlib
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_HASHLIB),y)
|
|
PYTHON_DEPENDENCIES += openssl
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-hashlib
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_OSSAUDIODEV),y)
|
|
PYTHON_CONF_OPTS += --enable-ossaudiodev
|
|
else
|
|
PYTHON_CONF_OPTS += --disable-ossaudiodev
|
|
endif
|
|
|
|
# Make python believe we don't have 'hg' and 'svn', so that it doesn't
|
|
# try to communicate over the network during the build.
|
|
PYTHON_CONF_ENV += \
|
|
ac_cv_have_long_long_format=yes \
|
|
ac_cv_file__dev_ptmx=yes \
|
|
ac_cv_file__dev_ptc=yes \
|
|
ac_cv_working_tzset=yes \
|
|
ac_cv_prog_HAS_HG=/bin/false \
|
|
ac_cv_prog_SVNVERSION=/bin/false
|
|
|
|
# GCC is always compliant with IEEE754
|
|
ifeq ($(BR2_ENDIAN),"LITTLE")
|
|
PYTHON_CONF_ENV += ac_cv_little_endian_double=yes
|
|
else
|
|
PYTHON_CONF_ENV += ac_cv_big_endian_double=yes
|
|
endif
|
|
|
|
PYTHON_CONF_OPTS += \
|
|
--without-cxx-main \
|
|
--without-doc-strings \
|
|
--with-system-ffi \
|
|
--disable-pydoc \
|
|
--disable-test-modules \
|
|
--disable-lib2to3 \
|
|
--disable-gdbm \
|
|
--disable-tk \
|
|
--disable-nis \
|
|
--disable-dbm \
|
|
--disable-pyo-build \
|
|
--disable-pyc-build
|
|
|
|
# This is needed to make sure the Python build process doesn't try to
|
|
# regenerate those files with the pgen program. Otherwise, it builds
|
|
# pgen for the target, and tries to run it on the host.
|
|
|
|
define PYTHON_TOUCH_GRAMMAR_FILES
|
|
touch $(@D)/Include/graminit.h $(@D)/Python/graminit.c
|
|
endef
|
|
|
|
PYTHON_POST_PATCH_HOOKS += PYTHON_TOUCH_GRAMMAR_FILES
|
|
|
|
#
|
|
# Remove useless files. In the config/ directory, only the Makefile
|
|
# and the pyconfig.h files are needed at runtime.
|
|
#
|
|
# idle & smtpd.py have bad shebangs and are mostly samples
|
|
#
|
|
define PYTHON_REMOVE_USELESS_FILES
|
|
rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR)-config
|
|
rm -f $(TARGET_DIR)/usr/bin/python2-config
|
|
rm -f $(TARGET_DIR)/usr/bin/python-config
|
|
rm -f $(TARGET_DIR)/usr/bin/smtpd.py
|
|
for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/config/ \
|
|
-type f -not -name pyconfig.h -a -not -name Makefile` ; do \
|
|
rm -f $$i ; \
|
|
done
|
|
endef
|
|
|
|
PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_REMOVE_USELESS_FILES
|
|
|
|
#
|
|
# Make sure libpython gets stripped out on target
|
|
#
|
|
define PYTHON_ENSURE_LIBPYTHON_STRIPPED
|
|
chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON_VERSION_MAJOR)*.so
|
|
endef
|
|
|
|
PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_ENSURE_LIBPYTHON_STRIPPED
|
|
|
|
# Always install the python symlink in the target tree
|
|
define PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
|
|
ln -sf python2 $(TARGET_DIR)/usr/bin/python
|
|
endef
|
|
|
|
PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_INSTALL_TARGET_PYTHON_SYMLINK
|
|
|
|
# Always install the python-config symlink in the staging tree
|
|
define PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
|
|
ln -sf python2-config $(STAGING_DIR)/usr/bin/python-config
|
|
endef
|
|
|
|
PYTHON_POST_INSTALL_STAGING_HOOKS += PYTHON_INSTALL_STAGING_PYTHON_CONFIG_SYMLINK
|
|
|
|
PYTHON_AUTORECONF = YES
|
|
|
|
# Some packages may have build scripts requiring python2.
|
|
# Only install the python symlink in the host tree if python3 is not enabled
|
|
# for the target, otherwise the default python program may be missing.
|
|
ifneq ($(BR2_PACKAGE_PYTHON3),y)
|
|
define HOST_PYTHON_INSTALL_PYTHON_SYMLINK
|
|
ln -sf python2 $(HOST_DIR)/bin/python
|
|
ln -sf python2-config $(HOST_DIR)/bin/python-config
|
|
endef
|
|
|
|
HOST_PYTHON_POST_INSTALL_HOOKS += HOST_PYTHON_INSTALL_PYTHON_SYMLINK
|
|
endif
|
|
|
|
# Provided to other packages
|
|
PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
|
|
|
|
$(eval $(autotools-package))
|
|
$(eval $(host-autotools-package))
|
|
|
|
ifeq ($(BR2_REPRODUCIBLE),y)
|
|
define PYTHON_FIX_TIME
|
|
find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | \
|
|
xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH)
|
|
endef
|
|
endif
|
|
|
|
define PYTHON_CREATE_PYC_FILES
|
|
$(PYTHON_FIX_TIME)
|
|
PYTHONPATH="$(PYTHON_PATH)" \
|
|
cd $(TARGET_DIR) && $(HOST_DIR)/bin/python$(PYTHON_VERSION_MAJOR) \
|
|
$(TOPDIR)/support/scripts/pycompile.py \
|
|
$(if $(BR2_REPRODUCIBLE),--force) \
|
|
usr/lib/python$(PYTHON_VERSION_MAJOR)
|
|
endef
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY)$(BR2_PACKAGE_PYTHON_PY_PYC),y)
|
|
PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_CREATE_PYC_FILES
|
|
endif
|
|
|
|
ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
|
|
define PYTHON_REMOVE_PY_FILES
|
|
find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | \
|
|
xargs -0 --no-run-if-empty rm -f
|
|
endef
|
|
PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PY_FILES
|
|
endif
|
|
|
|
# Normally, *.pyc files should not have been compiled, but just in
|
|
# case, we make sure we remove all of them.
|
|
ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
|
|
define PYTHON_REMOVE_PYC_FILES
|
|
find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | \
|
|
xargs -0 --no-run-if-empty rm -f
|
|
endef
|
|
PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYC_FILES
|
|
endif
|
|
|
|
# In all cases, we don't want to keep the optimized .pyo files
|
|
define PYTHON_REMOVE_PYO_FILES
|
|
find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyo' -print0 | \
|
|
xargs -0 --no-run-if-empty rm -f
|
|
endef
|
|
PYTHON_TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYO_FILES
|