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.

396 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:=2
  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. PKG_BUILD_DEPENDS:=bluez python3/host
  36. HOST_BUILD_DEPENDS:=bzip2/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 +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. CONFIGURE_ARGS+= \
  123. --enable-optimizations \
  124. --enable-shared \
  125. --with-system-ffi \
  126. --without-cxx-main \
  127. --without-ensurepip \
  128. --without-pymalloc \
  129. $(if $(CONFIG_IPV6),--enable-ipv6) \
  130. $(if $(findstring mips,$(CONFIG_ARCH)),,--with-lto) \
  131. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  132. OPT="$(TARGET_CFLAGS)"
  133. define Build/Prepare
  134. $(call Build/Prepare/Default)
  135. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  136. endef
  137. ifdef CONFIG_PACKAGE_python3-setuptools
  138. PYTHON3_SETUPTOOLS_BUILD:=1
  139. endif
  140. ifdef CONFIG_PACKAGE_python3-pkg-resources
  141. PYTHON3_SETUPTOOLS_BUILD:=1
  142. endif
  143. ifeq ($(PYTHON3_SETUPTOOLS_BUILD),1)
  144. define Build/Compile/python3-setuptools
  145. $(HOST_PYTHON3_PIP) \
  146. --disable-pip-version-check \
  147. --cache-dir "$(DL_DIR)/pip-cache" \
  148. install \
  149. --ignore-installed \
  150. --root=$(PKG_BUILD_DIR)/install-setuptools \
  151. --prefix=/usr \
  152. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
  153. $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
  154. endef
  155. else
  156. define Build/Compile/python3-setuptools
  157. ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
  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. # FIXME: [1] get rid of this asap; 'patch' doesn't like Windows endings, and this file is full of them...
  171. # I actually tried this in a number of ways and the only way to fix this is to implement
  172. # a poor-man's dos2unix using sed.
  173. # The issue is with the pip package; it seems that it throws in some Windows line-endings
  174. # and 'patch' won't handle them. So, we do a "dos2unix" and then patch.
  175. # We can get rid of this once this is solved upstream and in pip:
  176. # https://github.com/pypa/pep517/pull/130
  177. sed 's/\r//' -i $(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages/pip/_vendor/pep517/in_process/__init__.py
  178. $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
  179. endef
  180. else
  181. define Build/Compile/python3-pip
  182. ls $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
  183. endef
  184. endif # CONFIG_PACKAGE_python3-pip
  185. define Build/Compile
  186. $(call Build/Compile/Default)
  187. # Use host pip to install python-setuptools
  188. $(call Build/Compile/python3-setuptools)
  189. $(call Build/Compile/python3-pip)
  190. endef
  191. define Build/InstallDev
  192. $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
  193. $(INSTALL_DIR) $(2)/bin
  194. $(CP) \
  195. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON3_VERSION) \
  196. $(1)/usr/include/
  197. $(CP) \
  198. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION) \
  199. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* \
  200. $(1)/usr/lib/
  201. grep \
  202. '^_PYTHON_HOST_PLATFORM=' \
  203. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile > \
  204. $(1)/usr/lib/python$(PYTHON3_VERSION)/config-$(PYTHON3_VERSION)/Makefile-vars
  205. $(CP) \
  206. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
  207. $(1)/usr/lib/pkgconfig
  208. $(INSTALL_BIN) \
  209. $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON3_VERSION)-config \
  210. $(2)/bin/
  211. $(SED) \
  212. 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
  213. $(2)/bin/python$(PYTHON3_VERSION)-config
  214. endef
  215. PYTHON3_BASE_LIB_FILES:= \
  216. /usr/lib/python$(PYTHON3_VERSION)/encodings \
  217. /usr/lib/python$(PYTHON3_VERSION)/_collections_abc.py \
  218. /usr/lib/python$(PYTHON3_VERSION)/_sitebuiltins.py \
  219. /usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py \
  220. /usr/lib/python$(PYTHON3_VERSION)/_weakrefset.py \
  221. /usr/lib/python$(PYTHON3_VERSION)/abc.py \
  222. /usr/lib/python$(PYTHON3_VERSION)/codecs.py \
  223. /usr/lib/python$(PYTHON3_VERSION)/genericpath.py \
  224. /usr/lib/python$(PYTHON3_VERSION)/io.py \
  225. /usr/lib/python$(PYTHON3_VERSION)/os.py \
  226. /usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
  227. /usr/lib/python$(PYTHON3_VERSION)/site.py \
  228. /usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
  229. /usr/lib/python$(PYTHON3_VERSION)/stat.py
  230. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  231. define Py3Package/python3-base/filespec
  232. +|/usr/bin/python$(PYTHON3_VERSION)
  233. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  234. endef
  235. define Py3Package/python3-light/filespec
  236. +|/usr/lib/python$(PYTHON3_VERSION)
  237. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
  238. -|/usr/lib/python$(PYTHON3_VERSION)/distutils/command/wininst*
  239. -|/usr/lib/python$(PYTHON3_VERSION)/ensurepip
  240. -|/usr/lib/python$(PYTHON3_VERSION)/idlelib
  241. -|/usr/lib/python$(PYTHON3_VERSION)/tkinter
  242. -|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
  243. -|/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/_test*.so
  244. -|/usr/lib/python$(PYTHON3_VERSION)/pdb.doc
  245. -|/usr/lib/python$(PYTHON3_VERSION)/test
  246. -|/usr/lib/python$(PYTHON3_VERSION)/webbrowser.py
  247. -|/usr/lib/python$(PYTHON3_VERSION)/*/test
  248. -|/usr/lib/python$(PYTHON3_VERSION)/*/tests
  249. -|/usr/lib/python$(PYTHON3_VERSION)/_osx_support.py
  250. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  251. endef
  252. define Package/libpython3/install
  253. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  254. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON3_VERSION)/lib-dynload/
  255. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON3_VERSION).so* $(1)/usr/lib/
  256. endef
  257. define Py3Package/python3-base/install
  258. $(INSTALL_DIR) $(1)/usr/bin
  259. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python3
  260. $(LN) python$(PYTHON3_VERSION) $(1)/usr/bin/python
  261. # This depends on being called before filespec is processed
  262. $(SED) 's|$(TARGET_AR)|ar|g;s|$(TARGET_CROSS)readelf|readelf|g;s|$(TARGET_CC)|gcc|g;s|$(TARGET_CXX)|g++|g' \
  263. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON3_VERSION)/_sysconfigdata.py
  264. endef
  265. Py3Package/python3-light/install:=:
  266. Py3Package/python3/install:=:
  267. define Py3Package/python3/filespec
  268. -|$(PYTHON3_PKG_DIR)
  269. endef
  270. HOST_LDFLAGS += \
  271. -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
  272. ifeq ($(HOST_OS),Linux)
  273. HOST_LDFLAGS += \
  274. -Wl,--no-as-needed -lrt
  275. endif
  276. ifeq ($(HOST_OS),Darwin)
  277. HOST_CONFIGURE_VARS += \
  278. ac_cv_header_libintl_h=no
  279. HOST_MAKE_VARS += \
  280. USE_PYTHON_CONFIG_PY=1
  281. endif
  282. HOST_CONFIGURE_ARGS+= \
  283. --enable-optimizations \
  284. --with-ensurepip=upgrade \
  285. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  286. --without-cxx-main \
  287. --without-pymalloc \
  288. CONFIG_SITE=
  289. define Host/Configure
  290. $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
  291. $(call Host/Configure/Default)
  292. endef
  293. define Host/Compile
  294. $(call Host/Compile/Default,python)
  295. $(call Host/Compile/Default,sharedmods)
  296. endef
  297. define Host/Install
  298. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  299. rm -rf \
  300. $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
  301. $(HOST_PYTHON3_PKG_DIR)/setuptools \
  302. $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
  303. $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
  304. $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
  305. )
  306. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  307. rm -rf \
  308. $(HOST_PYTHON3_PKG_DIR)/pip \
  309. $(HOST_PYTHON3_PKG_DIR)/pip-* \
  310. $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
  311. $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
  312. )
  313. $(call Host/Install/Default)
  314. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  315. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
  316. touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
  317. )
  318. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  319. # FIXME: [2] get rid of this asap; same as [1]
  320. sed 's/\r//' -i $(HOST_PYTHON3_PKG_DIR)/pip/_vendor/pep517/in_process/__init__.py
  321. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
  322. touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
  323. )
  324. endef
  325. $(eval $(call HostBuild))
  326. $(foreach package, $(PYTHON3_PACKAGES), \
  327. $(eval $(call Py3Package,$(package))) \
  328. $(eval $(call BuildPackage,$(package))) \
  329. $(eval $(call BuildPackage,$(package)-src)) \
  330. )
  331. $(eval $(call BuildPackage,libpython3))
  332. $(eval $(call Py3Package,python3-base))
  333. $(eval $(call Py3Package,python3-light))
  334. $(eval $(call Py3Package,python3))
  335. $(eval $(call BuildPackage,python3-base))
  336. $(eval $(call BuildPackage,python3-light))
  337. $(eval $(call BuildPackage,python3))
  338. $(eval $(call BuildPackage,python3-base-src))
  339. $(eval $(call BuildPackage,python3-light-src))