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.

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