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.

305 lines
9.2 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:=1
  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:=692b4fc3a2ba0d54d1495d4ead5b0b5c
  18. PKG_HASH:=a01810ddfcec216bcdb357a84bfaafdfaa0ca42bbdaa4cb7ff74f5a9961e4041
  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. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  83. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  84. endif
  85. endef
  86. endef
  87. include ./files/python3-package-*.mk
  88. define Package/python3
  89. $(call Package/python3/Default)
  90. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  91. endef
  92. define Package/python3/description
  93. This package contains the (almost) full Python install.
  94. It's python3-light + all other packages.
  95. endef
  96. MAKE_FLAGS+=\
  97. CROSS_COMPILE=yes \
  98. LD="$(TARGET_CC)" \
  99. PGEN=pgen3
  100. EXTRA_CFLAGS+= \
  101. -DNDEBUG -fno-inline
  102. EXTRA_LDFLAGS+= \
  103. -L$(PKG_BUILD_DIR)
  104. ENABLE_IPV6:=
  105. ifeq ($(CONFIG_IPV6),y)
  106. ENABLE_IPV6 += --enable-ipv6
  107. endif
  108. PYTHON_FOR_BUILD:= \
  109. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  110. _PYTHON_HOST_PLATFORM=linux2 \
  111. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  112. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  113. $(HOST_PYTHON3_BIN)
  114. CONFIGURE_ARGS+= \
  115. --sysconfdir=/etc \
  116. --enable-shared \
  117. --without-cxx-main \
  118. --with-threads \
  119. --with-system-ffi \
  120. --with-ensurepip=no \
  121. --without-pymalloc \
  122. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  123. $(ENABLE_IPV6) \
  124. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  125. OPT="$(TARGET_CFLAGS)"
  126. define Build/Prepare
  127. $(call Build/Prepare/Default)
  128. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  129. endef
  130. ifdef CONFIG_PACKAGE_python3-setuptools
  131. define Build/Compile/python3-setuptools
  132. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  133. --ignore-installed \
  134. --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
  135. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
  136. endef
  137. endif # CONFIG_PACKAGE_python3-setuptools
  138. ifdef CONFIG_PACKAGE_python3-pip
  139. define Build/Compile/python3-pip
  140. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  141. --ignore-installed \
  142. --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
  143. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
  144. endef
  145. endif # CONFIG_PACKAGE_python3-pip
  146. define Build/Compile
  147. $(call Build/Compile/Default)
  148. # Use host pip to install python-setuptools
  149. $(call Build/Compile/python3-setuptools)
  150. $(call Build/Compile/python3-pip)
  151. endef
  152. define Build/InstallDev
  153. $(INSTALL_DIR) $(STAGING_DIR)/mk/
  154. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
  155. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  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. $(CP) \
  163. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  164. $(1)/usr/include/
  165. $(CP) \
  166. $(HOST_PYTHON3_LIB_DIR) \
  167. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  168. $(1)/usr/lib/
  169. $(CP) \
  170. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
  171. $(1)/usr/lib/python$(PYTHON_VERSION)/
  172. endef
  173. PYTHON3_BASE_LIB_FILES:= \
  174. /usr/lib/python$(PYTHON_VERSION)/encodings \
  175. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  176. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  177. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  178. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  179. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  180. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  181. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  182. /usr/lib/python$(PYTHON_VERSION)/io.py \
  183. /usr/lib/python$(PYTHON_VERSION)/os.py \
  184. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  185. /usr/lib/python$(PYTHON_VERSION)/site.py \
  186. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  187. /usr/lib/python$(PYTHON_VERSION)/stat.py
  188. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  189. define Py3Package/python3-base/filespec
  190. +|/usr/bin/python$(PYTHON_VERSION)
  191. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  192. endef
  193. define Py3Package/python3-light/filespec
  194. +|/usr/lib/python$(PYTHON_VERSION)
  195. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  196. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  197. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  198. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  199. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  200. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  201. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  202. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  203. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  204. -|/usr/lib/python$(PYTHON_VERSION)/test
  205. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  206. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  207. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  208. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  209. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  210. endef
  211. define Py3Package/python3-base/install
  212. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  213. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  214. $(INSTALL_DIR) $(1)/usr/bin
  215. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  216. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  217. endef
  218. define Py3Package/python3/filespec
  219. -|$(PYTHON3_PKG_DIR)
  220. endef
  221. HOST_LDFLAGS += \
  222. $$$$(pkg-config --static --libs libcrypto libssl)
  223. HOST_CONFIGURE_ARGS+= \
  224. --without-cxx-main \
  225. --without-pymalloc \
  226. --with-threads \
  227. --prefix=$(HOST_PYTHON3_DIR) \
  228. --exec-prefix=$(HOST_PYTHON3_DIR) \
  229. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  230. --with-system-ffi=no \
  231. --with-ensurepip=install \
  232. CONFIG_SITE=
  233. define Host/Compile
  234. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
  235. +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  236. endef
  237. define Host/Install
  238. $(MAKE) -C $(HOST_BUILD_DIR) install
  239. $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
  240. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
  241. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Programs/_freeze_importlib $(HOST_PYTHON3_DIR)/bin/_freeze_importlib
  242. endef
  243. $(eval $(call HostBuild))
  244. $(foreach package, $(PYTHON3_PACKAGES), \
  245. $(eval $(call Py3Package,$(package))) \
  246. $(eval $(call BuildPackage,$(package))) \
  247. $(eval $(call BuildPackage,$(package)-src)) \
  248. )
  249. $(eval $(call Py3Package,python3-base))
  250. $(eval $(call Py3Package,python3-light))
  251. $(eval $(call Py3Package,python3))
  252. $(eval $(call BuildPackage,python3-base))
  253. $(eval $(call BuildPackage,python3-light))
  254. $(eval $(call BuildPackage,python3))
  255. $(eval $(call BuildPackage,python3-base-src))
  256. $(eval $(call BuildPackage,python3-light-src))
  257. $(eval $(call BuildPackage,python3-src))