From 94157535445c6f743dd50405618a500816454471 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 00:45:59 +0300 Subject: [PATCH 1/7] python: export CC + CCSHARED env vars to cross-compile Python C extensions properly Signed-off-by: Alexandru Ardelean --- lang/python/files/python-package.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/python/files/python-package.mk b/lang/python/files/python-package.mk index dc30494fe..8bf51ed95 100644 --- a/lang/python/files/python-package.mk +++ b/lang/python/files/python-package.mk @@ -72,6 +72,8 @@ endef define Build/Compile/PyMod $(call HostPython, \ cd $(PKG_BUILD_DIR)/$(strip $(1)); \ + CC="$(TARGET_CC)" \ + CCSHARED="$(TARGET_CC) $(FPIC)" \ CFLAGS="$(TARGET_CFLAGS)" \ CPPFLAGS="$(TARGET_CPPFLAGS)" \ LDFLAGS="$(TARGET_LDFLAGS)" \ From 6521cc7ed742adfa81dbbf5fafa999893e130316 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 01:29:21 +0300 Subject: [PATCH 2/7] python: do not install pyconfig.h on the target Signed-off-by: Alexandru Ardelean --- lang/python/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/lang/python/Makefile b/lang/python/Makefile index 9e6282f08..a2b2699e6 100644 --- a/lang/python/Makefile +++ b/lang/python/Makefile @@ -384,7 +384,6 @@ define PyPackage/python/filespec +|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_heapq.so +|/usr/lib/python$(PYTHON_VERSION)/bisect.py +|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_bisect.so -+|/usr/include/python$(PYTHON_VERSION)/pyconfig.h endef define PyPackage/python/install From bfb286ff624787633c6ed441c1be729526cb3383 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 10:03:44 +0300 Subject: [PATCH 3/7] python: add PYTHON_INC_DIR var to CPPFLAGS The target's PYTHON_INC_DIR should take precedence over the host's include dir when cross-compiling. Signed-off-by: Alexandru Ardelean --- lang/python/files/python-package.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/python/files/python-package.mk b/lang/python/files/python-package.mk index 8bf51ed95..273076387 100644 --- a/lang/python/files/python-package.mk +++ b/lang/python/files/python-package.mk @@ -75,7 +75,7 @@ define Build/Compile/PyMod CC="$(TARGET_CC)" \ CCSHARED="$(TARGET_CC) $(FPIC)" \ CFLAGS="$(TARGET_CFLAGS)" \ - CPPFLAGS="$(TARGET_CPPFLAGS)" \ + CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \ LDFLAGS="$(TARGET_LDFLAGS)" \ $(3) \ , \ From 855ef2a53085f79a0603de7cd08a7ea8923e62c2 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 10:21:03 +0300 Subject: [PATCH 4/7] python: add LD and LDSHARED env vars to Build/Compile/PyMod Tells the host Python to use the target's linker. Signed-off-by: Alexandru Ardelean --- lang/python/files/python-package.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lang/python/files/python-package.mk b/lang/python/files/python-package.mk index 273076387..35f5ac837 100644 --- a/lang/python/files/python-package.mk +++ b/lang/python/files/python-package.mk @@ -74,9 +74,11 @@ define Build/Compile/PyMod cd $(PKG_BUILD_DIR)/$(strip $(1)); \ CC="$(TARGET_CC)" \ CCSHARED="$(TARGET_CC) $(FPIC)" \ + LD="$(TARGET_CC)" \ + LDSHARED="$(TARGET_CC) -shared" \ CFLAGS="$(TARGET_CFLAGS)" \ CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \ - LDFLAGS="$(TARGET_LDFLAGS)" \ + LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \ $(3) \ , \ ./setup.py $(2) \ From a1f86a6870875fca8f288df01ed283927c544a69 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 10:45:17 +0300 Subject: [PATCH 5/7] python: enable shared python lib; make this the norm This will reduce the bloat when users will want to compile in their Python C extensions. There will be a initial bloat (several kb) if just Python is installed, but that will be compensated when users will add more C extensions. During the build we also have to add Python's PKG_BUILD_DIR so that the shared lib is found when compiling Python's built-in C extensions. Signed-off-by: Alexandru Ardelean --- lang/python/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lang/python/Makefile b/lang/python/Makefile index a2b2699e6..02f5a3b05 100644 --- a/lang/python/Makefile +++ b/lang/python/Makefile @@ -140,7 +140,7 @@ MAKE_FLAGS:=\ DESTDIR="$(PKG_INSTALL_DIR)" \ CROSS_COMPILE=yes \ CFLAGS="$(TARGET_CFLAGS) -DNDEBUG -fno-inline" \ - LDFLAGS="$(TARGET_LDFLAGS)" \ + LDFLAGS="$(TARGET_LDFLAGS) -L$(PKG_BUILD_DIR)" \ LD="$(TARGET_CC)" \ PGEN=pgen2 @@ -155,7 +155,7 @@ define Build/Configure $(CP) ./files/config.site $(PKG_BUILD_DIR) $(call Build/Configure/Default, \ --sysconfdir=/etc \ - --disable-shared \ + --enable-shared \ --without-cxx-main \ --with-threads \ --with-system-ffi="$(STAGING_DIR)/usr" \ @@ -176,7 +176,7 @@ define Build/InstallDev $(1)/usr/include/ $(CP) \ $(STAGING_DIR_HOST)/lib/python$(PYTHON_VERSION) \ - $(PKG_BUILD_DIR)/libpython$(PYTHON_VERSION).a \ + $(PKG_BUILD_DIR)/libpython$(PYTHON_VERSION).so* \ $(1)/usr/lib/ $(CP) \ $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config \ @@ -389,6 +389,7 @@ endef define PyPackage/python/install $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python2 + $(CP) $(PKG_BUILD_DIR)/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/ endef define PyPackage/python-doc/filespec From 0141057a59d86cccc7550d0ccbb6f42ed12b41a0 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 21:17:33 +0300 Subject: [PATCH 6/7] python: add _PYTHON_HOST_PLATFORM env var when cross-compiling C extensions This mostly helps to avoid confusion when modules are cross-compiled. Otherwise build folders are named with the host's platform name. Signed-off-by: Alexandru Ardelean --- lang/python/files/python-package.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/python/files/python-package.mk b/lang/python/files/python-package.mk index 35f5ac837..f5ec5cee9 100644 --- a/lang/python/files/python-package.mk +++ b/lang/python/files/python-package.mk @@ -79,6 +79,7 @@ define Build/Compile/PyMod CFLAGS="$(TARGET_CFLAGS)" \ CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON_INC_DIR)" \ LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON_VERSION)" \ + _PYTHON_HOST_PLATFORM="linux-$(ARCH)" \ $(3) \ , \ ./setup.py $(2) \ From 820278a0c83099832527e06e771c64990743f293 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 19 Oct 2014 22:38:03 +0300 Subject: [PATCH 7/7] python: use libncursesw instead of libncurses Python's build scripts prefer ncursesw, and if it is detected it will be used. The problem will occur when linking, since ncursesw libs may not be installed if not added as deps, but the sources will be compiled against ncursesw. Reference from Python's HISTORY file: Patch #1428494: Prefer linking against ncursesw over ncurses library. Signed-off-by: Alexandru Ardelean --- lang/python/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/python/Makefile b/lang/python/Makefile index 02f5a3b05..edecefe1d 100644 --- a/lang/python/Makefile +++ b/lang/python/Makefile @@ -126,13 +126,13 @@ endef define Package/python-readline $(call Package/python/Default) TITLE:=Python support for readline - DEPENDS:=@PACKAGE_python +PACKAGE_python:python +libreadline +libncurses @BROKEN + DEPENDS:=@PACKAGE_python +PACKAGE_python:python +libreadline +libncursesw @BROKEN endef define Package/python-ncurses $(call Package/python/Default) TITLE:=Python support for readline - DEPENDS:=@PACKAGE_python +PACKAGE_python:python +libncurses + DEPENDS:=@PACKAGE_python +PACKAGE_python:python +libncursesw endef MAKE_FLAGS:=\