You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

367 lines
12 KiB

python3: Use default _PYTHON_HOST_PLATFORM This lets the Python build process set _PYTHON_HOST_PLATFORM instead of forcing an explicit value. Also: * Save the target _PYTHON_HOST_PLATFORM value during Build/InstallDev for use when building target Python packages (in python3-package.mk). * Use the (mostly) default PYTHON_FOR_BUILD value, instead patch configure to remove the platform triplet from the sysconfigdata file name. * Remove the "CROSS_COMPILE=yes" make variable (there is no indication that this variable is necessary). * Force host pip to build packages from source instead of downloading binary wheels. Previously, host pip can download universal (platform-independent) wheels but not platform-specific wheels, because of the custom _PYTHON_HOST_PLATFORM value. (Packages that do not have universal wheels would be compiled from source.) With a correct _PYTHON_HOST_PLATFORM, host pip can install platform-specific wheels as well. However, the pre-built shared object (.so) files in these wheels will have the host's platform triplet in their file names. When target Python packages are built (using the target's _PYTHON_HOST_PLATFORM), Python will not use these shared object files. By forcing host pip to build packages from source, the built shared object files will not have the platform triplet in their file names. (Host Python has been patched to remove the platform triplet from file names.) This allows these packages to be used when building target Python packages. (The net effect of this complete change is that platform-dependent packages will continue to be compiled from source, while platform-independent packages will now also be compiled from source.) Signed-off-by: Jeffery To <jeffery.to@gmail.com>
4 years ago
  1. #
  2. # Copyright (C) 2006-2016 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. # The file included below defines PYTHON3_VERSION
  9. include ../python3-version.mk
  10. PKG_NAME:=python3
  11. PKG_RELEASE:=1
  12. PKG_VERSION:=$(PYTHON3_VERSION).$(PYTHON3_VERSION_MICRO)
  13. PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
  14. PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
  15. PKG_HASH:=991c3f8ac97992f3d308fefeb03a64db462574eadbff34ce8bc5bb583d9903ff
  16. PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
  17. PKG_LICENSE:=Python/2.0
  18. PKG_LICENSE_FILES:=LICENSE Doc/copyright.rst Doc/license.rst Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi_osx/LICENSE Modules/expat/COPYING
  19. PKG_CPE_ID:=cpe:/a:python:python
  20. # This file provides the necsessary host build variables
  21. include ../python3-host.mk
  22. # For Py3Package
  23. PYTHON3_PKG_BUILD:=0
  24. include ../python3-package.mk
  25. PKG_FIXUP:=autoreconf
  26. PKG_INSTALL:=1
  27. PKG_BUILD_PARALLEL:=1
  28. HOST_BUILD_PARALLEL:=1
  29. PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
  30. HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
  31. PKG_CONFIG_DEPENDS:= \
  32. CONFIG_PACKAGE_python3-pkg-resources \
  33. CONFIG_PACKAGE_python3-setuptools CONFIG_PACKAGE_python3-pip \
  34. CONFIG_PYTHON3_BLUETOOTH_SUPPORT
  35. PKG_BUILD_DEPENDS:=python3/host
  36. HOST_BUILD_DEPENDS:=bzip2/host expat/host libffi/host
  37. include $(INCLUDE_DIR)/host-build.mk
  38. include $(INCLUDE_DIR)/package.mk
  39. define Package/python3/Default
  40. SUBMENU:=Python
  41. SECTION:=lang
  42. CATEGORY:=Languages
  43. TITLE:=Python $(PYTHON3_VERSION) programming language
  44. URL:=https://www.python.org/
  45. endef
  46. define Package/python3/Default/description
  47. Python is a dynamic object-oriented programming language that can be used
  48. for many kinds of software development. It offers strong support for
  49. integration with other languages and tools, comes with extensive standard
  50. libraries, and can be learned in a few days. Many Python programmers
  51. report substantial productivity gains and feel the language encourages
  52. the development of higher quality, more maintainable code.
  53. endef
  54. define Package/python3-base
  55. $(call Package/python3/Default)
  56. TITLE:=Python $(PYTHON3_VERSION) interpreter
  57. DEPENDS:=+libpthread +zlib
  58. endef
  59. define Package/python3-base/description
  60. This package contains only the interpreter and the bare minimum
  61. for the interpreter to start.
  62. endef
  63. define Package/python3-light
  64. $(call Package/python3/Default)
  65. TITLE:=Python $(PYTHON3_VERSION) light installation
  66. DEPENDS:=+python3-base +libffi +libbz2 +PYTHON3_BLUETOOTH_SUPPORT:bluez-libs +libuuid
  67. endef
  68. define Package/python3-light/config
  69. source "$(SOURCE)/Config-python3-light.in"
  70. endef
  71. define Package/python3-light/description
  72. This package is essentially the python3-base package plus
  73. a few of the rarely used (and big) libraries stripped out
  74. into separate packages.
  75. endef
  76. PYTHON3_LIB_FILES_DEL:=
  77. PYTHON3_PACKAGES:=
  78. PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
  79. PYTHON3_PACKAGES_DEPENDS:=
  80. define Py3BasePackage
  81. PYTHON3_PACKAGES+=$(1)
  82. ifeq ($(3),)
  83. PYTHON3_PACKAGES_DEPENDS+=$(1)
  84. endif
  85. PYTHON3_LIB_FILES_DEL+=$(2)
  86. define Py3Package/$(1)/filespec
  87. ifneq ($(2),)
  88. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  89. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  90. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  91. endif
  92. endef
  93. Py3Package/$(1)/install?=:
  94. endef
  95. include ./files/python3-package-*.mk
  96. define Package/python3
  97. $(call Package/python3/Default)
  98. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  99. endef
  100. define Package/python3/description
  101. This package contains the (almost) full Python install.
  102. It's python3-light + all other packages.
  103. endef
  104. TARGET_CONFIGURE_OPTS+= \
  105. READELF="$(TARGET_CROSS)readelf"
  106. MAKE_FLAGS+=\
  107. LD="$(TARGET_CC)"
  108. EXTRA_CFLAGS+= \
  109. -DNDEBUG -fno-inline
  110. EXTRA_LDFLAGS+= \
  111. -L$(PKG_BUILD_DIR) \
  112. -L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
  113. DISABLE_BLUETOOTH:= \
  114. ac_cv_header_bluetooth_bluetooth_h=no \
  115. ac_cv_header_bluetooth_h=no
  116. CONFIGURE_ARGS+= \
  117. --enable-optimizations \
  118. --enable-shared \
  119. --with-system-ffi \
  120. --without-cxx-main \
  121. --without-ensurepip \
  122. --without-pymalloc \
  123. $(if $(CONFIG_IPV6),--enable-ipv6) \
  124. $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
  125. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  126. OPT="$(TARGET_CFLAGS)" \
  127. $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH))
  128. define Build/Prepare
  129. $(call Build/Prepare/Default)
  130. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  131. endef
  132. ifdef CONFIG_PACKAGE_python3-setuptools
  133. PYTHON3_SETUPTOOLS_BUILD:=1
  134. endif
  135. ifdef CONFIG_PACKAGE_python3-pkg-resources
  136. PYTHON3_SETUPTOOLS_BUILD:=1
  137. endif
  138. ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
  139. define Build/Compile/python3-setuptools
  140. $(HOST_PYTHON3_PIP) \
  141. --disable-pip-version-check \
  142. --cache-dir "$(DL_DIR)/pip-cache" \
  143. install \
  144. --ignore-installed \
  145. --root=$(PKG_BUILD_DIR)/install-setuptools \
  146. --prefix=/usr \
  147. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
  148. $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
  149. endef
  150. endif # CONFIG_PACKAGE_python3-setuptools
  151. ifdef CONFIG_PACKAGE_python3-pip
  152. define Build/Compile/python3-pip
  153. $(HOST_PYTHON3_PIP) \
  154. --disable-pip-version-check \
  155. --cache-dir "$(DL_DIR)/pip-cache" \
  156. install \
  157. --ignore-installed \
  158. --root=$(PKG_BUILD_DIR)/install-pip \
  159. --prefix=/usr \
  160. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py2.py3-none-any.whl
  161. $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
  162. endef
  163. endif # CONFIG_PACKAGE_python3-pip
  164. define Build/Compile
  165. $(call Build/Compile/Default)
  166. # Use host pip to install python-setuptools
  167. $(call Build/Compile/python3-setuptools)
  168. $(call Build/Compile/python3-pip)
  169. endef
  170. define Build/InstallDev
  171. $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
  172. $(INSTALL_DIR) $(2)/bin
  173. $(CP) \
  174. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
  175. $(1)/usr/include/
  176. $(CP) \
  177. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
  178. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
  179. $(1)/usr/lib/
  180. grep \
  181. '^_PYTHON_HOST_PLATFORM=' \
  182. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
  183. $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
  184. $(CP) \
  185. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
  186. $(1)/usr/lib/pkgconfig
  187. $(INSTALL_BIN) \
  188. $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
  189. $(2)/bin/
  190. $(SED) \
  191. 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
  192. $(2)/bin/python$(PYTHON3_VERSION)-config
  193. endef
  194. PYTHON3_BASE_LIB_FILES:= \
  195. /usr/lib/python$(PYTHON3_VERSION)/encodings \
  196. /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
  197. /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
  198. /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
  199. /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
  200. /usr/lib/python$(PYTHON3_VERSION)/abc.py \
  201. /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
  202. /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
  203. /usr/lib/python$(PYTHON3_VERSION)/io.py \
  204. /usr/lib/python$(PYTHON3_VERSION)/os.py \
  205. /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
  206. /usr/lib/python$(PYTHON3_VERSION)/site.py \
  207. /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
  208. /usr/lib/python$(PYTHON3_VERSION)/stat.py
  209. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  210. define Py3Package/python3-base/filespec
  211. +|/usr/bin/python$(PYTHON3_VERSION)
  212. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  213. endef
  214. define Py3Package/python3-light/filespec
  215. +|/usr/lib/python$(PYTHON3_VERSION)
  216. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
  217. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
  218. -|/usr/lib/python$(PYTHON3_VERSION)/ensurepip
  219. -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
  220. -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
  221. -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
  222. -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
  223. -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/readline*.so
  224. -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
  225. -|/usr/lib/python$(PYTHON3_VERSION)/test
  226. -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
  227. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  228. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  229. -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
  230. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  231. endef
  232. define Py3Package/python3-base/install
  233. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  234. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
  235. $(INSTALL_DIR) $(1)/usr/bin
  236. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
  237. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
  238. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
  239. # This depends on being called before filespec is processed
  240. $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
  241. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
  242. endef
  243. Py3Package/python3-light/install:=:
  244. Py3Package/python3/install:=:
  245. define Py3Package/python3/filespec
  246. -|$(PYTHON3_PKG_DIR)
  247. endef
  248. HOST_LDFLAGS += \
  249. -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
  250. ifeq ($(HOST_OS),Linux)
  251. HOST_LDFLAGS += \
  252. -Wl,--no-as-needed -lrt
  253. endif
  254. ifeq ($(HOST_OS),Darwin)
  255. HOST_CONFIGURE_VARS += \
  256. ac_cv_header_libintl_h=no
  257. endif
  258. HOST_CONFIGURE_ARGS+= \
  259. --enable-optimizations \
  260. --with-ensurepip=upgrade \
  261. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  262. --without-cxx-main \
  263. --without-pymalloc \
  264. CONFIG_SITE=
  265. define Host/Configure
  266. $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
  267. $(call Host/Configure/Default)
  268. endef
  269. define Host/Compile
  270. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python
  271. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  272. endef
  273. define Host/Install
  274. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  275. rm -rf \
  276. $(HOST_PYTHON3_PKG_DIR)/easy_install.py \
  277. $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
  278. $(HOST_PYTHON3_PKG_DIR)/setuptools \
  279. $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
  280. $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
  281. $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
  282. )
  283. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  284. rm -rf \
  285. $(HOST_PYTHON3_PKG_DIR)/pip \
  286. $(HOST_PYTHON3_PKG_DIR)/pip-* \
  287. $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
  288. $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
  289. )
  290. $(MAKE) -C $(HOST_BUILD_DIR) install
  291. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  292. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
  293. touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
  294. )
  295. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  296. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
  297. touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
  298. )
  299. endef
  300. $(eval $(call HostBuild))
  301. $(foreach package, $(PYTHON3_PACKAGES), \
  302. $(eval $(call Py3Package,$(package))) \
  303. $(eval $(call BuildPackage,$(package))) \
  304. $(eval $(call BuildPackage,$(package)-src)) \
  305. )
  306. $(eval $(call Py3Package,python3-base))
  307. $(eval $(call Py3Package,python3-light))
  308. $(eval $(call Py3Package,python3))
  309. $(eval $(call BuildPackage,python3-base))
  310. $(eval $(call BuildPackage,python3-light))
  311. $(eval $(call BuildPackage,python3))
  312. $(eval $(call BuildPackage,python3-base-src))
  313. $(eval $(call BuildPackage,python3-light-src))