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.

319 lines
9.3 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:=5
  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. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  88. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  89. endif
  90. endef
  91. endef
  92. include ./files/python-package-*.mk
  93. define Package/python
  94. $(call Package/python/Default)
  95. DEPENDS:=+python-light $(foreach package,$(PYTHON_PACKAGES_DEPENDS),+$(package))
  96. endef
  97. define Package/python/description
  98. This package contains the (almost) full Python install.
  99. It's python-light + all other packages.
  100. endef
  101. MAKE_FLAGS+=\
  102. CROSS_COMPILE=yes \
  103. LD="$(TARGET_CC)" \
  104. PGEN=pgen2
  105. EXTRA_CFLAGS+= \
  106. -DNDEBUG -fno-inline
  107. EXTRA_LDFLAGS+= \
  108. -L$(PKG_BUILD_DIR)
  109. ENABLE_IPV6:=
  110. ifeq ($(CONFIG_IPV6),y)
  111. ENABLE_IPV6 += --enable-ipv6
  112. endif
  113. PYTHON_FOR_BUILD:= \
  114. _PYTHON_PROJECT_BASE=$(PKG_BUILD_DIR) \
  115. _PYTHON_HOST_PLATFORM=linux2 \
  116. PYTHONPATH="$(PKG_BUILD_DIR)/Lib:$(PKG_BUILD_DIR)/build/lib.linux2-$(PYTHON_VERSION)" \
  117. _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata \
  118. $(HOST_PYTHON_BIN)
  119. CONFIGURE_ARGS+= \
  120. --sysconfdir=/etc \
  121. --enable-shared \
  122. --without-cxx-main \
  123. --with-threads \
  124. --with-system-ffi \
  125. --with-ensurepip=no \
  126. --without-pymalloc \
  127. PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)" \
  128. $(ENABLE_IPV6) \
  129. CONFIG_SITE="$(PKG_BUILD_DIR)/config.site" \
  130. OPT="$(TARGET_CFLAGS)"
  131. define Build/Prepare
  132. $(call Build/Prepare/Default)
  133. $(CP) ./files/config.site $(PKG_BUILD_DIR)/config.site
  134. endef
  135. ifdef CONFIG_PACKAGE_python-setuptools
  136. define Build/Compile/python-setuptools
  137. $(STAGING_DIR_HOSTPKG)/bin/pip install \
  138. --ignore-installed \
  139. --root=$(PKG_BUILD_DIR)/install-setuptools --prefix=. \
  140. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-*.whl
  141. endef
  142. endif # CONFIG_PACKAGE_python-setuptools
  143. ifdef CONFIG_PACKAGE_python-pip
  144. define Build/Compile/python-pip
  145. $(STAGING_DIR_HOSTPKG)/bin/pip install \
  146. --ignore-installed \
  147. --root=$(PKG_BUILD_DIR)/install-pip --prefix=. \
  148. $(PKG_BUILD_DIR)/Lib/ensurepip/_bundled/pip-*.whl
  149. endef
  150. endif # CONFIG_PACKAGE_python-pip
  151. define Build/Compile
  152. $(call Build/Compile/Default)
  153. # Use host pip to install python-setuptools
  154. $(call Build/Compile/python-setuptools)
  155. $(call Build/Compile/python-pip)
  156. endef
  157. define Build/InstallDev
  158. $(INSTALL_DIR) $(STAGING_DIR)/mk/
  159. $(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/ $(1)/usr/lib/pkgconfig
  160. $(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
  161. $(INSTALL_DATA) \
  162. ./files/python-package.mk \
  163. ./files/python-host.mk \
  164. ./files/python-version.mk \
  165. ./files/python-package-install.sh \
  166. $(STAGING_DIR)/mk/
  167. $(CP) \
  168. $(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
  169. $(1)/usr/include/
  170. $(CP) \
  171. $(HOST_PYTHON_LIB_DIR) \
  172. $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* \
  173. $(1)/usr/lib/
  174. $(CP) \
  175. $(HOST_PYTHON_DIR)/lib/pkgconfig/python.pc \
  176. $(HOST_PYTHON_DIR)/lib/pkgconfig/python2.pc \
  177. $(HOST_PYTHON_DIR)/lib/pkgconfig/python-$(PYTHON_VERSION).pc \
  178. $(1)/usr/lib/pkgconfig
  179. $(CP) \
  180. $(PKG_INSTALL_DIR)/usr/lib/python$(PYTHON_VERSION)/config \
  181. $(1)/usr/lib/python$(PYTHON_VERSION)/
  182. endef
  183. PYTHON_BASE_LIB_FILES:= \
  184. /usr/lib/python$(PYTHON_VERSION)/_abcoll.py \
  185. /usr/lib/python$(PYTHON_VERSION)/_sysconfigdata.py \
  186. /usr/lib/python$(PYTHON_VERSION)/_weakrefset.py \
  187. /usr/lib/python$(PYTHON_VERSION)/abc.py \
  188. /usr/lib/python$(PYTHON_VERSION)/copy_reg.py \
  189. /usr/lib/python$(PYTHON_VERSION)/genericpath.py \
  190. /usr/lib/python$(PYTHON_VERSION)/linecache.py \
  191. /usr/lib/python$(PYTHON_VERSION)/posixpath.py \
  192. /usr/lib/python$(PYTHON_VERSION)/os.py \
  193. /usr/lib/python$(PYTHON_VERSION)/re.py \
  194. /usr/lib/python$(PYTHON_VERSION)/site.py \
  195. /usr/lib/python$(PYTHON_VERSION)/sre_compile.py \
  196. /usr/lib/python$(PYTHON_VERSION)/sre_constants.py \
  197. /usr/lib/python$(PYTHON_VERSION)/sre_parse.py \
  198. /usr/lib/python$(PYTHON_VERSION)/sysconfig.py \
  199. /usr/lib/python$(PYTHON_VERSION)/stat.py \
  200. /usr/lib/python$(PYTHON_VERSION)/traceback.py \
  201. /usr/lib/python$(PYTHON_VERSION)/types.py \
  202. /usr/lib/python$(PYTHON_VERSION)/UserDict.py \
  203. /usr/lib/python$(PYTHON_VERSION)/warnings.py
  204. PYTHON_LIB_FILES_DEL+=$(PYTHON_BASE_LIB_FILES)
  205. define PyPackage/python-base/filespec
  206. +|/usr/bin/python$(PYTHON_VERSION)
  207. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_BASE_LIB_FILES),+|$(lib_file)))
  208. endef
  209. define PyPackage/python-light/filespec
  210. +|/usr/lib/python$(PYTHON_VERSION)
  211. -|/usr/lib/python$(PYTHON_VERSION)/distutils/cygwinccompiler.py
  212. -|/usr/lib/python$(PYTHON_VERSION)/distutils/command/wininst*
  213. -|/usr/lib/python$(PYTHON_VERSION)/ensurepip
  214. -|/usr/lib/python$(PYTHON_VERSION)/idlelib
  215. -|/usr/lib/python$(PYTHON_VERSION)/lib-tk
  216. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_testcapi.so
  217. -|/usr/lib/python$(PYTHON_VERSION)/pdb.doc
  218. -|/usr/lib/python$(PYTHON_VERSION)/test
  219. -|/usr/lib/python$(PYTHON_VERSION)/webbrowser.py
  220. -|/usr/lib/python$(PYTHON_VERSION)/*/test
  221. -|/usr/lib/python$(PYTHON_VERSION)/*/tests
  222. -|/usr/lib/python$(PYTHON_VERSION)/lib-dynload/readline.so
  223. $(subst $(space),$(newline),$(foreach lib_file,$(PYTHON_LIB_FILES_DEL),-|$(lib_file)))
  224. endef
  225. define PyPackage/python-base/install
  226. $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib
  227. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python
  228. $(LN) python$(PYTHON_VERSION) $(1)/usr/bin/python2
  229. $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpython$(PYTHON_VERSION).so* $(1)/usr/lib/
  230. endef
  231. define PyPackage/python/filespec
  232. -|$(PYTHON_PKG_DIR)
  233. endef
  234. define Package/python-pip-conf/install
  235. $(INSTALL_DIR) $(1)/etc
  236. $(CP) ./files/pip.conf $(1)/etc
  237. endef
  238. HOST_LDFLAGS += \
  239. $$$$(pkg-config --static --libs libcrypto libssl)
  240. HOST_CONFIGURE_ARGS+= \
  241. --without-cxx-main \
  242. --without-pymalloc \
  243. --with-threads \
  244. --prefix=$(HOST_PYTHON_DIR) \
  245. --exec-prefix=$(HOST_PYTHON_DIR) \
  246. --with-system-expat=$(STAGING_DIR_HOSTPKG) \
  247. --with-system-ffi=no \
  248. --with-ensurepip=install \
  249. CONFIG_SITE=
  250. define Host/Install
  251. $(MAKE) -C $(HOST_BUILD_DIR) install
  252. $(INSTALL_DIR) $(HOST_PYTHON_DIR)/bin/
  253. $(INSTALL_BIN) $(HOST_BUILD_DIR)/Parser/pgen $(HOST_PYTHON_DIR)/bin/pgen2
  254. endef
  255. $(eval $(call HostBuild))
  256. $(foreach package, $(PYTHON_PACKAGES), \
  257. $(eval $(call PyPackage,$(package))) \
  258. $(eval $(call BuildPackage,$(package))) \
  259. $(eval $(call BuildPackage,$(package)-src)) \
  260. )
  261. $(eval $(call PyPackage,python-base))
  262. $(eval $(call PyPackage,python-light))
  263. $(eval $(call PyPackage,python))
  264. $(eval $(call BuildPackage,python-pip-conf))
  265. $(eval $(call BuildPackage,python-base))
  266. $(eval $(call BuildPackage,python-light))
  267. $(eval $(call BuildPackage,python))
  268. $(eval $(call BuildPackage,python-base-src))
  269. $(eval $(call BuildPackage,python-light-src))
  270. $(eval $(call BuildPackage,python-src))