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.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 ../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_HASH:=d83fe8ce51b1bb48bbcf0550fd265b9a75cdfdfa93f916f9e700aef8444bf1bb
  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. PKG_MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>, Jeffery To <jeffery.to@gmail.com>
  21. # This file provides the necsessary host build variables
  22. include ../python3-host.mk
  23. # For Py3Package
  24. include ../python3-package.mk
  25. PKG_FIXUP:=autoreconf
  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:= \
  32. CONFIG_PACKAGE_python3-setuptools CONFIG_PACKAGE_python3-pip \
  33. CONFIG_PYTHON3_BLUETOOTH_SUPPORT
  34. PKG_BUILD_DEPENDS:=python3/host
  35. HOST_BUILD_DEPENDS:=bzip2/host expat/host libffi/host
  36. include $(INCLUDE_DIR)/host-build.mk
  37. include $(INCLUDE_DIR)/package.mk
  38. define Package/python3/Default
  39. SUBMENU:=Python
  40. SECTION:=lang
  41. CATEGORY:=Languages
  42. TITLE:=Python $(PYTHON_VERSION) programming language
  43. URL:=https://www.python.org/
  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 +libuuid
  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. Py3Package/$(1)/install?=:
  93. endef
  94. include ./files/python3-package-*.mk
  95. define Package/python3
  96. $(call Package/python3/Default)
  97. DEPENDS:=+python3-light $(foreach package,$(PYTHON3_PACKAGES_DEPENDS),+$(package))
  98. endef
  99. define Package/python3/description
  100. This package contains the (almost) full Python install.
  101. It's python3-light + all other packages.
  102. endef
  103. MAKE_FLAGS+=\
  104. CROSS_COMPILE=yes \
  105. LD="$(TARGET_CC)" \
  106. PGEN=pgen3
  107. EXTRA_CFLAGS+= \
  108. -DNDEBUG -fno-inline
  109. EXTRA_LDFLAGS+= \
  110. -L$(PKG_BUILD_DIR)
  111. ENABLE_IPV6:=
  112. ifeq ($(CONFIG_IPV6),y)
  113. ENABLE_IPV6 += --enable-ipv6
  114. endif
  115. PYTHON_FOR_BUILD:= \
  116. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  117. _PYTHON_HOST_PLATFORM=linux2 \
  118. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  119. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  120. $(HOST_PYTHON3_BIN)
  121. DISABLE_BLUETOOTH:= \
  122. ac_cv_header_bluetooth_bluetooth_h=no \
  123. ac_cv_header_bluetooth_h=no
  124. CONFIGURE_ARGS+= \
  125. --sysconfdir=/etc \
  126. --enable-shared \
  127. --without-cxx-main \
  128. --with-threads \
  129. --with-system-ffi \
  130. --with-ensurepip=no \
  131. --without-pymalloc \
  132. $(if $(CONFIG_PYTHON3_BLUETOOTH_SUPPORT),,$(DISABLE_BLUETOOTH)) \
  133. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  134. $(ENABLE_IPV6) \
  135. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  136. OPT="$(TARGET_CFLAGS)"
  137. define Build/Prepare
  138. $(call Build/Prepare/Default)
  139. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  140. endef
  141. ifdef CONFIG_PACKAGE_python3-setuptools
  142. define Build/Compile/python3-setuptools
  143. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  144. --ignore-installed \
  145. --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
  146. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py2.py3-none-any.whl
  147. endef
  148. endif # CONFIG_PACKAGE_python3-setuptools
  149. ifdef CONFIG_PACKAGE_python3-pip
  150. define Build/Compile/python3-pip
  151. $(STAGING_DIR_HOSTPKG)/bin/pip3 install \
  152. --ignore-installed \
  153. --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
  154. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py2.py3-none-any.whl
  155. endef
  156. endif # CONFIG_PACKAGE_python3-pip
  157. define Build/Compile
  158. $(call Build/Compile/Default)
  159. # Use host pip to install python-setuptools
  160. $(call Build/Compile/python3-setuptools)
  161. $(call Build/Compile/python3-pip)
  162. endef
  163. define Build/InstallDev
  164. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
  165. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  166. $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
  167. $(CP) \
  168. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  169. $(1)/usr/include/
  170. $(CP) \
  171. $(HOST_PYTHON3_LIB_DIR) \
  172. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  173. $(1)/usr/lib/
  174. $(CP) \
  175. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python3.pc \
  176. $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/python-$(PYTHON3_VERSION).pc \
  177. $(1)/usr/lib/pkgconfig
  178. $(CP) \
  179. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
  180. $(1)/usr/lib/python$(PYTHON_VERSION)/
  181. endef
  182. PYTHON3_BASE_LIB_FILES:= \
  183. /usr/lib/python$(PYTHON_VERSION)/encodings \
  184. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  185. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  186. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  187. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  188. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  189. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  190. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  191. /usr/lib/python$(PYTHON_VERSION)/io.py \
  192. /usr/lib/python$(PYTHON_VERSION)/os.py \
  193. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  194. /usr/lib/python$(PYTHON_VERSION)/site.py \
  195. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  196. /usr/lib/python$(PYTHON_VERSION)/stat.py
  197. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  198. define Py3Package/python3-base/filespec
  199. +|/usr/bin/python$(PYTHON_VERSION)
  200. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  201. endef
  202. define Py3Package/python3-light/filespec
  203. +|/usr/lib/python$(PYTHON_VERSION)
  204. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  205. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  206. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  207. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  208. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  209. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  210. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  211. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  212. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  213. -|/usr/lib/python$(PYTHON_VERSION)/test
  214. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  215. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  216. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  217. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  218. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  219. endef
  220. define Py3Package/python3-base/install
  221. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  222. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  223. $(INSTALL_DIR) $(1)/usr/bin
  224. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  225. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  226. endef
  227. Py3Package/python3-light/install:=:
  228. Py3Package/python3/install:=:
  229. define Py3Package/python3/filespec
  230. -|$(PYTHON3_PKG_DIR)
  231. endef
  232. HOST_LDFLAGS += \
  233. $$$$(pkg-config --static --libs libcrypto libssl) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib
  234. ifeq ($(HOST_OS),Linux)
  235. HOST_LDFLAGS += \
  236. -Wl,--no-as-needed -lrt
  237. endif
  238. HOST_CONFIGURE_ARGS+= \
  239. --without-cxx-main \
  240. --without-pymalloc \
  241. --with-threads \
  242. --prefix=$(HOST_PYTHON3_DIR) \
  243. --exec-prefix=$(HOST_PYTHON3_DIR) \
  244. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  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. $(MAKE) -C $(HOST_BUILD_DIR) install
  253. $(INSTALL_DIR) $(HOST_PYTHON3_DIR)/bin/
  254. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON3_DIR)/bin/pgen3
  255. endef
  256. $(eval $(call HostBuild))
  257. $(foreach package, $(PYTHON3_PACKAGES), \
  258. $(eval $(call Py3Package,$(package))) \
  259. $(eval $(call BuildPackage,$(package))) \
  260. $(eval $(call BuildPackage,$(package)-src)) \
  261. )
  262. $(eval $(call Py3Package,python3-base))
  263. $(eval $(call Py3Package,python3-light))
  264. $(eval $(call Py3Package,python3))
  265. $(eval $(call BuildPackage,python3-base))
  266. $(eval $(call BuildPackage,python3-light))
  267. $(eval $(call BuildPackage,python3))
  268. $(eval $(call BuildPackage,python3-base-src))
  269. $(eval $(call BuildPackage,python3-light-src))