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.

312 lines
9.4 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:=6
  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:=9229773be41ed144370f47f0f626a1579931f5a390f1e8e3853174d52edd64a9
  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_INSTALL:=1
  27. PKG_BUILD_PARALLEL:=1
  28. HOST_BUILD_PARALLEL:=1
  29. PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
  30. HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
  31. PKG_CONFIG_DEPENDS:=CONFIG_PACKAGE_python3-setuptools CONFIG_PACKAGE_python3-pip
  32. PKG_BUILD_DEPENDS:=python3/host
  33. HOST_BUILD_DEPENDS:=bzip2/host expat/host libffi/host
  34. include $(INCLUDE_DIR)/host-build.mk
  35. include $(INCLUDE_DIR)/package.mk
  36. define Package/python3/Default
  37. SUBMENU:=Python
  38. SECTION:=lang
  39. CATEGORY:=Languages
  40. TITLE:=Python $(PYTHON_VERSION) programming language
  41. URL:=https://www.python.org/
  42. MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
  43. endef
  44. define Package/python3/Default/description
  45. Python is a dynamic object-oriented programming language that can be used
  46. for many kinds of software development. It offers strong support for
  47. integration with other languages and tools, comes with extensive standard
  48. libraries, and can be learned in a few days. Many Python programmers
  49. report substantial productivity gains and feel the language encourages
  50. the development of higher quality, more maintainable code.
  51. endef
  52. define Package/python3-base
  53. $(call Package/python3/Default)
  54. TITLE:=Python $(PYTHON_VERSION) interpreter
  55. DEPENDS:=+libpthread +zlib
  56. endef
  57. define Package/python3-base/description
  58. This package contains only the interpreter and the bare minimum
  59. for the interpreter to start.
  60. endef
  61. define Package/python3-light
  62. $(call Package/python3/Default)
  63. TITLE:=Python $(PYTHON_VERSION) light installation
  64. DEPENDS:=+python3-base +libffi +libbz2
  65. endef
  66. define Package/python3-light/description
  67. This package is essentially the python3-base package plus
  68. a few of the rarely used (and big) libraries stripped out
  69. into separate packages.
  70. endef
  71. PYTHON3_LIB_FILES_DEL:=
  72. PYTHON3_PACKAGES:=
  73. PYTHON3_SO_SUFFIX:=cpython-$(PYTHON3_VERSION_MAJOR)$(PYTHON3_VERSION_MINOR).so
  74. PYTHON3_PACKAGES_DEPENDS:=
  75. define Py3BasePackage
  76. PYTHON3_PACKAGES+=$(1)
  77. ifeq ($(3),)
  78. PYTHON3_PACKAGES_DEPENDS+=$(1)
  79. endif
  80. PYTHON3_LIB_FILES_DEL+=$(2)
  81. define Py3Package/$(1)/filespec
  82. ifneq ($(2),)
  83. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  84. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  85. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  86. endif
  87. endef
  88. endef
  89. include ./files/python3-package-*.mk
  90. define Package/python3
  91. $(call Package/python3/Default)
  92. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  93. endef
  94. define Package/python3/description
  95. This package contains the (almost) full Python install.
  96. It's python3-light + all other packages.
  97. endef
  98. MAKE_FLAGS+=\
  99. CROSS_COMPILE=yes \
  100. LD="$(TARGET_CC)" \
  101. PGEN=pgen3
  102. EXTRA_CFLAGS+= \
  103. -DNDEBUG -fno-inline
  104. EXTRA_LDFLAGS+= \
  105. -L$(PKG_BUILD_DIR)
  106. ENABLE_IPV6:=
  107. ifeq ($(CONFIG_IPV6),y)
  108. ENABLE_IPV6 += --enable-ipv6
  109. endif
  110. PYTHON_FOR_BUILD:= \
  111. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  112. _PYTHON_HOST_PLATFORM=linux2 \
  113. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  114. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  115. $(HOST_PYTHON3_BIN)
  116. CONFIGURE_ARGS+= \
  117. --sysconfdir=/etc \
  118. --enable-shared \
  119. --without-cxx-main \
  120. --with-threads \
  121. --with-system-ffi \
  122. --with-ensurepip=no \
  123. --without-pymalloc \
  124. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  125. $(ENABLE_IPV6) \
  126. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  127. OPT="$(TARGET_CFLAGS)"
  128. define Build/Prepare
  129. $(call Build/Prepare/Default)
  130. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  131. endef
  132. ifdef CONFIG_PACKAGE_python3-setuptools
  133. define Build/Compile/python3-setuptools
  134. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  135. --ignore-installed \
  136. --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
  137. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
  138. endef
  139. endif # CONFIG_PACKAGE_python3-setuptools
  140. ifdef CONFIG_PACKAGE_python3-pip
  141. define Build/Compile/python3-pip
  142. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  143. --ignore-installed \
  144. --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
  145. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
  146. endef
  147. endif # CONFIG_PACKAGE_python3-pip
  148. define Build/Compile
  149. $(call Build/Compile/Default)
  150. # Use host pip to install python-setuptools
  151. $(call Build/Compile/python3-setuptools)
  152. $(call Build/Compile/python3-pip)
  153. endef
  154. define Build/InstallMkFiles
  155. $(INSTALL_DIR) $(STAGING_DIR)/mk/
  156. $(INSTALL_DATA) \
  157. ./files/python3-package.mk \
  158. ./files/python3-host.mk \
  159. ./files/python3-version.mk \
  160. ./files/python3-package-install.sh \
  161. $(STAGING_DIR)/mk/
  162. endef
  163. define Build/InstallDev
  164. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
  165. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  166. $(CP) \
  167. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  168. $(1)/usr/include/
  169. $(CP) \
  170. $(HOST_PYTHON3_LIB_DIR) \
  171. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  172. $(1)/usr/lib/
  173. $(CP) \
  174. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
  175. $(1)/usr/lib/python$(PYTHON_VERSION)/
  176. $(call Build/InstallMkFiles)
  177. endef
  178. PYTHON3_BASE_LIB_FILES:= \
  179. /usr/lib/python$(PYTHON_VERSION)/encodings \
  180. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  181. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  182. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  183. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  184. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  185. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  186. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  187. /usr/lib/python$(PYTHON_VERSION)/io.py \
  188. /usr/lib/python$(PYTHON_VERSION)/os.py \
  189. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  190. /usr/lib/python$(PYTHON_VERSION)/site.py \
  191. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  192. /usr/lib/python$(PYTHON_VERSION)/stat.py
  193. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  194. define Py3Package/python3-base/filespec
  195. +|/usr/bin/python$(PYTHON_VERSION)
  196. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  197. endef
  198. define Py3Package/python3-light/filespec
  199. +|/usr/lib/python$(PYTHON_VERSION)
  200. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  201. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  202. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  203. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  204. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  205. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  206. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  207. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  208. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  209. -|/usr/lib/python$(PYTHON_VERSION)/test
  210. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  211. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  212. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  213. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  214. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  215. endef
  216. define Py3Package/python3-base/install
  217. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  218. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  219. $(INSTALL_DIR) $(1)/usr/bin
  220. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  221. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  222. endef
  223. define Py3Package/python3/filespec
  224. -|$(PYTHON3_PKG_DIR)
  225. endef
  226. HOST_LDFLAGS += \
  227. -Wl,--no-as-needed -lrt \
  228. $$$$(pkg-config --static --libs libcrypto libssl)
  229. HOST_CONFIGURE_ARGS+= \
  230. --without-cxx-main \
  231. --without-pymalloc \
  232. --with-threads \
  233. --prefix=$(HOST_PYTHON3_DIR) \
  234. --exec-prefix=$(HOST_PYTHON3_DIR) \
  235. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  236. --with-system-ffi=no \
  237. --with-ensurepip=install \
  238. CONFIG_SITE=
  239. define Host/Compile
  240. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
  241. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  242. endef
  243. define Host/Install
  244. $(call Build/InstallMkFiles)
  245. $(MAKE) -C $(HOST_BUILD_DIR) install
  246. $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
  247. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
  248. endef
  249. $(eval $(call HostBuild))
  250. $(foreach package, $(PYTHON3_PACKAGES), \
  251. $(eval $(call Py3Package,$(package))) \
  252. $(eval $(call BuildPackage,$(package))) \
  253. $(eval $(call BuildPackage,$(package)-src)) \
  254. )
  255. $(eval $(call Py3Package,python3-base))
  256. $(eval $(call Py3Package,python3-light))
  257. $(eval $(call Py3Package,python3))
  258. $(eval $(call BuildPackage,python3-base))
  259. $(eval $(call BuildPackage,python3-light))
  260. $(eval $(call BuildPackage,python3))
  261. $(eval $(call BuildPackage,python3-base-src))
  262. $(eval $(call BuildPackage,python3-light-src))
  263. $(eval $(call BuildPackage,python3-src))