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.

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