python3.mk 8.4 KB

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