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.

360 lines
11 KiB

  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 PYTHON_VERSION
  9. include ../python3-version.mk
  10. PYTHON_VERSION:=$(PYTHON3_VERSION)
  11. PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO)
  12. PKG_NAME:=python3
  13. PKG_RELEASE:=13
  14. PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
  15. PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
  16. PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
  17. PKG_HASH:=d83fe8ce51b1bb48bbcf0550fd265b9a75cdfdfa93f916f9e700aef8444bf1bb
  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. PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
  22. # This file provides the necsessary host build variables
  23. include ../python3-host.mk
  24. # For Py3Package
  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-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 $(PYTHON_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 $(PYTHON_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 $(PYTHON_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$(PYTHON_VERSION)/*/test
  90. -|/usr/lib/python$(PYTHON_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. MAKE_FLAGS+=\
  105. CROSS_COMPILE=yes \
  106. LD="$(TARGET_CC)" \
  107. PGEN=pgen3
  108. EXTRA_CFLAGS+= \
  109. -DNDEBUG -fno-inline
  110. EXTRA_LDFLAGS+= \
  111. -L$(PKG_BUILD_DIR)
  112. ENABLE_IPV6:=
  113. ifeq ($(CONFIG_IPV6),y)
  114. ENABLE_IPV6 += --enable-ipv6
  115. endif
  116. PYTHON_FOR_BUILD:= \
  117. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  118. _PYTHON_HOST_PLATFORM=linux2 \
  119. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  120. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  121. $(HOST_PYTHON3_BIN)
  122. DISABLE_BLUETOOTH:= \
  123. ac_cv_header_bluetooth_bluetooth_h=no \
  124. ac_cv_header_bluetooth_h=no
  125. CONFIGURE_ARGS+= \
  126. --sysconfdir=/etc \
  127. --enable-shared \
  128. --without-cxx-main \
  129. --with-threads \
  130. --with-system-ffi \
  131. --with-ensurepip=no \
  132. --without-pymalloc \
  133. $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH)) \
  134. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  135. $(ENABLE_IPV6) \
  136. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  137. OPT="$(TARGET_CFLAGS)"
  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. define Build/Compile/python3-setuptools
  144. $(HOST_PYTHON3_PIP) \
  145. --disable-pip-version-check \
  146. --cache-dir "$(DL_DIR)/pip-cache" \
  147. install \
  148. --ignore-installed \
  149. --root=$(PKG_BUILD_DIR)/install-setuptools \
  150. --prefix=/usr \
  151. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py2.py3-none-any.whl
  152. $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
  153. endef
  154. endif # CONFIG_PACKAGE_python3-setuptools
  155. ifdef CONFIG_PACKAGE_python3-pip
  156. define Build/Compile/python3-pip
  157. $(HOST_PYTHON3_PIP) \
  158. --disable-pip-version-check \
  159. --cache-dir "$(DL_DIR)/pip-cache" \
  160. install \
  161. --ignore-installed \
  162. --root=$(PKG_BUILD_DIR)/install-pip \
  163. --prefix=/usr \
  164. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py2.py3-none-any.whl
  165. $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
  166. endef
  167. endif # CONFIG_PACKAGE_python3-pip
  168. define Build/Compile
  169. $(call Build/Compile/Default)
  170. # Use host pip to install python-setuptools
  171. $(call Build/Compile/python3-setuptools)
  172. $(call Build/Compile/python3-pip)
  173. endef
  174. define Build/InstallDev
  175. $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
  176. $(INSTALL_DIR) $(1)/usr/bin
  177. $(CP) \
  178. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  179. $(1)/usr/include/
  180. $(CP) \
  181. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION) \
  182. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  183. $(1)/usr/lib/
  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$(PYTHON_VERSION)-config \
  189. $(1)/usr/bin/
  190. endef
  191. PYTHON3_BASE_LIB_FILES:= \
  192. /usr/lib/python$(PYTHON_VERSION)/encodings \
  193. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  194. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  195. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  196. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  197. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  198. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  199. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  200. /usr/lib/python$(PYTHON_VERSION)/io.py \
  201. /usr/lib/python$(PYTHON_VERSION)/os.py \
  202. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  203. /usr/lib/python$(PYTHON_VERSION)/site.py \
  204. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  205. /usr/lib/python$(PYTHON_VERSION)/stat.py
  206. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  207. define Py3Package/python3-base/filespec
  208. +|/usr/bin/python$(PYTHON_VERSION)
  209. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  210. endef
  211. define Py3Package/python3-light/filespec
  212. +|/usr/lib/python$(PYTHON_VERSION)
  213. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  214. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  215. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  216. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  217. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  218. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  219. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  220. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  221. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  222. -|/usr/lib/python$(PYTHON_VERSION)/test
  223. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  224. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  225. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  226. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  227. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  228. endef
  229. define Py3Package/python3-base/install
  230. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  231. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  232. $(INSTALL_DIR) $(1)/usr/bin
  233. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  234. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  235. endef
  236. Py3Package/python3-light/install:=:
  237. Py3Package/python3/install:=:
  238. define Py3Package/python3/filespec
  239. -|$(PYTHON3_PKG_DIR)
  240. endef
  241. HOST_LDFLAGS += \
  242. $$$$(pkg-config --static --libs libcrypto libssl) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib
  243. ifeq ($(HOST_OS),Linux)
  244. HOST_LDFLAGS += \
  245. -Wl,--no-as-needed -lrt
  246. endif
  247. HOST_CONFIGURE_ARGS+= \
  248. --without-cxx-main \
  249. --without-pymalloc \
  250. --with-threads \
  251. --prefix=$(HOST_PYTHON3_DIR) \
  252. --exec-prefix=$(HOST_PYTHON3_DIR) \
  253. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  254. --with-ensurepip=upgrade \
  255. CONFIG_SITE=
  256. define Host/Configure
  257. $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
  258. $(call Host/Configure/Default)
  259. endef
  260. define Host/Compile
  261. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
  262. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  263. endef
  264. define Host/Install
  265. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  266. rm -rf \
  267. $(HOST_PYTHON3_PKG_DIR)/easy_install.py \
  268. $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
  269. $(HOST_PYTHON3_PKG_DIR)/setuptools \
  270. $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
  271. $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
  272. $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
  273. )
  274. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  275. rm -rf \
  276. $(HOST_PYTHON3_PKG_DIR)/pip \
  277. $(HOST_PYTHON3_PKG_DIR)/pip-* \
  278. $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
  279. $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
  280. )
  281. $(MAKE) -C $(HOST_BUILD_DIR) install
  282. $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
  283. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
  284. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  285. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
  286. touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
  287. )
  288. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  289. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
  290. touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
  291. )
  292. endef
  293. $(eval $(call HostBuild))
  294. $(foreach package, $(PYTHON3_PACKAGES), \
  295. $(eval $(call Py3Package,$(package))) \
  296. $(eval $(call BuildPackage,$(package))) \
  297. $(eval $(call BuildPackage,$(package)-src)) \
  298. )
  299. $(eval $(call Py3Package,python3-base))
  300. $(eval $(call Py3Package,python3-light))
  301. $(eval $(call Py3Package,python3))
  302. $(eval $(call BuildPackage,python3-base))
  303. $(eval $(call BuildPackage,python3-light))
  304. $(eval $(call BuildPackage,python3))
  305. $(eval $(call BuildPackage,python3-base-src))
  306. $(eval $(call BuildPackage,python3-light-src))