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.

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