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.6 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:=5
  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/InstallDev
  155. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
  156. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  157. $(CP) \
  158. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  159. $(1)/usr/include/
  160. $(CP) \
  161. $(HOST_PYTHON3_LIB_DIR) \
  162. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  163. $(1)/usr/lib/
  164. $(CP) \
  165. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
  166. $(1)/usr/lib/python$(PYTHON_VERSION)/
  167. endef
  168. PYTHON3_BASE_LIB_FILES:= \
  169. /usr/lib/python$(PYTHON_VERSION)/encodings \
  170. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  171. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  172. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  173. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  174. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  175. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  176. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  177. /usr/lib/python$(PYTHON_VERSION)/io.py \
  178. /usr/lib/python$(PYTHON_VERSION)/os.py \
  179. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  180. /usr/lib/python$(PYTHON_VERSION)/site.py \
  181. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  182. /usr/lib/python$(PYTHON_VERSION)/stat.py
  183. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  184. define Py3Package/python3-base/filespec
  185. +|/usr/bin/python$(PYTHON_VERSION)
  186. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  187. endef
  188. define Py3Package/python3-light/filespec
  189. +|/usr/lib/python$(PYTHON_VERSION)
  190. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  191. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  192. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  193. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  194. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  195. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  196. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  197. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  198. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  199. -|/usr/lib/python$(PYTHON_VERSION)/test
  200. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  201. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  202. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  203. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  204. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  205. endef
  206. define Py3Package/python3-base/install
  207. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  208. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  209. $(INSTALL_DIR) $(1)/usr/bin
  210. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  211. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  212. endef
  213. define Py3Package/python3/filespec
  214. -|$(PYTHON3_PKG_DIR)
  215. endef
  216. HOST_LDFLAGS += \
  217. -Wl,--no-as-needed -lrt \
  218. $$$$(pkg-config --static --libs libcrypto libssl)
  219. HOST_CONFIGURE_ARGS+= \
  220. --without-cxx-main \
  221. --without-pymalloc \
  222. --with-threads \
  223. --prefix=$(HOST_PYTHON3_DIR) \
  224. --exec-prefix=$(HOST_PYTHON3_DIR) \
  225. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  226. --with-system-ffi=no \
  227. --with-ensurepip=install \
  228. CONFIG_SITE=
  229. define Host/Compile
  230. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
  231. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  232. endef
  233. define Host/Install
  234. $(MAKE) -C $(HOST_BUILD_DIR) install
  235. $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/ $(STAGING_DIR)/mk/
  236. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
  237. # Install these mk files in the Host/Install phase ;
  238. # The Build/InstallDev rule is activated only for target builds.
  239. # But if someone needs only the host Python, then
  240. # these files need to be installed in this phase, and not Build/InstallDev
  241. $(INSTALL_DATA) \
  242. ./files/python3-package.mk \
  243. ./files/python3-host.mk \
  244. ./files/python3-version.mk \
  245. ./files/python3-package-install.sh \
  246. $(STAGING_DIR)/mk/
  247. endef
  248. $(eval $(call HostBuild))
  249. $(foreach package, $(PYTHON3_PACKAGES), \
  250. $(eval $(call Py3Package,$(package))) \
  251. $(eval $(call BuildPackage,$(package))) \
  252. $(eval $(call BuildPackage,$(package)-src)) \
  253. )
  254. $(eval $(call Py3Package,python3-base))
  255. $(eval $(call Py3Package,python3-light))
  256. $(eval $(call Py3Package,python3))
  257. $(eval $(call BuildPackage,python3-base))
  258. $(eval $(call BuildPackage,python3-light))
  259. $(eval $(call BuildPackage,python3))
  260. $(eval $(call BuildPackage,python3-base-src))
  261. $(eval $(call BuildPackage,python3-light-src))
  262. $(eval $(call BuildPackage,python3-src))