python3.mk 9.0 KB

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