1################################################################################ 2# 3# python3 4# 5################################################################################ 6 7PYTHON3_VERSION_MAJOR = 3.10 8PYTHON3_VERSION = $(PYTHON3_VERSION_MAJOR).5 9PYTHON3_SOURCE = Python-$(PYTHON3_VERSION).tar.xz 10PYTHON3_SITE = https://python.org/ftp/python/$(PYTHON3_VERSION) 11PYTHON3_LICENSE = Python-2.0, others 12PYTHON3_LICENSE_FILES = LICENSE 13PYTHON3_CPE_ID_VENDOR = python 14PYTHON3_CPE_ID_PRODUCT = python 15 16# This host Python is installed in $(HOST_DIR), as it is needed when 17# cross-compiling third-party Python modules. 18 19HOST_PYTHON3_CONF_OPTS += \ 20 --without-ensurepip \ 21 --without-cxx-main \ 22 --disable-sqlite3 \ 23 --disable-tk \ 24 --with-expat=system \ 25 --disable-curses \ 26 --disable-codecs-cjk \ 27 --disable-nis \ 28 --enable-unicodedata \ 29 --disable-test-modules \ 30 --disable-idle3 \ 31 --disable-ossaudiodev 32 33# Make sure that LD_LIBRARY_PATH overrides -rpath. 34# This is needed because libpython may be installed at the same time that 35# python is called. 36# Make python believe we don't have 'hg', so that it doesn't try to 37# communicate over the network during the build. 38HOST_PYTHON3_CONF_ENV += \ 39 LDFLAGS="$(HOST_LDFLAGS) -Wl,--enable-new-dtags" \ 40 ac_cv_prog_HAS_HG=/bin/false 41 42PYTHON3_DEPENDENCIES = host-python3 libffi 43 44HOST_PYTHON3_DEPENDENCIES = host-autoconf-archive host-expat host-zlib host-libffi 45 46ifeq ($(BR2_PACKAGE_HOST_PYTHON3_BZIP2),y) 47HOST_PYTHON3_DEPENDENCIES += host-bzip2 48else 49HOST_PYTHON3_CONF_OPTS += --disable-bzip2 50endif 51 52ifeq ($(BR2_PACKAGE_HOST_PYTHON3_SSL),y) 53HOST_PYTHON3_DEPENDENCIES += host-openssl 54else 55HOST_PYTHON3_CONF_OPTS += --disable-openssl 56endif 57 58PYTHON3_INSTALL_STAGING = YES 59 60ifeq ($(BR2_PACKAGE_PYTHON3_2TO3),y) 61PYTHON3_CONF_OPTS += --enable-lib2to3 62else 63PYTHON3_CONF_OPTS += --disable-lib2to3 64endif 65 66ifeq ($(BR2_PACKAGE_PYTHON3_BERKELEYDB),y) 67PYTHON3_DEPENDENCIES += berkeleydb 68else 69PYTHON3_CONF_OPTS += --disable-berkeleydb 70endif 71 72ifeq ($(BR2_PACKAGE_PYTHON3_READLINE),y) 73PYTHON3_DEPENDENCIES += readline 74else 75PYTHON3_CONF_OPTS += --disable-readline 76endif 77 78ifeq ($(BR2_PACKAGE_PYTHON3_CURSES),y) 79PYTHON3_DEPENDENCIES += ncurses 80else 81PYTHON3_CONF_OPTS += --disable-curses 82endif 83 84ifeq ($(BR2_PACKAGE_PYTHON3_DECIMAL),y) 85PYTHON3_DEPENDENCIES += mpdecimal 86PYTHON3_CONF_OPTS += --with-libmpdec=system 87else 88PYTHON3_CONF_OPTS += --with-libmpdec=none 89endif 90 91ifeq ($(BR2_PACKAGE_PYTHON3_PYEXPAT),y) 92PYTHON3_DEPENDENCIES += expat 93PYTHON3_CONF_OPTS += --with-expat=system 94else 95PYTHON3_CONF_OPTS += --with-expat=none 96endif 97 98ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y) 99PYTHON3_DEPENDENCIES += sqlite 100else 101PYTHON3_CONF_OPTS += --disable-sqlite3 102endif 103 104ifeq ($(BR2_PACKAGE_PYTHON3_SSL),y) 105PYTHON3_DEPENDENCIES += openssl 106PYTHON3_CONF_OPTS += --with-openssl=$(STAGING_DIR)/usr 107else 108PYTHON3_CONF_OPTS += --disable-openssl 109endif 110 111ifneq ($(BR2_PACKAGE_PYTHON3_CODECSCJK),y) 112PYTHON3_CONF_OPTS += --disable-codecs-cjk 113endif 114 115ifneq ($(BR2_PACKAGE_PYTHON3_UNICODEDATA),y) 116PYTHON3_CONF_OPTS += --disable-unicodedata 117endif 118 119# Disable auto-detection of uuid.h (util-linux) 120# which would add _uuid module support, instead 121# default to the pure python implementation 122PYTHON3_CONF_OPTS += --disable-uuid 123 124ifeq ($(BR2_PACKAGE_PYTHON3_BZIP2),y) 125PYTHON3_DEPENDENCIES += bzip2 126else 127PYTHON3_CONF_OPTS += --disable-bzip2 128endif 129 130ifeq ($(BR2_PACKAGE_PYTHON3_XZ),y) 131PYTHON3_DEPENDENCIES += xz 132else 133PYTHON3_CONF_OPTS += --disable-xz 134endif 135 136ifeq ($(BR2_PACKAGE_PYTHON3_ZLIB),y) 137PYTHON3_DEPENDENCIES += zlib 138else 139PYTHON3_CONF_OPTS += --disable-zlib 140endif 141 142ifeq ($(BR2_PACKAGE_PYTHON3_OSSAUDIODEV),y) 143PYTHON3_CONF_OPTS += --enable-ossaudiodev 144else 145PYTHON3_CONF_OPTS += --disable-ossaudiodev 146endif 147 148# Make python believe we don't have 'hg', so that it doesn't try to 149# communicate over the network during the build. 150PYTHON3_CONF_ENV += \ 151 ac_cv_have_long_long_format=yes \ 152 ac_cv_file__dev_ptmx=yes \ 153 ac_cv_file__dev_ptc=yes \ 154 ac_cv_working_tzset=yes \ 155 ac_cv_prog_HAS_HG=/bin/false 156 157# GCC is always compliant with IEEE754 158ifeq ($(BR2_ENDIAN),"LITTLE") 159PYTHON3_CONF_ENV += ac_cv_little_endian_double=yes 160else 161PYTHON3_CONF_ENV += ac_cv_big_endian_double=yes 162endif 163 164# uClibc is known to have a broken wcsftime() implementation, so tell 165# Python 3 to fall back to strftime() instead. 166ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y) 167PYTHON3_CONF_ENV += ac_cv_func_wcsftime=no 168endif 169 170ifeq ($(BR2_PACKAGE_GETTEXT_PROVIDES_LIBINTL),y) 171PYTHON3_DEPENDENCIES += gettext 172endif 173 174PYTHON3_CONF_OPTS += \ 175 --without-ensurepip \ 176 --without-cxx-main \ 177 --with-system-ffi \ 178 --disable-pydoc \ 179 --disable-test-modules \ 180 --disable-tk \ 181 --disable-nis \ 182 --disable-idle3 \ 183 --disable-pyc-build 184 185# 186# Some of CPython's source code is generated using Python interpreter 187# and some helper tools such as "Programs/_freeze_importlib" or 188# "Parser/pgen" (look for regen-* targets in Makefile.pre.in for more 189# info). Normally CPython codebase ships with those files 190# pre-generated, so just regular "make" with no additional steps 191# should be sufficient for a succesfull build, however due to 192# Buildroot's "Add importlib fix for PEP 3147 issue" custom patch we 193# end up modifying "Lib/importlib/_bootstrap_external.py" which means 194# we have to do "regen-importlib" step before building CPython 195# (Importlib is a builtin module that needs to be "frozen"/converted 196# to a C array of bytecode using "Programs/_freeze_importlib") 197# 198# To achive that we add pre-build steps to host-python3 as well as 199# python3 that execute "regen-importlib" target. 200# 201# Unfortunately, for the target Python, "Programs/_freeze_importlib" 202# is built for the target, while we need to run them at build time. So 203# when installing host-python3, we copy them to $(HOST_DIR)/bin... 204# 205define HOST_PYTHON3_MAKE_REGEN_IMPORTLIB 206 $(HOST_MAKE_ENV) $(PYTHON3_CONF_ENV) $(MAKE) $(HOST_CONFIGURE_OPTS) -C $(@D) regen-importlib 207 cp $(@D)/Programs/_freeze_importlib $(HOST_DIR)/bin/python-freeze-importlib 208endef 209 210HOST_PYTHON3_PRE_BUILD_HOOKS += HOST_PYTHON3_MAKE_REGEN_IMPORTLIB 211# 212# ... And then, when building the target python we first buid 213# 'Programs/_freeze_importlib' to force GNU Make to update all of the 214# prerequisites of 'Programs/_freeze_importlib', then copy our stashed 215# "host-usable" version over the one that was just build and then 216# build "regen-importlib" target 217# 218define PYTHON3_MAKE_REGEN_IMPORTLIB 219 $(TARGET_MAKE_ENV) $(PYTHON3_CONF_ENV) $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) Programs/_freeze_importlib 220 cp $(HOST_DIR)/bin/python-freeze-importlib $(@D)/Programs/_freeze_importlib 221 $(TARGET_MAKE_ENV) $(PYTHON3_CONF_ENV) $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) regen-importlib 222endef 223 224PYTHON3_PRE_BUILD_HOOKS += PYTHON3_MAKE_REGEN_IMPORTLIB 225 226# 227# Remove useless files. In the config/ directory, only the Makefile 228# and the pyconfig.h files are needed at runtime. 229# 230define PYTHON3_REMOVE_USELESS_FILES 231 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)-config 232 rm -f $(TARGET_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR)m-config 233 rm -f $(TARGET_DIR)/usr/bin/python3-config 234 rm -f $(TARGET_DIR)/usr/bin/smtpd.py.3 235 rm -f $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/distutils/command/wininst*.exe 236 for i in `find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/config-$(PYTHON3_VERSION_MAJOR)m-*/ \ 237 -type f -not -name Makefile` ; do \ 238 rm -f $$i ; \ 239 done 240 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/__pycache__/ 241 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/lib-dynload/sysconfigdata/__pycache__ 242 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/collections/__pycache__ 243 rm -rf $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/importlib/__pycache__ 244endef 245 246PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_REMOVE_USELESS_FILES 247 248# 249# Make sure libpython gets stripped out on target 250# 251define PYTHON3_ENSURE_LIBPYTHON_STRIPPED 252 chmod u+w $(TARGET_DIR)/usr/lib/libpython$(PYTHON3_VERSION_MAJOR)*.so 253endef 254 255PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_ENSURE_LIBPYTHON_STRIPPED 256 257PYTHON3_AUTORECONF = YES 258PYTHON3_AUTORECONF_OPTS = --include=$(HOST_DIR)/share/autoconf-archive 259 260define PYTHON3_INSTALL_SYMLINK 261 ln -fs python3 $(TARGET_DIR)/usr/bin/python 262endef 263 264PYTHON3_POST_INSTALL_TARGET_HOOKS += PYTHON3_INSTALL_SYMLINK 265 266define HOST_PYTHON3_INSTALL_SYMLINK 267 ln -fs python3 $(HOST_DIR)/bin/python 268 ln -fs python3-config $(HOST_DIR)/bin/python-config 269endef 270 271HOST_PYTHON3_POST_INSTALL_HOOKS += HOST_PYTHON3_INSTALL_SYMLINK 272 273# Provided to other packages 274PYTHON3_PATH = $(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)/ 275 276# Support for socket.AF_BLUETOOTH 277ifeq ($(BR2_PACKAGE_BLUEZ5_UTILS_HEADERS),y) 278PYTHON3_DEPENDENCIES += bluez5_utils-headers 279endif 280 281$(eval $(autotools-package)) 282$(eval $(host-autotools-package)) 283 284ifeq ($(BR2_REPRODUCIBLE),y) 285define PYTHON3_FIX_TIME 286 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \ 287 xargs -0 --no-run-if-empty touch -d @$(SOURCE_DATE_EPOCH) 288endef 289endif 290 291define PYTHON3_CREATE_PYC_FILES 292 $(PYTHON3_FIX_TIME) 293 PYTHONPATH="$(PYTHON3_PATH)" \ 294 $(HOST_DIR)/bin/python$(PYTHON3_VERSION_MAJOR) \ 295 $(TOPDIR)/support/scripts/pycompile.py \ 296 $(if $(VERBOSE),--verbose) \ 297 --strip-root $(TARGET_DIR) \ 298 $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) 299endef 300 301ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y) 302PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES 303endif 304 305ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y) 306define PYTHON3_REMOVE_PY_FILES 307 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' \ 308 $(if $(strip $(KEEP_PYTHON_PY_FILES)),-not \( $(call finddirclauses,$(TARGET_DIR),$(KEEP_PYTHON_PY_FILES)) \) ) \ 309 -print0 | \ 310 xargs -0 --no-run-if-empty rm -f 311endef 312PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES 313endif 314 315# Normally, *.pyc files should not have been compiled, but just in 316# case, we make sure we remove all of them. 317ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y) 318define PYTHON3_REMOVE_PYC_FILES 319 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \ 320 xargs -0 --no-run-if-empty rm -f 321endef 322PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PYC_FILES 323endif 324 325# In all cases, we don't want to keep the optimized .opt-1.pyc and 326# .opt-2.pyc files, since they can't work without their non-optimized 327# variant. 328define PYTHON3_REMOVE_OPTIMIZED_PYC_FILES 329 find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.opt-1.pyc' -print0 -o -name '*.opt-2.pyc' -print0 | \ 330 xargs -0 --no-run-if-empty rm -f 331endef 332PYTHON3_TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_OPTIMIZED_PYC_FILES 333