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.

384 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:=0c5a140665436ec3dbfbb79e2dfb6d192655f26ef4a29aeffcb6d1820d716d83
  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/libpython3
  55. $(call Package/python3/Default)
  56. TITLE:=Python $(PYTHON3_VERSION) core library
  57. DEPENDS:=+libpthread +zlib
  58. ABI_VERSION:=$(PYTHON3_VERSION)
  59. endef
  60. define Package/libpython3/description
  61. This package contains only core Python library.
  62. endef
  63. define Package/python3-base
  64. $(call Package/python3/Default)
  65. TITLE:=Python $(PYTHON3_VERSION) interpreter
  66. DEPENDS:=+libpthread +zlib +libpython3
  67. endef
  68. define Package/python3-base/description
  69. This package contains only the interpreter and the bare minimum
  70. for the interpreter to start.
  71. endef
  72. define Package/python3-light
  73. $(call Package/python3/Default)
  74. TITLE:=Python $(PYTHON3_VERSION) light installation
  75. DEPENDS:=+python3-base +libffi +libbz2 +PYTHON3_BLUETOOTH_SUPPORT:bluez-libs +libuuid
  76. endef
  77. define Package/python3-light/config
  78. source "$(SOURCE)/Config-python3-light.in"
  79. endef
  80. define Package/python3-light/description
  81. This package is essentially the python3-base package plus
  82. a few of the rarely used (and big) libraries stripped out
  83. into separate packages.
  84. endef
  85. PYTHON3_LIB_FILES_DEL:=
  86. PYTHON3_PACKAGES:=
  87. PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
  88. PYTHON3_PACKAGES_DEPENDS:=
  89. define Py3BasePackage
  90. PYTHON3_PACKAGES+=$(1)
  91. ifeq ($(3),)
  92. PYTHON3_PACKAGES_DEPENDS+=$(1)
  93. endif
  94. PYTHON3_LIB_FILES_DEL+=$(2)
  95. define Py3Package/$(1)/filespec
  96. ifneq ($(2),)
  97. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  98. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  99. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  100. endif
  101. endef
  102. Py3Package/$(1)/install?=:
  103. endef
  104. include ./files/python3-package-*.mk
  105. define Package/python3
  106. $(call Package/python3/Default)
  107. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  108. endef
  109. define Package/python3/description
  110. This package contains the (almost) full Python install.
  111. It's python3-light + all other packages.
  112. endef
  113. TARGET_CONFIGURE_OPTS+= \
  114. READELF="$(TARGET_CROSS)readelf"
  115. MAKE_FLAGS+=\
  116. LD="$(TARGET_CC)"
  117. EXTRA_CFLAGS+= \
  118. -DNDEBUG -fno-inline
  119. EXTRA_LDFLAGS+= \
  120. -L$(PKG_BUILD_DIR) \
  121. -L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
  122. DISABLE_BLUETOOTH:= \
  123. ac_cv_header_bluetooth_bluetooth_h=no \
  124. ac_cv_header_bluetooth_h=no
  125. CONFIGURE_ARGS+= \
  126. --enable-optimizations \
  127. --enable-shared \
  128. --with-system-ffi \
  129. --without-cxx-main \
  130. --without-ensurepip \
  131. --without-pymalloc \
  132. $(if $(CONFIG_IPV6),--enable-ipv6) \
  133. $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
  134. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  135. OPT="$(TARGET_CFLAGS)" \
  136. $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH))
  137. define Build/Prepare
  138. $(call Build/Prepare/Default)
  139. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  140. endef
  141. ifdef CONFIG_PACKAGE_python3-setuptools
  142. PYTHON3_SETUPTOOLS_BUILD:=1
  143. endif
  144. ifdef CONFIG_PACKAGE_python3-pkg-resources
  145. PYTHON3_SETUPTOOLS_BUILD:=1
  146. endif
  147. ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
  148. define Build/Compile/python3-setuptools
  149. $(HOST_PYTHON3_PIP) \
  150. --disable-pip-version-check \
  151. --cache-dir "$(DL_DIR)/pip-cache" \
  152. install \
  153. --ignore-installed \
  154. --root=$(PKG_BUILD_DIR)/install-setuptools \
  155. --prefix=/usr \
  156. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
  157. $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
  158. endef
  159. endif # CONFIG_PACKAGE_python3-setuptools
  160. ifdef CONFIG_PACKAGE_python3-pip
  161. define Build/Compile/python3-pip
  162. $(HOST_PYTHON3_PIP) \
  163. --disable-pip-version-check \
  164. --cache-dir "$(DL_DIR)/pip-cache" \
  165. install \
  166. --ignore-installed \
  167. --root=$(PKG_BUILD_DIR)/install-pip \
  168. --prefix=/usr \
  169. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
  170. $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
  171. endef
  172. endif # CONFIG_PACKAGE_python3-pip
  173. define Build/Compile
  174. $(call Build/Compile/Default)
  175. # Use host pip to install python-setuptools
  176. $(call Build/Compile/python3-setuptools)
  177. $(call Build/Compile/python3-pip)
  178. endef
  179. define Build/InstallDev
  180. $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
  181. $(INSTALL_DIR) $(2)/bin
  182. $(CP) \
  183. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
  184. $(1)/usr/include/
  185. $(CP) \
  186. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
  187. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
  188. $(1)/usr/lib/
  189. grep \
  190. '^_PYTHON_HOST_PLATFORM=' \
  191. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
  192. $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
  193. $(CP) \
  194. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
  195. $(1)/usr/lib/pkgconfig
  196. $(INSTALL_BIN) \
  197. $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
  198. $(2)/bin/
  199. $(SED) \
  200. 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
  201. $(2)/bin/python$(PYTHON3_VERSION)-config
  202. endef
  203. PYTHON3_BASE_LIB_FILES:= \
  204. /usr/lib/python$(PYTHON3_VERSION)/encodings \
  205. /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
  206. /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
  207. /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
  208. /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
  209. /usr/lib/python$(PYTHON3_VERSION)/abc.py \
  210. /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
  211. /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
  212. /usr/lib/python$(PYTHON3_VERSION)/io.py \
  213. /usr/lib/python$(PYTHON3_VERSION)/os.py \
  214. /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
  215. /usr/lib/python$(PYTHON3_VERSION)/site.py \
  216. /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
  217. /usr/lib/python$(PYTHON3_VERSION)/stat.py
  218. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  219. define Py3Package/python3-base/filespec
  220. +|/usr/bin/python$(PYTHON3_VERSION)
  221. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  222. endef
  223. define Py3Package/python3-light/filespec
  224. +|/usr/lib/python$(PYTHON3_VERSION)
  225. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
  226. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
  227. -|/usr/lib/python$(PYTHON3_VERSION)/ensurepip
  228. -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
  229. -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
  230. -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
  231. -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
  232. -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/readline*.so
  233. -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
  234. -|/usr/lib/python$(PYTHON3_VERSION)/test
  235. -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
  236. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  237. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  238. -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
  239. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  240. endef
  241. define Package/libpython3/install
  242. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  243. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
  244. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
  245. endef
  246. define Py3Package/python3-base/install
  247. $(INSTALL_DIR) $(1)/usr/bin
  248. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
  249. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
  250. # This depends on being called before filespec is processed
  251. $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
  252. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
  253. endef
  254. Py3Package/python3-light/install:=:
  255. Py3Package/python3/install:=:
  256. define Py3Package/python3/filespec
  257. -|$(PYTHON3_PKG_DIR)
  258. endef
  259. HOST_LDFLAGS += \
  260. -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
  261. ifeq ($(HOST_OS),Linux)
  262. HOST_LDFLAGS += \
  263. -Wl,--no-as-needed -lrt
  264. endif
  265. ifeq ($(HOST_OS),Darwin)
  266. HOST_CONFIGURE_VARS += \
  267. ac_cv_header_libintl_h=no
  268. HOST_MAKE_VARS += \
  269. USE_PYTHON_CONFIG_PY=1
  270. endif
  271. HOST_CONFIGURE_ARGS+= \
  272. --enable-optimizations \
  273. --with-ensurepip=upgrade \
  274. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  275. --without-cxx-main \
  276. --without-pymalloc \
  277. CONFIG_SITE=
  278. define Host/Configure
  279. $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
  280. $(call Host/Configure/Default)
  281. endef
  282. define Host/Compile
  283. $(call Host/Compile/Default,python)
  284. $(call Host/Compile/Default,sharedmods)
  285. endef
  286. define Host/Install
  287. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  288. rm -rf \
  289. $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
  290. $(HOST_PYTHON3_PKG_DIR)/setuptools \
  291. $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
  292. $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
  293. $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
  294. )
  295. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  296. rm -rf \
  297. $(HOST_PYTHON3_PKG_DIR)/pip \
  298. $(HOST_PYTHON3_PKG_DIR)/pip-* \
  299. $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
  300. $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
  301. )
  302. $(call Host/Install/Default)
  303. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  304. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
  305. touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
  306. )
  307. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  308. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
  309. touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
  310. )
  311. endef
  312. $(eval $(call HostBuild))
  313. $(foreach package, $(PYTHON3_PACKAGES), \
  314. $(eval $(call Py3Package,$(package))) \
  315. $(eval $(call BuildPackage,$(package))) \
  316. $(eval $(call BuildPackage,$(package)-src)) \
  317. )
  318. $(eval $(call BuildPackage,libpython3))
  319. $(eval $(call Py3Package,python3-base))
  320. $(eval $(call Py3Package,python3-light))
  321. $(eval $(call Py3Package,python3))
  322. $(eval $(call BuildPackage,python3-base))
  323. $(eval $(call BuildPackage,python3-light))
  324. $(eval $(call BuildPackage,python3))
  325. $(eval $(call BuildPackage,python3-base-src))
  326. $(eval $(call BuildPackage,python3-light-src))