python3.mk 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. ################################################################################
  2. #
  3. # python3
  4. #
  5. ################################################################################
  6. PYTHON3_VERSION_MAJOR = 3.10
  7. PYTHON3_VERSION = $(PYTHON3_VERSION_MAJOR).8
  8. PYTHON3_SOURCE = Python-$(PYTHON3_VERSION).tar.xz
  9. PYTHON3_SITE = https://python.org/ftp/python/$(PYTHON3_VERSION)
  10. PYTHON3_LICENSE = Python-2.0, others
  11. PYTHON3_LICENSE_FILES = LICENSE
  12. PYTHON3_CPE_ID_VENDOR = python
  13. PYTHON3_CPE_ID_PRODUCT = python
  14. # 0033-3.11-gh-98433-Fix-quadratic-time-idna-decoding.-GH-9.patch
  15. PYTHON3_IGNORE_CVES += CVE-2022-45061
  16. # 0034-3-10-gh-98517-Fix-buffer-overflows-in-_sha3-module.patch
  17. PYTHON3_IGNORE_CVES += CVE-2022-37454
  18. # This host Python is installed in $(HOST_DIR), as it is needed when
  19. # cross-compiling third-party Python modules.
  20. HOST_PYTHON3_CONF_OPTS += \
  21. --without-ensurepip \
  22. --without-cxx-main \
  23. --disable-sqlite3 \
  24. --disable-tk \
  25. --with-expat=system \
  26. --disable-curses \
  27. --disable-codecs-cjk \
  28. --disable-nis \
  29. --enable-unicodedata \
  30. --disable-test-modules \
  31. --disable-idle3 \
  32. --disable-ossaudiodev
  33. # Make sure that LD_LIBRARY_PATH overrides -rpath.
  34. # This is needed because libpython may be installed at the same time that
  35. # python is called.
  36. # Make python believe we don't have 'hg', so that it doesn't try to
  37. # communicate over the network during the build.
  38. HOST_PYTHON3_CONF_ENV += \
  39. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \
  40. ac_cv_prog_HAS_HG=/bin/false
  41. PYTHON3_DEPENDENCIES = host-python3 libffi
  42. HOST_PYTHON3_DEPENDENCIES = host-autoconf-archive host-expat host-zlib host-libffi
  43. ifeq ($(BR2_PACKAGE_HOST_PYTHON3_BZIP2),y)
  44. HOST_PYTHON3_DEPENDENCIES += host-bzip2
  45. else
  46. HOST_PYTHON3_CONF_OPTS += --disable-bzip2
  47. endif
  48. ifeq ($(BR2_PACKAGE_HOST_PYTHON3_SSL),y)
  49. HOST_PYTHON3_DEPENDENCIES += host-openssl
  50. else
  51. HOST_PYTHON3_CONF_OPTS += --disable-openssl
  52. endif
  53. PYTHON3_INSTALL_STAGING = YES
  54. ifeq ($(BR2_PACKAGE_PYTHON3_2TO3),y)
  55. PYTHON3_CONF_OPTS += --enable-lib2to3
  56. else
  57. PYTHON3_CONF_OPTS += --disable-lib2to3
  58. endif
  59. ifeq ($(BR2_PACKAGE_PYTHON3_BERKELEYDB),y)
  60. PYTHON3_DEPENDENCIES += berkeleydb
  61. else
  62. PYTHON3_CONF_OPTS += --disable-berkeleydb
  63. endif
  64. ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y)
  65. PYTHON3_DEPENDENCIES += readline
  66. else
  67. PYTHON3_CONF_OPTS += --disable-readline
  68. endif
  69. ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
  70. PYTHON3_DEPENDENCIES += ncurses
  71. else
  72. PYTHON3_CONF_OPTS += --disable-curses
  73. endif
  74. ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
  75. PYTHON3_DEPENDENCIES += mpdecimal
  76. PYTHON3_CONF_OPTS += --with-libmpdec=system
  77. else
  78. PYTHON3_CONF_OPTS += --with-libmpdec=none
  79. endif
  80. ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
  81. PYTHON3_DEPENDENCIES += expat
  82. PYTHON3_CONF_OPTS += --with-expat=system
  83. else
  84. PYTHON3_CONF_OPTS += --with-expat=none
  85. endif
  86. ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
  87. PYTHON3_DEPENDENCIES += sqlite
  88. else
  89. PYTHON3_CONF_OPTS += --disable-sqlite3
  90. endif
  91. ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
  92. PYTHON3_DEPENDENCIES += openssl
  93. PYTHON3_CONF_OPTS += --with-openssl=$(STAGING_DIR)/usr
  94. else
  95. PYTHON3_CONF_OPTS += --disable-openssl
  96. endif
  97. ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
  98. PYTHON3_CONF_OPTS += --disable-codecs-cjk
  99. endif
  100. ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
  101. PYTHON3_CONF_OPTS += --disable-unicodedata
  102. endif
  103. # Disable auto-detection of uuid.h (util-linux)
  104. # which would add _uuid module support, instead
  105. # default to the pure python implementation
  106. PYTHON3_CONF_OPTS += --disable-uuid
  107. ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
  108. PYTHON3_DEPENDENCIES += bzip2
  109. else
  110. PYTHON3_CONF_OPTS += --disable-bzip2
  111. endif
  112. ifeq ($(BR2_PACKAGE_PYTHON3_XZ),y)
  113. PYTHON3_DEPENDENCIES += xz
  114. else
  115. PYTHON3_CONF_OPTS += --disable-xz
  116. endif
  117. ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
  118. PYTHON3_DEPENDENCIES += zlib
  119. else
  120. PYTHON3_CONF_OPTS += --disable-zlib
  121. endif
  122. ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
  123. PYTHON3_CONF_OPTS += --enable-ossaudiodev
  124. else
  125. PYTHON3_CONF_OPTS += --disable-ossaudiodev
  126. endif
  127. # Make python believe we don't have 'hg', so that it doesn't try to
  128. # communicate over the network during the build.
  129. PYTHON3_CONF_ENV += \
  130. ac_cv_have_long_long_format=yes \
  131. ac_cv_file__dev_ptmx=yes \
  132. ac_cv_file__dev_ptc=yes \
  133. ac_cv_working_tzset=yes \
  134. ac_cv_prog_HAS_HG=/bin/false
  135. # GCC is always compliant with IEEE754
  136. ifeq ($(BR2_ENDIAN),"LITTLE")
  137. PYTHON3_CONF_ENV += ac_cv_little_endian_double=yes
  138. else
  139. PYTHON3_CONF_ENV += ac_cv_big_endian_double=yes
  140. endif
  141. # uClibc is known to have a broken wcsftime() implementation, so tell
  142. # Python 3 to fall back to strftime() instead.
  143. ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
  144. PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no
  145. endif
  146. ifeq ($(BR2_PACKAGE_GETTEXT_PROVIDES_LIBINTL),y)
  147. PYTHON3_DEPENDENCIES += gettext
  148. endif
  149. PYTHON3_CONF_OPTS += \
  150. --without-ensurepip \
  151. --without-cxx-main \
  152. --with-system-ffi \
  153. --disable-pydoc \
  154. --disable-test-modules \
  155. --disable-tk \
  156. --disable-nis \
  157. --disable-idle3 \
  158. --disable-pyc-build
  159. #
  160. # Remove useless files. In the config/ directory, only the Makefile
  161. # and the pyconfig.h files are needed at runtime.
  162. #
  163. define PYTHON3_REMOVE_USELESS_FILES
  164. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
  165. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config
  166. rm -f $(TARGET_DIR)/usr/bin/python3-config
  167. rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3
  168. rm -f $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/distutils/command/wininst*.exe
  169. for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m-*/ \
  170. -type f -not -name Makefile` ; do \
  171. rm -f $$i ; \
  172. done
  173. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/
  174. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__
  175. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__
  176. rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__
  177. endef
  178. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
  179. #
  180. # Make sure libpython gets stripped out on target
  181. #
  182. define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  183. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
  184. endef
  185. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  186. PYTHON3_AUTORECONF = YES
  187. PYTHON3_AUTORECONF_OPTS = --include=$(HOST_DIR)/share/autoconf-archive
  188. define PYTHON3_INSTALL_SYMLINK
  189. ln -fs python3 $(TARGET_DIR)/usr/bin/python
  190. endef
  191. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
  192. define HOST_PYTHON3_INSTALL_SYMLINK
  193. ln -fs python3 $(HOST_DIR)/bin/python
  194. ln -fs python3-config $(HOST_DIR)/bin/python-config
  195. endef
  196. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
  197. # Provided to other packages
  198. PYTHON3_PATH = $(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/
  199. # Support for socket.AF_BLUETOOTH
  200. ifeq ($(BR2_PACKAGE_BLUEZ5_UTILS_HEADERS),y)
  201. PYTHON3_DEPENDENCIES += bluez5_utils-headers
  202. endif
  203. $(eval $(autotools-package))
  204. $(eval $(host-autotools-package))
  205. ifeq ($(BR2_REPRODUCIBLE),y)
  206. define PYTHON3_FIX_TIME
  207. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
  208. xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH)
  209. endef
  210. endif
  211. define PYTHON3_CREATE_PYC_FILES
  212. $(PYTHON3_FIX_TIME)
  213. PYTHONPATH="$(PYTHON3_PATH)" \
  214. $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) \
  215. $(PYTHON3_DIR)/Lib/compileall.py \
  216. $(if $(VERBOSE),,-q) \
  217. $(if $(BR2_PACKAGE_PYTHON3_PYC_ONLY),-b) \
  218. -s $(TARGET_DIR) \
  219. -p / \
  220. $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
  221. endef
  222. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
  223. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
  224. endif
  225. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  226. define PYTHON3_REMOVE_PY_FILES
  227. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' \
  228. $(if $(strip $(KEEP_PYTHON_PY_FILES)),-not \( $(call finddirclauses,$(TARGET_DIR),$(KEEP_PYTHON_PY_FILES)) \) ) \
  229. -print0 | \
  230. xargs -0 --no-run-if-empty rm -f
  231. endef
  232. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
  233. endif
  234. # Normally, *.pyc files should not have been compiled, but just in
  235. # case, we make sure we remove all of them.
  236. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  237. define PYTHON3_REMOVE_PYC_FILES
  238. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
  239. xargs -0 --no-run-if-empty rm -f
  240. endef
  241. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
  242. endif
  243. # In all cases, we don't want to keep the optimized .opt-1.pyc and
  244. # .opt-2.pyc files, since they can't work without their non-optimized
  245. # variant.
  246. define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  247. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \
  248. xargs -0 --no-run-if-empty rm -f
  249. endef
  250. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES