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.

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