python3.mk 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. ################################################################################
  2. #
  3. # python3
  4. #
  5. ################################################################################
  6. PYTHON3_VERSION_MAJOR = 3.13
  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. # This host Python is installed in $(HOST_DIR), as it is needed when
  15. # cross-compiling third-party Python modules.
  16. HOST_PYTHON3_CONF_OPTS += \
  17. --without-ensurepip \
  18. --without-cxx-main \
  19. --disable-sqlite3 \
  20. --disable-tk \
  21. --with-expat=system \
  22. --disable-test-modules \
  23. --disable-idle3
  24. # Make sure that LD_LIBRARY_PATH overrides -rpath.
  25. # This is needed because libpython may be installed at the same time that
  26. # python is called.
  27. # TODO: nis and ossaudiodev modules will be dropped in 3.13: https://peps.python.org/pep-0594/
  28. HOST_PYTHON3_CONF_ENV += \
  29. LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \
  30. py_cv_module_unicodedata=yes \
  31. py_cv_module__codecs_cn=n/a \
  32. py_cv_module__codecs_hk=n/a \
  33. py_cv_module__codecs_iso2022=n/a \
  34. py_cv_module__codecs_jp=n/a \
  35. py_cv_module__codecs_kr=n/a \
  36. py_cv_module__codecs_tw=n/a \
  37. py_cv_module__uuid=n/a \
  38. py_cv_module_nis=n/a \
  39. py_cv_module_ossaudiodev=n/a
  40. PYTHON3_DEPENDENCIES = host-python3 libffi
  41. HOST_PYTHON3_DEPENDENCIES = \
  42. host-autoconf-archive \
  43. host-expat \
  44. host-libffi \
  45. host-pkgconf \
  46. host-zlib
  47. ifeq ($(BR2_PACKAGE_HOST_PYTHON3_BZIP2),y)
  48. HOST_PYTHON3_DEPENDENCIES += host-bzip2
  49. else
  50. HOST_PYTHON3_CONF_ENV += py_cv_module__bz2=n/a
  51. endif
  52. ifeq ($(BR2_PACKAGE_HOST_PYTHON3_XZ),y)
  53. HOST_PYTHON3_DEPENDENCIES += host-xz
  54. else
  55. HOST_PYTHON3_CONF_ENV += py_cv_module__lzma=n/a
  56. endif
  57. ifeq ($(BR2_PACKAGE_HOST_PYTHON3_CURSES),y)
  58. HOST_PYTHON3_DEPENDENCIES += host-ncurses
  59. else
  60. HOST_PYTHON3_CONF_OPTS += --disable-curses
  61. endif
  62. ifeq ($(BR2_PACKAGE_HOST_PYTHON3_SSL),y)
  63. HOST_PYTHON3_DEPENDENCIES += host-openssl
  64. else
  65. HOST_PYTHON3_CONF_ENV += \
  66. py_cv_module__hashlib=n/a \
  67. py_cv_module__ssl=n/a
  68. endif
  69. PYTHON3_INSTALL_STAGING = YES
  70. ifeq ($(BR2_PACKAGE_PYTHON3_2TO3),y)
  71. PYTHON3_CONF_OPTS += --enable-lib2to3
  72. else
  73. PYTHON3_CONF_OPTS += --disable-lib2to3
  74. endif
  75. ifeq ($(BR2_PACKAGE_PYTHON3_BERKELEYDB),y)
  76. PYTHON3_DEPENDENCIES += berkeleydb
  77. else
  78. PYTHON3_CONF_ENV += py_cv_module__dbm=n/a
  79. endif
  80. ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y)
  81. PYTHON3_CONF_OPTS += --with-readline
  82. PYTHON3_DEPENDENCIES += readline
  83. else
  84. PYTHON3_CONF_OPTS += --without-readline
  85. endif
  86. ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y)
  87. PYTHON3_DEPENDENCIES += ncurses
  88. else
  89. PYTHON3_CONF_OPTS += --disable-curses
  90. endif
  91. ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y)
  92. PYTHON3_DEPENDENCIES += mpdecimal
  93. PYTHON3_CONF_OPTS += --with-system-libmpdec
  94. else
  95. PYTHON3_CONF_ENV += py_cv_module__decimal=n/a
  96. endif
  97. ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y)
  98. PYTHON3_DEPENDENCIES += expat
  99. PYTHON3_CONF_OPTS += --with-expat=system
  100. else
  101. PYTHON3_CONF_OPTS += --with-expat=none
  102. endif
  103. ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
  104. PYTHON3_DEPENDENCIES += sqlite
  105. else
  106. PYTHON3_CONF_OPTS += --disable-sqlite3
  107. endif
  108. ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y)
  109. PYTHON3_DEPENDENCIES += openssl
  110. PYTHON3_CONF_OPTS += --with-openssl=$(STAGING_DIR)/usr
  111. else
  112. PYTHON3_CONF_ENV += \
  113. py_cv_module__hashlib=n/a \
  114. py_cv_module__ssl=n/a
  115. endif
  116. ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y)
  117. PYTHON3_CONF_ENV += \
  118. py_cv_module__codecs_cn=n/a \
  119. py_cv_module__codecs_hk=n/a \
  120. py_cv_module__codecs_iso2022=n/a \
  121. py_cv_module__codecs_jp=n/a \
  122. py_cv_module__codecs_kr=n/a \
  123. py_cv_module__codecs_tw=n/a
  124. endif
  125. ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y)
  126. PYTHON3_CONF_ENV += py_cv_module_unicodedata=n/a
  127. endif
  128. # Disable auto-detection of uuid.h (util-linux)
  129. # which would add _uuid module support, instead
  130. # default to the pure python implementation
  131. PYTHON3_CONF_ENV += py_cv_module__uuid=n/a
  132. ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y)
  133. PYTHON3_DEPENDENCIES += bzip2
  134. else
  135. PYTHON3_CONF_ENV += py_cv_module__bz2=n/a
  136. endif
  137. ifeq ($(BR2_PACKAGE_PYTHON3_XZ),y)
  138. PYTHON3_DEPENDENCIES += xz
  139. else
  140. PYTHON3_CONF_ENV += py_cv_module__lzma=n/a
  141. endif
  142. ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y)
  143. PYTHON3_DEPENDENCIES += zlib
  144. else
  145. PYTHON3_CONF_ENV += py_cv_module_zlib=n/a
  146. endif
  147. ifneq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y)
  148. PYTHON3_CONF_ENV += py_cv_module_ossaudiodev=n/a
  149. endif
  150. PYTHON3_CONF_ENV += \
  151. ac_cv_have_long_long_format=yes \
  152. ac_cv_buggy_getaddrinfo=no \
  153. ac_cv_file__dev_ptmx=yes \
  154. ac_cv_file__dev_ptc=yes \
  155. ac_cv_working_tzset=yes \
  156. py_cv_module_nis=n/a
  157. # GCC is always compliant with IEEE754
  158. ifeq ($(BR2_ENDIAN),"LITTLE")
  159. PYTHON3_CONF_ENV += ac_cv_little_endian_double=yes
  160. else
  161. PYTHON3_CONF_ENV += ac_cv_big_endian_double=yes
  162. endif
  163. PYTHON3_CFLAGS = $(TARGET_CFLAGS)
  164. ifeq ($(BR2_TOOLCHAIN_HAS_GCC_BUG_121567),y)
  165. PYTHON3_CFLAGS += -O1
  166. endif
  167. PYTHON3_CONF_ENV += \
  168. CFLAGS="$(PYTHON3_CFLAGS)"
  169. ifeq ($(BR2_PACKAGE_GETTEXT_PROVIDES_LIBINTL),y)
  170. PYTHON3_DEPENDENCIES += gettext
  171. endif
  172. PYTHON3_CONF_OPTS += \
  173. --without-ensurepip \
  174. --without-cxx-main \
  175. --with-build-python=$(HOST_DIR)/bin/python3 \
  176. --with-system-ffi \
  177. --disable-pydoc \
  178. --disable-test-modules \
  179. --disable-tk \
  180. --disable-idle3 \
  181. --disable-pyc-build
  182. #
  183. # Remove useless files. In the config/ directory, only the Makefile
  184. # and the pyconfig.h files are needed at runtime.
  185. #
  186. define PYTHON3_REMOVE_USELESS_FILES
  187. rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config
  188. rm -f $(TARGET_DIR)/usr/bin/python3-config
  189. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)*/ \
  190. -depth -type f -not -name Makefile -exec rm -rf {} \;
  191. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/ -depth -type d \
  192. -name __pycache__ -exec rm -rf {} \;
  193. endef
  194. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES
  195. #
  196. # Make sure libpython gets stripped out on target
  197. #
  198. define PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  199. chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so
  200. endef
  201. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED
  202. PYTHON3_AUTORECONF = YES
  203. PYTHON3_AUTORECONF_OPTS = --include=$(HOST_DIR)/share/autoconf-archive
  204. define PYTHON3_INSTALL_SYMLINK
  205. ln -fs python3 $(TARGET_DIR)/usr/bin/python
  206. endef
  207. PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK
  208. define HOST_PYTHON3_INSTALL_SYMLINK
  209. ln -fs python3 $(HOST_DIR)/bin/python
  210. ln -fs python3-config $(HOST_DIR)/bin/python-config
  211. endef
  212. HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK
  213. # Provided to other packages
  214. PYTHON3_PATH = $(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/
  215. # Support for socket.AF_BLUETOOTH
  216. ifeq ($(BR2_PACKAGE_BLUEZ5_UTILS_HEADERS),y)
  217. PYTHON3_DEPENDENCIES += bluez5_utils-headers
  218. endif
  219. $(eval $(autotools-package))
  220. $(eval $(host-autotools-package))
  221. ifeq ($(BR2_REPRODUCIBLE),y)
  222. define PYTHON3_FIX_TIME
  223. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
  224. xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH)
  225. endef
  226. endif
  227. define PYTHON3_CREATE_PYC_FILES
  228. $(PYTHON3_FIX_TIME)
  229. PYTHONPATH="$(PYTHON3_PATH)" \
  230. $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) \
  231. $(PYTHON3_DIR)/Lib/compileall.py \
  232. $(if $(VERBOSE),,-q) \
  233. $(if $(BR2_PACKAGE_PYTHON3_PYC_ONLY),-b) \
  234. -s $(TARGET_DIR) \
  235. -p / \
  236. $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
  237. endef
  238. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
  239. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
  240. endif
  241. ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
  242. define PYTHON3_REMOVE_PY_FILES
  243. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' \
  244. $(if $(strip $(KEEP_PYTHON_PY_FILES)),-not \( $(call finddirclauses,$(TARGET_DIR),$(KEEP_PYTHON_PY_FILES)) \) ) \
  245. -print0 | \
  246. xargs -0 --no-run-if-empty rm -f
  247. endef
  248. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
  249. endif
  250. # Normally, *.pyc files should not have been compiled, but just in
  251. # case, we make sure we remove all of them.
  252. ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
  253. define PYTHON3_REMOVE_PYC_FILES
  254. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
  255. xargs -0 --no-run-if-empty rm -f
  256. endef
  257. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES
  258. endif
  259. # In all cases, we don't want to keep the optimized .opt-1.pyc and
  260. # .opt-2.pyc files, since they can't work without their non-optimized
  261. # variant.
  262. define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  263. find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \
  264. xargs -0 --no-run-if-empty rm -f
  265. endef
  266. PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES
  267. # uClibc without time64 support (i.e. when linux headers < 5.1) causes
  268. # a runtime assertion in Python. Encoding this as a dependency in Config.in
  269. # causes too many problems for propagating reverse dependencies. Therefore
  270. # instead we do a build time check.
  271. ifeq ($(BR_BUILDING)$(BR2_PACKAGE_PYTHON3)$(BR2_TOOLCHAIN_USES_UCLIBC)-$(BR2_TOOLCHAIN_HEADERS_AT_LEAST_5_1),yyy-)
  272. $(error Python3 doesn't work with uClibc and kernel headers < 5.1. Please use a different toolchain or unselect Python3.)
  273. endif