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.

256 lines
7.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 ./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:=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. 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. PGEN=pgen3
  87. ifeq ($(ARCH),i386)
  88. MAKE_FLAGS+=PYTHON_DECIMAL_WITH_MACHINE=ansi32
  89. endif
  90. EXTRA_CFLAGS+= \
  91. -DNDEBUG -fno-inline
  92. EXTRA_LDFLAGS+= \
  93. -L$(PKG_BUILD_DIR)
  94. ENABLE_IPV6:=
  95. ifeq ($(CONFIG_IPV6),y)
  96. ENABLE_IPV6 += --enable-ipv6
  97. endif
  98. CONFIGURE_ARGS+= \
  99. --sysconfdir=/etc \
  100. --enable-shared \
  101. --without-cxx-main \
  102. --with-threads \
  103. --with-system-ffi="$(STAGING_DIR)/usr" \
  104. --without-pymalloc \
  105. --without-ensurepip \
  106. $(ENABLE_IPV6) \
  107. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  108. OPT="$(TARGET_CFLAGS)"
  109. define Build/Prepare
  110. $(call Build/Prepare/Default)
  111. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  112. endef
  113. define Build/InstallDev
  114. $(INSTALL_DIR) $(STAGING_DIR)/mk/
  115. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/
  116. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  117. $(INSTALL_DATA) ./files/python3-package.mk $(STAGING_DIR)/mk/
  118. $(CP) \
  119. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  120. $(1)/usr/include/
  121. $(CP) \
  122. $(HOST_BUILD_PREFIX)/lib/python$(PYTHON_VERSION) \
  123. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  124. $(1)/usr/lib/
  125. $(CP) \
  126. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config-$(PYTHON_VERSION) \
  127. $(1)/usr/lib/python$(PYTHON_VERSION)/
  128. endef
  129. PYTHON3_BASE_LIB_FILES:= \
  130. /usr/lib/python$(PYTHON_VERSION)/encodings \
  131. /usr/lib/python$(PYTHON_VERSION)/_collections_abc.py \
  132. /usr/lib/python$(PYTHON_VERSION)/_sitebuiltins.py \
  133. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  134. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  135. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  136. /usr/lib/python$(PYTHON_VERSION)/codecs.py \
  137. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  138. /usr/lib/python$(PYTHON_VERSION)/io.py \
  139. /usr/lib/python$(PYTHON_VERSION)/os.py \
  140. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  141. /usr/lib/python$(PYTHON_VERSION)/site.py \
  142. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  143. /usr/lib/python$(PYTHON_VERSION)/stat.py
  144. PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
  145. define Py3Package/python3-base/filespec
  146. +|/usr/bin/python$(PYTHON_VERSION)
  147. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_BASE_LIB_FILES),+|$(lib_file)))
  148. endef
  149. define Py3Package/python3-light/filespec
  150. +|/usr/lib/python$(PYTHON_VERSION)
  151. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  152. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  153. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  154. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  155. -|/usr/lib/python$(PYTHON_VERSION)/tkinter
  156. -|/usr/lib/python$(PYTHON_VERSION)/turtledemo
  157. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_test*.so
  158. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline*.so
  159. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  160. -|/usr/lib/python$(PYTHON_VERSION)/test
  161. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  162. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  163. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  164. -|/usr/lib/python$(PYTHON_VERSION)/_osx_support.py
  165. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON3_LIB_FILES_DEL),-|$(lib_file)))
  166. endef
  167. define Py3Package/python3-base/install
  168. # Adding the lib-dynload folder (even just empty) suppresses 2 warnings when starting Python
  169. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/lib-dynload/
  170. $(INSTALL_DIR) $(1)/usr/bin
  171. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python3
  172. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  173. endef
  174. define Py3Package/python3/filespec
  175. -|$(PYTHON3_PKG_DIR)
  176. endef
  177. HOST_CFLAGS+= \
  178. -I/usr/include/ncursesw \
  179. -I/usr/include/ncurses
  180. HOST_CONFIGURE_ARGS+= \
  181. --without-cxx-main \
  182. --without-pymalloc \
  183. --with-threads \
  184. --prefix=$(HOST_BUILD_PREFIX) \
  185. --exec-prefix=$(HOST_BUILD_PREFIX) \
  186. --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
  187. --localstatedir=$(HOST_BUILD_PREFIX)/var \
  188. --sbindir=$(HOST_BUILD_PREFIX)/bin \
  189. --with-system-expat=$(HOST_BUILD_PREFIX) \
  190. --with-system-ffi=$(HOST_BUILD_PREFIX) \
  191. --with-ensurepip=upgrade \
  192. CONFIG_SITE= \
  193. CFLAGS="$(HOST_CFLAGS)"
  194. define Host/Compile
  195. +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) python Parser/pgen
  196. +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) sharedmods
  197. endef
  198. define Host/Install
  199. $(MAKE) -C $(HOST_BUILD_DIR) install
  200. $(INSTALL_DIR) $(HOST_BUILD_PREFIX)/bin/
  201. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_BUILD_PREFIX)/bin/pgen3
  202. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Programs/_freeze_importlib $(HOST_BUILD_PREFIX)/bin/_freeze_importlib
  203. endef
  204. $(eval $(call HostBuild))
  205. $(foreach package, $(PYTHON3_PACKAGES), \
  206. $(eval $(call Py3Package,$(package))) \
  207. $(eval $(call BuildPackage,$(package))) \
  208. )
  209. $(eval $(call Py3Package,python3-base))
  210. $(eval $(call Py3Package,python3-light))
  211. $(eval $(call Py3Package,python3))
  212. $(eval $(call BuildPackage,python3-base))
  213. $(eval $(call BuildPackage,python3-light))
  214. $(eval $(call BuildPackage,python3))