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.

373 lines
12 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:=2
  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:=b356244e13fb5491da890b35b13b2118c3122977c2cd825e3eb6e7d462030d84
  18. PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
  19. PKG_LICENSE:=Python/2.0
  20. PKG_LICENSE_FILES:=LICENSE Doc/copyright.rst Doc/license.rst Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi_osx/LICENSE Modules/expat/COPYING
  21. PKG_CPE_ID:=cpe:/a:python:python
  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-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 $(PYTHON_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/python3-base
  56. $(call Package/python3/Default)
  57. TITLE:=Python $(PYTHON_VERSION) interpreter
  58. DEPENDS:=+libpthread +zlib
  59. endef
  60. define Package/python3-base/description
  61. This package contains only the interpreter and the bare minimum
  62. for the interpreter to start.
  63. endef
  64. define Package/python3-light
  65. $(call Package/python3/Default)
  66. TITLE:=Python $(PYTHON_VERSION) light installation
  67. DEPENDS:=+python3-base +libffi +libbz2 +PYTHON3_BLUETOOTH_SUPPORT:bluez-libs +libuuid
  68. endef
  69. define Package/python3-light/config
  70. source "$(SOURCE)/Config-python3-light.in"
  71. endef
  72. define Package/python3-light/description
  73. This package is essentially the python3-base package plus
  74. a few of the rarely used (and big) libraries stripped out
  75. into separate packages.
  76. endef
  77. PYTHON3_LIB_FILES_DEL:=
  78. PYTHON3_PACKAGES:=
  79. PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
  80. PYTHON3_PACKAGES_DEPENDS:=
  81. define Py3BasePackage
  82. PYTHON3_PACKAGES+=$(1)
  83. ifeq ($(3),)
  84. PYTHON3_PACKAGES_DEPENDS+=$(1)
  85. endif
  86. PYTHON3_LIB_FILES_DEL+=$(2)
  87. define Py3Package/$(1)/filespec
  88. ifneq ($(2),)
  89. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  90. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  91. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  92. endif
  93. endef
  94. Py3Package/$(1)/install?=:
  95. endef
  96. include ./files/python3-package-*.mk
  97. define Package/python3
  98. $(call Package/python3/Default)
  99. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  100. endef
  101. define Package/python3/description
  102. This package contains the (almost) full Python install.
  103. It's python3-light + all other packages.
  104. endef
  105. MAKE_FLAGS+=\
  106. CROSS_COMPILE=yes \
  107. LD="$(TARGET_CC)"
  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. 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)-py2.py3-none-any.whl
  158. $(call PatchDir,$(PKG_BUILD_DIR)/install-setuptools/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-setuptools,)
  159. endef
  160. endif # CONFIG_PACKAGE_python3-setuptools
  161. ifdef CONFIG_PACKAGE_python3-pip
  162. define Build/Compile/python3-pip
  163. $(HOST_PYTHON3_PIP) \
  164. --disable-pip-version-check \
  165. --cache-dir "$(DL_DIR)/pip-cache" \
  166. install \
  167. --ignore-installed \
  168. --root=$(PKG_BUILD_DIR)/install-pip \
  169. --prefix=/usr \
  170. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py2.py3-none-any.whl
  171. $(call PatchDir,$(PKG_BUILD_DIR)/install-pip/usr/lib/python$(PYTHON3_VERSION)/site-packages,./patches-pip,)
  172. endef
  173. endif # CONFIG_PACKAGE_python3-pip
  174. define Build/Compile
  175. $(call Build/Compile/Default)
  176. # Use host pip to install python-setuptools
  177. $(call Build/Compile/python3-setuptools)
  178. $(call Build/Compile/python3-pip)
  179. endef
  180. define Build/InstallDev
  181. $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib $(1)/usr/lib/pkgconfig
  182. $(INSTALL_DIR) $(2)/bin
  183. $(CP) \
  184. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  185. $(1)/usr/include/
  186. $(CP) \
  187. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION) \
  188. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  189. $(1)/usr/lib/
  190. $(CP) \
  191. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python*.pc \
  192. $(1)/usr/lib/pkgconfig
  193. $(INSTALL_BIN) \
  194. $(PKG_INSTALL_DIR)/usr/bin/python$(PYTHON_VERSION)-config \
  195. $(2)/bin/
  196. $(SED) \
  197. 's|^prefix_real=.*$$$$|prefix_real="$(PYTHON3_DIR)"|' \
  198. $(2)/bin/python$(PYTHON_VERSION)-config
  199. endef
  200. PYTHON3_BASE_LIB_FILES:= \
  201. /usr/lib/python$(PYTHON_VERSION)/encodings \
  202. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  203. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  204. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  205. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  206. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  207. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  208. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  209. /usr/lib/python$(PYTHON_VERSION)/io.py \
  210. /usr/lib/python$(PYTHON_VERSION)/os.py \
  211. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  212. /usr/lib/python$(PYTHON_VERSION)/site.py \
  213. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  214. /usr/lib/python$(PYTHON_VERSION)/stat.py
  215. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  216. define Py3Package/python3-base/filespec
  217. +|/usr/bin/python$(PYTHON_VERSION)
  218. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  219. endef
  220. define Py3Package/python3-light/filespec
  221. +|/usr/lib/python$(PYTHON_VERSION)
  222. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  223. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  224. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  225. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  226. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  227. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  228. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  229. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  230. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  231. -|/usr/lib/python$(PYTHON_VERSION)/test
  232. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  233. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  234. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  235. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  236. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  237. endef
  238. define Py3Package/python3-base/install
  239. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  240. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  241. $(INSTALL_DIR) $(1)/usr/bin
  242. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  243. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  244. endef
  245. Py3Package/python3-light/install:=:
  246. Py3Package/python3/install:=:
  247. define Py3Package/python3/filespec
  248. -|$(PYTHON3_PKG_DIR)
  249. endef
  250. HOST_LDFLAGS += \
  251. -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib
  252. ifeq ($(HOST_OS),Linux)
  253. HOST_LDFLAGS += \
  254. -Wl,--no-as-needed -lrt
  255. endif
  256. ifeq ($(HOST_OS),Darwin)
  257. HOST_CONFIGURE_VARS += \
  258. ac_cv_header_libintl_h=no
  259. endif
  260. HOST_CONFIGURE_ARGS+= \
  261. --without-cxx-main \
  262. --without-pymalloc \
  263. --with-threads \
  264. --prefix=$(HOST_PYTHON3_DIR) \
  265. --exec-prefix=$(HOST_PYTHON3_DIR) \
  266. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  267. --with-ensurepip=upgrade \
  268. CONFIG_SITE=
  269. define Host/Configure
  270. $(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
  271. $(call Host/Configure/Default)
  272. endef
  273. define Host/Compile
  274. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python
  275. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  276. endef
  277. define Host/Install
  278. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  279. rm -rf \
  280. $(HOST_PYTHON3_PKG_DIR)/easy_install.py \
  281. $(HOST_PYTHON3_PKG_DIR)/pkg_resources \
  282. $(HOST_PYTHON3_PKG_DIR)/setuptools \
  283. $(HOST_PYTHON3_PKG_DIR)/setuptools-* \
  284. $(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
  285. $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
  286. )
  287. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  288. rm -rf \
  289. $(HOST_PYTHON3_PKG_DIR)/pip \
  290. $(HOST_PYTHON3_PKG_DIR)/pip-* \
  291. $(HOST_PYTHON3_PKG_DIR)/.pip-patched* \
  292. $(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
  293. )
  294. $(MAKE) -C $(HOST_BUILD_DIR) install
  295. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
  296. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-setuptools,)
  297. touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
  298. )
  299. $(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
  300. $(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-pip,)
  301. touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)
  302. )
  303. endef
  304. $(eval $(call HostBuild))
  305. $(foreach package, $(PYTHON3_PACKAGES), \
  306. $(eval $(call Py3Package,$(package))) \
  307. $(eval $(call BuildPackage,$(package))) \
  308. $(eval $(call BuildPackage,$(package)-src)) \
  309. )
  310. $(eval $(call Py3Package,python3-base))
  311. $(eval $(call Py3Package,python3-light))
  312. $(eval $(call Py3Package,python3))
  313. $(eval $(call BuildPackage,python3-base))
  314. $(eval $(call BuildPackage,python3-light))
  315. $(eval $(call BuildPackage,python3))
  316. $(eval $(call BuildPackage,python3-base-src))
  317. $(eval $(call BuildPackage,python3-light-src))