python3.mk 8.4 KB

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