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.

310 lines
9.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. # For PYTHON_VERSION
  9. include ./files/python-version.mk
  10. PKG_NAME:=python
  11. PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO)
  12. PKG_RELEASE:=4
  13. PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
  14. PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
  15. PKG_MD5SUM:=53b43534153bb2a0363f08bae8b9d990
  16. PKG_HASH:=35d543986882f78261f97787fd3e06274bfa6df29fac9b4a94f73930ff98f731
  17. PKG_LICENSE:=PSF
  18. 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
  19. # This file provides the necsessary host build variables
  20. include ./files/python-host.mk
  21. # For PyPackage
  22. include ./files/python-package.mk
  23. PKG_INSTALL:=1
  24. PKG_BUILD_PARALLEL:=1
  25. HOST_BUILD_PARALLEL:=1
  26. PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
  27. HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
  28. PKG_BUILD_DEPENDS:=python/host
  29. HOST_BUILD_DEPENDS:=bzip2/host expat/host
  30. include $(INCLUDE_DIR)/host-build.mk
  31. include $(INCLUDE_DIR)/package.mk
  32. define Package/python/Default
  33. SUBMENU:=Python
  34. SECTION:=lang
  35. CATEGORY:=Languages
  36. TITLE:=Python $(PYTHON_VERSION) programming language
  37. URL:=https://www.python.org/
  38. MAINTAINER:=Alexandru Ardelean <ardeleanalex@gmail.com>
  39. endef
  40. define Package/python/Default/description
  41. Python is a dynamic object-oriented programming language that can be used
  42. for many kinds of software development. It offers strong support for
  43. integration with other languages and tools, comes with extensive standard
  44. libraries, and can be learned in a few days. Many Python programmers
  45. report substantial productivity gains and feel the language encourages
  46. the development of higher quality, more maintainable code.
  47. endef
  48. define Package/python-pip-conf
  49. $(call Package/python/Default)
  50. TITLE:=Configuration file for pip/pip3
  51. URL:=https://pip.pypa.io
  52. endef
  53. define Package/python-pip-conf/description
  54. Configuration file for pip/pip3
  55. endef
  56. define Package/python-base
  57. $(call Package/python/Default)
  58. TITLE:=Python $(PYTHON_VERSION) interpreter
  59. DEPENDS:=+libpthread +zlib
  60. endef
  61. define Package/python-base/description
  62. This package contains only the interpreter and the bare minimum
  63. for the interpreter to start.
  64. endef
  65. define Package/python-light
  66. $(call Package/python/Default)
  67. TITLE:=Python $(PYTHON_VERSION) light installation
  68. DEPENDS:=+python-base +libffi +libbz2
  69. endef
  70. define Package/python-light/description
  71. This package is essentially the python-base package plus
  72. a few of the rarely used (and big) libraries stripped out
  73. into separate packages.
  74. endef
  75. PYTHON_LIB_FILES_DEL:=
  76. PYTHON_PACKAGES:=
  77. PYTHON_PACKAGES_DEPENDS:=
  78. define PyBasePackage
  79. PYTHON_PACKAGES+=$(1)
  80. ifeq ($(3),)
  81. PYTHON_PACKAGES_DEPENDS+=$(1)
  82. endif
  83. PYTHON_LIB_FILES_DEL+=$(2)
  84. define PyPackage/$(1)/filespec
  85. ifneq ($(2),)
  86. $(subst $(space),$(newline),$(foreach lib_file,$(2),+|$(lib_file)))
  87. endif
  88. endef
  89. endef
  90. include ./files/python-package-*.mk
  91. define Package/python
  92. $(call Package/python/Default)
  93. DEPENDS:=+python-light $(foreach package,$(PYTHON_PACKAGES_DEPENDS),+$(package))
  94. endef
  95. define Package/python/description
  96. This package contains the (almost) full Python install.
  97. It's python-light + all other packages.
  98. endef
  99. MAKE_FLAGS+=\
  100. CROSS_COMPILE=yes \
  101. LD="$(TARGET_CC)" \
  102. PGEN=pgen2
  103. EXTRA_CFLAGS+= \
  104. -DNDEBUG -fno-inline
  105. EXTRA_LDFLAGS+= \
  106. -L$(PKG_BUILD_DIR)
  107. ENABLE_IPV6:=
  108. ifeq ($(CONFIG_IPV6),y)
  109. ENABLE_IPV6 += --enable-ipv6
  110. endif
  111. PYTHON_FOR_BUILD:= \
  112. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  113. _PYTHON_HOST_PLATFORM=linux2 \
  114. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  115. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  116. $(HOST_PYTHON_BIN)
  117. CONFIGURE_ARGS+= \
  118. --sysconfdir=/etc \
  119. --enable-shared \
  120. --without-cxx-main \
  121. --with-threads \
  122. --with-system-ffi \
  123. --with-ensurepip=no \
  124. --without-pymalloc \
  125. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  126. $(ENABLE_IPV6) \
  127. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  128. OPT="$(TARGET_CFLAGS)"
  129. define Build/Prepare
  130. $(call Build/Prepare/Default)
  131. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  132. endef
  133. ifdef CONFIG_PACKAGE_python-setuptools
  134. define Build/Compile/python-setuptools
  135. $(STAGING_DIR_HOSTPKG)/bin/pip install \
  136. --ignore-installed \
  137. --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
  138. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
  139. endef
  140. endif # CONFIG_PACKAGE_python-setuptools
  141. ifdef CONFIG_PACKAGE_python-pip
  142. define Build/Compile/python-pip
  143. $(STAGING_DIR_HOSTPKG)/bin/pip install \
  144. --ignore-installed \
  145. --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
  146. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
  147. endef
  148. endif # CONFIG_PACKAGE_python-pip
  149. define Build/Compile
  150. $(call Build/Compile/Default)
  151. # Use host pip to install python-setuptools
  152. $(call Build/Compile/python-setuptools)
  153. $(call Build/Compile/python-pip)
  154. endef
  155. define Build/InstallDev
  156. $(INSTALL_DIR) $(STAGING_DIR)/mk/
  157. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/ $(1)/usr/lib/pkgconfig
  158. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  159. $(INSTALL_DATA) \
  160. ./files/python-package.mk \
  161. ./files/python-host.mk \
  162. ./files/python-version.mk \
  163. $(STAGING_DIR)/mk/
  164. $(CP) \
  165. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  166. $(1)/usr/include/
  167. $(CP) \
  168. $(HOST_PYTHON_LIB_DIR) \
  169. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  170. $(1)/usr/lib/
  171. $(CP) \
  172. $(HOST_PYTHON_DIR)/lib/pkgconfig/python.pc \
  173. $(HOST_PYTHON_DIR)/lib/pkgconfig/python2.pc \
  174. $(HOST_PYTHON_DIR)/lib/pkgconfig/python-$(PYTHON_VERSION).pc \
  175. $(1)/usr/lib/pkgconfig
  176. $(CP) \
  177. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config \
  178. $(1)/usr/lib/python$(PYTHON_VERSION)/
  179. endef
  180. PYTHON_BASE_LIB_FILES:= \
  181. /usr/lib/python$(PYTHON_VERSION)/_abcoll.py \
  182. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  183. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  184. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  185. /usr/lib/python$(PYTHON_VERSION)/copy_reg.py \
  186. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  187. /usr/lib/python$(PYTHON_VERSION)/linecache.py \
  188. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  189. /usr/lib/python$(PYTHON_VERSION)/os.py \
  190. /usr/lib/python$(PYTHON_VERSION)/re.py \
  191. /usr/lib/python$(PYTHON_VERSION)/site.py \
  192. /usr/lib/python$(PYTHON_VERSION)/sre_compile.py \
  193. /usr/lib/python$(PYTHON_VERSION)/sre_constants.py \
  194. /usr/lib/python$(PYTHON_VERSION)/sre_parse.py \
  195. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  196. /usr/lib/python$(PYTHON_VERSION)/stat.py \
  197. /usr/lib/python$(PYTHON_VERSION)/traceback.py \
  198. /usr/lib/python$(PYTHON_VERSION)/types.py \
  199. /usr/lib/python$(PYTHON_VERSION)/UserDict.py \
  200. /usr/lib/python$(PYTHON_VERSION)/warnings.py
  201. PYTHON_LIB_FILES_DEL+=$(PYTHON_BASE_LIB_FILES)
  202. define PyPackage/python-base/filespec
  203. +|/usr/bin/python$(PYTHON_VERSION)
  204. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_BASE_LIB_FILES),+|$(lib_file)))
  205. endef
  206. define PyPackage/python-light/filespec
  207. +|/usr/lib/python$(PYTHON_VERSION)
  208. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  209. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  210. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  211. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  212. -|/usr/lib/python$(PYTHON_VERSION)/lib-tk
  213. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_testcapi.so
  214. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  215. -|/usr/lib/python$(PYTHON_VERSION)/test
  216. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  217. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  218. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  219. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline.so
  220. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_LIB_FILES_DEL),-|$(lib_file)))
  221. endef
  222. define PyPackage/python-base/install
  223. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python
  224. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python2
  225. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  226. endef
  227. define PyPackage/python/filespec
  228. -|$(PYTHON_PKG_DIR)
  229. endef
  230. define Package/python-pip-conf/install
  231. $(INSTALL_DIR) $(1)/etc
  232. $(CP) ./files/pip.conf $(1)/etc
  233. endef
  234. HOST_LDFLAGS += \
  235. $$$$(pkg-config --static --libs libcrypto libssl)
  236. HOST_CONFIGURE_ARGS+= \
  237. --without-cxx-main \
  238. --without-pymalloc \
  239. --with-threads \
  240. --prefix=$(HOST_PYTHON_DIR) \
  241. --exec-prefix=$(HOST_PYTHON_DIR) \
  242. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  243. --with-system-ffi=no \
  244. --with-ensurepip=install \
  245. CONFIG_SITE=
  246. define Host/Install
  247. $(MAKE) -C $(HOST_BUILD_DIR) install
  248. $(INSTALL_DIR) $(HOST_PYTHON_DIR)/bin/
  249. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON_DIR)/bin/pgen2
  250. endef
  251. $(eval $(call HostBuild))
  252. $(foreach package, $(PYTHON_PACKAGES), \
  253. $(eval $(call PyPackage,$(package))) \
  254. $(eval $(call BuildPackage,$(package))) \
  255. )
  256. $(eval $(call PyPackage,python-base))
  257. $(eval $(call PyPackage,python-light))
  258. $(eval $(call PyPackage,python))
  259. $(eval $(call BuildPackage,python-pip-conf))
  260. $(eval $(call BuildPackage,python-base))
  261. $(eval $(call BuildPackage,python-light))
  262. $(eval $(call BuildPackage,python))