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.

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