1
0

Makefile 8.1 KB

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