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.

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