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.

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