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.

402 lines
13 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>
5 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. # FIXME: if updating, get rid of [1] & [2] asap
  16. PKG_HASH:=f8145616e68c00041d1a6399b76387390388f8359581abc24432bb969b5e3c57
  17. PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
  18. PKG_LICENSE:=Python/2.0
  19. PKG_LICENSE_FILES:=LICENSE Doc/copyright.rst Doc/license.rst Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi_osx/LICENSE Modules/expat/COPYING
  20. PKG_CPE_ID:=cpe:/a:python:python
  21. # This file provides the necsessary host build variables
  22. include ../python3-host.mk
  23. # For Py3Package
  24. PYTHON3_PKG_BUILD:=0
  25. include ../python3-package.mk
  26. PKG_FIXUP:=autoreconf
  27. PKG_INSTALL:=1
  28. PKG_BUILD_PARALLEL:=1
  29. HOST_BUILD_PARALLEL:=1
  30. PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
  31. HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
  32. PKG_CONFIG_DEPENDS:= \
  33. CONFIG_PACKAGE_python3-pkg-resources \
  34. CONFIG_PACKAGE_python3-setuptools CONFIG_PACKAGE_python3-pip \
  35. CONFIG_PYTHON3_BLUETOOTH_SUPPORT
  36. PKG_BUILD_DEPENDS:=python3/host
  37. HOST_BUILD_DEPENDS:=bzip2/host expat/host libffi/host
  38. include $(INCLUDE_DIR)/host-build.mk
  39. include $(INCLUDE_DIR)/package.mk
  40. define Package/python3/Default
  41. SUBMENU:=Python
  42. SECTION:=lang
  43. CATEGORY:=Languages
  44. TITLE:=Python $(PYTHON3_VERSION) programming language
  45. URL:=https://www.python.org/
  46. endef
  47. define Package/python3/Default/description
  48. Python is a dynamic object-oriented programming language that can be used
  49. for many kinds of software development. It offers strong support for
  50. integration with other languages and tools, comes with extensive standard
  51. libraries, and can be learned in a few days. Many Python programmers
  52. report substantial productivity gains and feel the language encourages
  53. the development of higher quality, more maintainable code.
  54. endef
  55. define Package/libpython3
  56. $(call Package/python3/Default)
  57. TITLE:=Python $(PYTHON3_VERSION) core library
  58. DEPENDS:=+libpthread +zlib
  59. ABI_VERSION:=$(PYTHON3_VERSION)
  60. endef
  61. define Package/libpython3/description
  62. This package contains only core Python library.
  63. endef
  64. define Package/python3-base
  65. $(call Package/python3/Default)
  66. TITLE:=Python $(PYTHON3_VERSION) interpreter
  67. DEPENDS:=+libpthread +zlib +libpython3
  68. endef
  69. define Package/python3-base/description
  70. This package contains only the interpreter and the bare minimum
  71. for the interpreter to start.
  72. endef
  73. define Package/python3-light
  74. $(call Package/python3/Default)
  75. TITLE:=Python $(PYTHON3_VERSION) light installation
  76. DEPENDS:=+python3-base +libffi +libbz2 +PYTHON3_BLUETOOTH_SUPPORT:bluez-libs +libuuid
  77. endef
  78. define Package/python3-light/config
  79. source "$(SOURCE)/Config-python3-light.in"
  80. endef
  81. define Package/python3-light/description
  82. This package is essentially the python3-base package plus
  83. a few of the rarely used (and big) libraries stripped out
  84. into separate packages.
  85. endef
  86. PYTHON3_LIB_FILES_DEL:=
  87. PYTHON3_PACKAGES:=
  88. PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
  89. PYTHON3_PACKAGES_DEPENDS:=
  90. define Py3BasePackage
  91. PYTHON3_PACKAGES+=$(1)
  92. ifeq ($(3),)
  93. PYTHON3_PACKAGES_DEPENDS+=$(1)
  94. endif
  95. PYTHON3_LIB_FILES_DEL+=$(2)
  96. define Py3Package/$(1)/filespec
  97. ifneq ($(2),)
  98. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  99. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  100. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  101. endif
  102. endef
  103. Py3Package/$(1)/install?=:
  104. endef
  105. include ./files/python3-package-*.mk
  106. define Package/python3
  107. $(call Package/python3/Default)
  108. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  109. endef
  110. define Package/python3/description
  111. This package contains the (almost) full Python install.
  112. It's python3-light + all other packages.
  113. endef
  114. TARGET_CONFIGURE_OPTS+= \
  115. READELF="$(TARGET_CROSS)readelf"
  116. MAKE_FLAGS+=\
  117. LD="$(TARGET_CC)"
  118. EXTRA_CFLAGS+= \
  119. -DNDEBUG -fno-inline
  120. EXTRA_LDFLAGS+= \
  121. -L$(PKG_BUILD_DIR) \
  122. -L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
  123. DISABLE_BLUETOOTH:= \
  124. ac_cv_header_bluetooth_bluetooth_h=no \
  125. ac_cv_header_bluetooth_h=no
  126. CONFIGURE_ARGS+= \
  127. --enable-optimizations \
  128. --enable-shared \
  129. --with-system-ffi \
  130. --without-cxx-main \
  131. --without-ensurepip \
  132. --without-pymalloc \
  133. $(if $(CONFIG_IPV6),--enable-ipv6) \
  134. $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
  135. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  136. OPT="$(TARGET_CFLAGS)" \
  137. $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH))
  138. define Build/Prepare
  139. $(call Build/Prepare/Default)
  140. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  141. endef
  142. ifdef CONFIG_PACKAGE_python3-setuptools
  143. PYTHON3_SETUPTOOLS_BUILD:=1
  144. endif
  145. ifdef CONFIG_PACKAGE_python3-pkg-resources
  146. PYTHON3_SETUPTOOLS_BUILD:=1
  147. endif
  148. ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
  149. define Build/Compile/python3-setuptools
  150. $(HOST_PYTHON3_PIP) \
  151. --disable-pip-version-check \
  152. --cache-dir "$(DL_DIR)/pip-cache" \
  153. install \
  154. --ignore-installed \
  155. --root=$(PKG_BUILD_DIR)/install-setuptools \
  156. --prefix=/usr \
  157. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
  158. $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
  159. endef
  160. else
  161. define Build/Compile/python3-setuptools
  162. ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
  163. endef
  164. endif # CONFIG_PACKAGE_python3-setuptools
  165. ifdef CONFIG_PACKAGE_python3-pip
  166. define Build/Compile/python3-pip
  167. $(HOST_PYTHON3_PIP) \
  168. --disable-pip-version-check \
  169. --cache-dir "$(DL_DIR)/pip-cache" \
  170. install \
  171. --ignore-installed \
  172. --root=$(PKG_BUILD_DIR)/install-pip \
  173. --prefix=/usr \
  174. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
  175. # FIXME: [1] get rid of this asap; 'patch' doesn't like Windows endings, and this file is full of them...
  176. # I actually tried this in a number of ways and the only way to fix this is to implement
  177. # a poor-man's dos2unix using sed.
  178. # The issue is with the pip package; it seems that it throws in some Windows line-endings
  179. # and 'patch' won't handle them. So, we do a "dos2unix" and then patch.
  180. # We can get rid of this once this is solved upstream and in pip:
  181. # https://github.com/pypa/pep517/pull/130
  182. sed 's/\r//' -i $(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages/pip/_vendor/pep517/in_process/__init__.py
  183. $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
  184. endef
  185. else
  186. define Build/Compile/python3-pip
  187. ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
  188. endef
  189. endif # CONFIG_PACKAGE_python3-pip
  190. define Build/Compile
  191. $(call Build/Compile/Default)
  192. # Use host pip to install python-setuptools
  193. $(call Build/Compile/python3-setuptools)
  194. $(call Build/Compile/python3-pip)
  195. endef
  196. define Build/InstallDev
  197. $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
  198. $(INSTALL_DIR) $(2)/bin
  199. $(CP) \
  200. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
  201. $(1)/usr/include/
  202. $(CP) \
  203. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
  204. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
  205. $(1)/usr/lib/
  206. grep \
  207. '^_PYTHON_HOST_PLATFORM=' \
  208. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
  209. $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
  210. $(CP) \
  211. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
  212. $(1)/usr/lib/pkgconfig
  213. $(INSTALL_BIN) \
  214. $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
  215. $(2)/bin/
  216. $(SED) \
  217. 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
  218. $(2)/bin/python$(PYTHON3_VERSION)-config
  219. endef
  220. PYTHON3_BASE_LIB_FILES:= \
  221. /usr/lib/python$(PYTHON3_VERSION)/encodings \
  222. /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
  223. /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
  224. /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
  225. /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
  226. /usr/lib/python$(PYTHON3_VERSION)/abc.py \
  227. /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
  228. /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
  229. /usr/lib/python$(PYTHON3_VERSION)/io.py \
  230. /usr/lib/python$(PYTHON3_VERSION)/os.py \
  231. /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
  232. /usr/lib/python$(PYTHON3_VERSION)/site.py \
  233. /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
  234. /usr/lib/python$(PYTHON3_VERSION)/stat.py
  235. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  236. define Py3Package/python3-base/filespec
  237. +|/usr/bin/python$(PYTHON3_VERSION)
  238. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  239. endef
  240. define Py3Package/python3-light/filespec
  241. +|/usr/lib/python$(PYTHON3_VERSION)
  242. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
  243. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
  244. -|/usr/lib/python$(PYTHON3_VERSION)/ensurepip
  245. -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
  246. -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
  247. -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
  248. -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
  249. -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
  250. -|/usr/lib/python$(PYTHON3_VERSION)/test
  251. -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
  252. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  253. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  254. -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
  255. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  256. endef
  257. define Package/libpython3/install
  258. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  259. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
  260. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
  261. endef
  262. define Py3Package/python3-base/install
  263. $(INSTALL_DIR) $(1)/usr/bin
  264. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
  265. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
  266. # This depends on being called before filespec is processed
  267. $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
  268. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
  269. endef
  270. Py3Package/python3-light/install:=:
  271. Py3Package/python3/install:=:
  272. define Py3Package/python3/filespec
  273. -|$(PYTHON3_PKG_DIR)
  274. endef
  275. HOST_LDFLAGS += \
  276. -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
  277. ifeq ($(HOST_OS),Linux)
  278. HOST_LDFLAGS += \
  279. -Wl,--no-as-needed -lrt
  280. endif
  281. ifeq ($(HOST_OS),Darwin)
  282. HOST_CONFIGURE_VARS += \
  283. ac_cv_header_libintl_h=no
  284. HOST_MAKE_VARS += \
  285. USE_PYTHON_CONFIG_PY=1
  286. endif
  287. HOST_CONFIGURE_ARGS+= \
  288. --enable-optimizations \
  289. --with-ensurepip=upgrade \
  290. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  291. --without-cxx-main \
  292. --without-pymalloc \
  293. CONFIG_SITE=
  294. define Host/Configure
  295. $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
  296. $(call Host/Configure/Default)
  297. endef
  298. define Host/Compile
  299. $(call Host/Compile/Default,python)
  300. $(call Host/Compile/Default,sharedmods)
  301. endef
  302. define Host/Install
  303. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  304. rm -rf \
  305. $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
  306. $(HOST_PYTHON3_PKG_DIR)/setuptools \
  307. $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
  308. $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
  309. $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
  310. )
  311. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  312. rm -rf \
  313. $(HOST_PYTHON3_PKG_DIR)/pip \
  314. $(HOST_PYTHON3_PKG_DIR)/pip-* \
  315. $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
  316. $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
  317. )
  318. $(call Host/Install/Default)
  319. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  320. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
  321. touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
  322. )
  323. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  324. # FIXME: [2] get rid of this asap; same as [1]
  325. sed 's/\r//' -i $(HOST_PYTHON3_PKG_DIR)/pip/_vendor/pep517/in_process/__init__.py
  326. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
  327. touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
  328. )
  329. endef
  330. $(eval $(call HostBuild))
  331. $(foreach package, $(PYTHON3_PACKAGES), \
  332. $(eval $(call Py3Package,$(package))) \
  333. $(eval $(call BuildPackage,$(package))) \
  334. $(eval $(call BuildPackage,$(package)-src)) \
  335. )
  336. $(eval $(call BuildPackage,libpython3))
  337. $(eval $(call Py3Package,python3-base))
  338. $(eval $(call Py3Package,python3-light))
  339. $(eval $(call Py3Package,python3))
  340. $(eval $(call BuildPackage,python3-base))
  341. $(eval $(call BuildPackage,python3-light))
  342. $(eval $(call BuildPackage,python3))
  343. $(eval $(call BuildPackage,python3-base-src))
  344. $(eval $(call BuildPackage,python3-light-src))