python3.mk 7.9 KB

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