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.

316 lines
9.5 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 ./files/python3-version.mk
  10. PYTHON_VERSION:=$(PYTHON3_VERSION)
  11. PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO)
  12. PKG_NAME:=python3
  13. # XXX: reset PKG_RELEASE to 1 only if Python's pip & setuptools versions have also bumped;
  14. # otherwise, keep bumping PKG_RELEASE
  15. PKG_RELEASE:=10
  16. PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
  17. PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
  18. PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
  19. PKG_HASH:=cda7d967c9a4bfa52337cdf551bcc5cff026b6ac50a8834e568ce4a794ca81da
  20. PKG_LICENSE:=PSF
  21. PKG_LICENSE_FILES:=LICENSE Modules/_ctypes/libffi_msvc/LICENSE Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi/LICENSE Modules/_ctypes/libffi_osx/LICENSE Tools/pybench/LICENSE
  22. # This file provides the necsessary host build variables
  23. include ./files/python3-host.mk
  24. # For Py3Package
  25. include ./files/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_PACKAGE_bluez-libs
  35. PKG_BUILD_DEPENDS:=python3/host PACKAGE_bluez-libs:bluez-libs
  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. MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
  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 +PACKAGE_bluez-libs:bluez-libs
  68. endef
  69. define Package/python3-light/description
  70. This package is essentially the python3-base package plus
  71. a few of the rarely used (and big) libraries stripped out
  72. into separate packages.
  73. endef
  74. PYTHON3_LIB_FILES_DEL:=
  75. PYTHON3_PACKAGES:=
  76. PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
  77. PYTHON3_PACKAGES_DEPENDS:=
  78. define Py3BasePackage
  79. PYTHON3_PACKAGES+=$(1)
  80. ifeq ($(3),)
  81. PYTHON3_PACKAGES_DEPENDS+=$(1)
  82. endif
  83. PYTHON3_LIB_FILES_DEL+=$(2)
  84. define Py3Package/$(1)/filespec
  85. ifneq ($(2),)
  86. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  87. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  88. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  89. endif
  90. endef
  91. endef
  92. include ./files/python3-package-*.mk
  93. define Package/python3
  94. $(call Package/python3/Default)
  95. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  96. endef
  97. define Package/python3/description
  98. This package contains the (almost) full Python install.
  99. It's python3-light + all other packages.
  100. endef
  101. MAKE_FLAGS+=\
  102. CROSS_COMPILE=yes \
  103. LD="$(TARGET_CC)" \
  104. PGEN=pgen3
  105. EXTRA_CFLAGS+= \
  106. -DNDEBUG -fno-inline
  107. EXTRA_LDFLAGS+= \
  108. -L$(PKG_BUILD_DIR)
  109. ENABLE_IPV6:=
  110. ifeq ($(CONFIG_IPV6),y)
  111. ENABLE_IPV6 += --enable-ipv6
  112. endif
  113. PYTHON_FOR_BUILD:= \
  114. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  115. _PYTHON_HOST_PLATFORM=linux2 \
  116. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  117. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  118. $(HOST_PYTHON3_BIN)
  119. CONFIGURE_ARGS+= \
  120. --sysconfdir=/etc \
  121. --enable-shared \
  122. --without-cxx-main \
  123. --with-threads \
  124. --with-system-ffi \
  125. --with-ensurepip=no \
  126. --without-pymalloc \
  127. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  128. $(ENABLE_IPV6) \
  129. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  130. OPT="$(TARGET_CFLAGS)"
  131. define Build/Prepare
  132. $(call Build/Prepare/Default)
  133. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  134. endef
  135. ifdef CONFIG_PACKAGE_python3-setuptools
  136. define Build/Compile/python3-setuptools
  137. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  138. --ignore-installed \
  139. --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
  140. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
  141. endef
  142. endif # CONFIG_PACKAGE_python3-setuptools
  143. ifdef CONFIG_PACKAGE_python3-pip
  144. define Build/Compile/python3-pip
  145. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  146. --ignore-installed \
  147. --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
  148. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
  149. endef
  150. endif # CONFIG_PACKAGE_python3-pip
  151. define Build/Compile
  152. $(call Build/Compile/Default)
  153. # Use host pip to install python-setuptools
  154. $(call Build/Compile/python3-setuptools)
  155. $(call Build/Compile/python3-pip)
  156. endef
  157. define Build/InstallMkFiles
  158. $(INSTALL_DIR) $(STAGING_DIR)/mk/
  159. $(INSTALL_DATA) \
  160. ./files/python3-package.mk \
  161. ./files/python3-host.mk \
  162. ./files/python3-version.mk \
  163. ./files/python3-package-install.sh \
  164. $(STAGING_DIR)/mk/
  165. endef
  166. define Build/InstallDev
  167. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
  168. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  169. $(CP) \
  170. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  171. $(1)/usr/include/
  172. $(CP) \
  173. $(HOST_PYTHON3_LIB_DIR) \
  174. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  175. $(1)/usr/lib/
  176. $(CP) \
  177. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
  178. $(1)/usr/lib/python$(PYTHON_VERSION)/
  179. $(call Build/InstallMkFiles)
  180. endef
  181. PYTHON3_BASE_LIB_FILES:= \
  182. /usr/lib/python$(PYTHON_VERSION)/encodings \
  183. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  184. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  185. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  186. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  187. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  188. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  189. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  190. /usr/lib/python$(PYTHON_VERSION)/io.py \
  191. /usr/lib/python$(PYTHON_VERSION)/os.py \
  192. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  193. /usr/lib/python$(PYTHON_VERSION)/site.py \
  194. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  195. /usr/lib/python$(PYTHON_VERSION)/stat.py
  196. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  197. define Py3Package/python3-base/filespec
  198. +|/usr/bin/python$(PYTHON_VERSION)
  199. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  200. endef
  201. define Py3Package/python3-light/filespec
  202. +|/usr/lib/python$(PYTHON_VERSION)
  203. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  204. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  205. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  206. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  207. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  208. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  209. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  210. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  211. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  212. -|/usr/lib/python$(PYTHON_VERSION)/test
  213. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  214. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  215. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  216. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  217. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  218. endef
  219. define Py3Package/python3-base/install
  220. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  221. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  222. $(INSTALL_DIR) $(1)/usr/bin
  223. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  224. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  225. endef
  226. define Py3Package/python3/filespec
  227. -|$(PYTHON3_PKG_DIR)
  228. endef
  229. HOST_LDFLAGS += \
  230. -Wl,--no-as-needed -lrt \
  231. $$$$(pkg-config --static --libs libcrypto libssl)
  232. HOST_CONFIGURE_ARGS+= \
  233. --without-cxx-main \
  234. --without-pymalloc \
  235. --with-threads \
  236. --prefix=$(HOST_PYTHON3_DIR) \
  237. --exec-prefix=$(HOST_PYTHON3_DIR) \
  238. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  239. --with-system-ffi=no \
  240. --with-ensurepip=install \
  241. CONFIG_SITE=
  242. define Host/Compile
  243. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
  244. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  245. endef
  246. define Host/Install
  247. $(call Build/InstallMkFiles)
  248. $(MAKE) -C $(HOST_BUILD_DIR) install
  249. $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
  250. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
  251. endef
  252. $(eval $(call HostBuild))
  253. $(foreach package, $(PYTHON3_PACKAGES), \
  254. $(eval $(call Py3Package,$(package))) \
  255. $(eval $(call BuildPackage,$(package))) \
  256. $(eval $(call BuildPackage,$(package)-src)) \
  257. )
  258. $(eval $(call Py3Package,python3-base))
  259. $(eval $(call Py3Package,python3-light))
  260. $(eval $(call Py3Package,python3))
  261. $(eval $(call BuildPackage,python3-base))
  262. $(eval $(call BuildPackage,python3-light))
  263. $(eval $(call BuildPackage,python3))
  264. $(eval $(call BuildPackage,python3-base-src))
  265. $(eval $(call BuildPackage,python3-light-src))
  266. $(eval $(call BuildPackage,python3-src))