@@ -283,14 +283,19 @@ BUILDPYTHON= python$(BUILDEXE)
283283PYTHON_FOR_REGEN?=@PYTHON_FOR_REGEN@
284284UPDATE_FILE=$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/update_file.py
285285PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
286- # Standard builds use _bootstrap_python for freezing, cross compiling
287- # uses build Python, which must have the same version and bytecode,
288- PYTHON_FOR_FREEZE?=@PYTHON_FOR_FREEZE@
286+
287+ # Normal builds use Programs/_freeze_module.c for bootstrapping and
288+ # ./_bootstrap_python Programs/_freeze_module.py for remaining modules
289+ # Cross builds use an external "build Python" for all modules.
290+ PYTHON_FOR_FREEZE=@PYTHON_FOR_FREEZE@
291+ FREEZE_MODULE_BOOTSTRAP=@FREEZE_MODULE_BOOTSTRAP@
292+ FREEZE_MODULE_BOOTSTRAP_DEPS=@FREEZE_MODULE_BOOTSTRAP_DEPS@
293+ FREEZE_MODULE=@FREEZE_MODULE@
294+ FREEZE_MODULE_DEPS=@FREEZE_MODULE_DEPS@
295+
289296_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
290297BUILD_GNU_TYPE= @build@
291298HOST_GNU_TYPE= @host@
292- # Allow developers to override freeze_module command for cross building (bpo-45886)
293- FREEZE_MODULE?=@FREEZE_MODULE@
294299
295300# Tcl and Tk config info from --with-tcltk-includes and -libs options
296301TCLTK_INCLUDES= @TCLTK_INCLUDES@
@@ -967,7 +972,7 @@ _bootstrap_python: $(LIBRARY_OBJS_OMIT_FROZEN) Programs/_bootstrap_python.o Modu
967972.PHONY: regen-deepfreeze
968973regen-deepfreeze: $(DEEPFREEZE_OBJS)
969974
970- DEEPFREEZE_DEPS=$(srcdir)/Tools/scripts/deepfreeze.py _bootstrap_python
975+ DEEPFREEZE_DEPS=$(srcdir)/Tools/scripts/deepfreeze.py $(FREEZE_MODULE_DEPS)
971976
972977# BEGIN: deepfreeze modules
973978
@@ -1044,6 +1049,30 @@ Python/deepfreeze/frozen_only.c: Python/frozen_modules/frozen_only.h $(DEEPFREEZ
10441049
10451050############################################################################
10461051# frozen modules (including importlib)
1052+ #
1053+ # Freezing is a multi step process. It works differently for standard builds
1054+ # and cross builds. Standard builds use Programs/_freeze_module and
1055+ # _bootstrap_python for freezing and deepfreezing, so users can build Python
1056+ # without an existing Python installation. Cross builds cannot execute
1057+ # compiled binaries and therefore rely on an external build Python
1058+ # interpreter. The build interpreter must have same version and same bytecode
1059+ # as the host (target) binary.
1060+ #
1061+ # Standard build process:
1062+ # 1) compile minimal core objects for Py_Compile*() and PyMarshal_Write*().
1063+ # 2) build Programs/_freeze_module binary.
1064+ # 3) create frozen module headers for importlib and getpath.
1065+ # 4) build _bootstrap_python binary.
1066+ # 5) create remaining frozen module headers with
1067+ # ``./_bootstrap_python Programs/_freeze_module.py``. The pure Python
1068+ # script is used to test the cross compile code path.
1069+ # 6) deepfreeze modules with _bootstrap_python
1070+ #
1071+ # Cross compile process:
1072+ # 1) create all frozen module headers with external build Python and
1073+ # Programs/_freeze_module.py script.
1074+ # 2) deepfreeze modules with external build Python.
1075+ #
10471076
10481077# FROZEN_FILES_* are auto-generated by Tools/scripts/freeze_modules.py.
10491078FROZEN_FILES_IN = \
@@ -1104,83 +1133,83 @@ Modules/getpath_noop.o: $(srcdir)/Modules/getpath_noop.c Makefile
11041133Programs/_freeze_module: Programs/_freeze_module.o Modules/getpath_noop.o $(LIBRARY_OBJS_OMIT_FROZEN)
11051134 $(LINKCC) $(PY_CORE_LDFLAGS) -o $@ Programs/_freeze_module.o Modules/getpath_noop.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS)
11061135
1136+ # We manually freeze getpath.py rather than through freeze_modules
1137+ Python/frozen_modules/getpath.h: Modules/getpath.py $(FREEZE_MODULE_BOOTSTRAP_DEPS)
1138+ $(FREEZE_MODULE_BOOTSTRAP) getpath $(srcdir)/Modules/getpath.py Python/frozen_modules/getpath.h
1139+
11071140# BEGIN: freezing modules
11081141
1109- Python/frozen_modules/importlib._bootstrap.h: $(FREEZE_MODULE) Lib/importlib/_bootstrap.py
1110- $(FREEZE_MODULE ) importlib._bootstrap $(srcdir)/Lib/importlib/_bootstrap.py Python/frozen_modules/importlib._bootstrap.h
1142+ Python/frozen_modules/importlib._bootstrap.h: Lib/importlib/_bootstrap.py $(FREEZE_MODULE_BOOTSTRAP_DEPS)
1143+ $(FREEZE_MODULE_BOOTSTRAP ) importlib._bootstrap $(srcdir)/Lib/importlib/_bootstrap.py Python/frozen_modules/importlib._bootstrap.h
11111144
1112- Python/frozen_modules/importlib._bootstrap_external.h: $(FREEZE_MODULE) Lib/importlib/_bootstrap_external.py
1113- $(FREEZE_MODULE ) importlib._bootstrap_external $(srcdir)/Lib/importlib/_bootstrap_external.py Python/frozen_modules/importlib._bootstrap_external.h
1145+ Python/frozen_modules/importlib._bootstrap_external.h: Lib/importlib/_bootstrap_external.py $(FREEZE_MODULE_BOOTSTRAP_DEPS)
1146+ $(FREEZE_MODULE_BOOTSTRAP ) importlib._bootstrap_external $(srcdir)/Lib/importlib/_bootstrap_external.py Python/frozen_modules/importlib._bootstrap_external.h
11141147
1115- Python/frozen_modules/zipimport.h: $(FREEZE_MODULE) Lib/zipimport.py
1116- $(FREEZE_MODULE ) zipimport $(srcdir)/Lib/zipimport.py Python/frozen_modules/zipimport.h
1148+ Python/frozen_modules/zipimport.h: Lib/zipimport.py $(FREEZE_MODULE_BOOTSTRAP_DEPS)
1149+ $(FREEZE_MODULE_BOOTSTRAP ) zipimport $(srcdir)/Lib/zipimport.py Python/frozen_modules/zipimport.h
11171150
1118- Python/frozen_modules/abc.h: $(FREEZE_MODULE) Lib/abc.py
1151+ Python/frozen_modules/abc.h: Lib/abc.py $(FREEZE_MODULE_DEPS)
11191152 $(FREEZE_MODULE) abc $(srcdir)/Lib/abc.py Python/frozen_modules/abc.h
11201153
1121- Python/frozen_modules/codecs.h: $(FREEZE_MODULE) Lib/codecs.py
1154+ Python/frozen_modules/codecs.h: Lib/codecs.py $(FREEZE_MODULE_DEPS)
11221155 $(FREEZE_MODULE) codecs $(srcdir)/Lib/codecs.py Python/frozen_modules/codecs.h
11231156
1124- Python/frozen_modules/io.h: $(FREEZE_MODULE) Lib/io.py
1157+ Python/frozen_modules/io.h: Lib/io.py $(FREEZE_MODULE_DEPS)
11251158 $(FREEZE_MODULE) io $(srcdir)/Lib/io.py Python/frozen_modules/io.h
11261159
1127- Python/frozen_modules/_collections_abc.h: $(FREEZE_MODULE) Lib/_collections_abc.py
1160+ Python/frozen_modules/_collections_abc.h: Lib/_collections_abc.py $(FREEZE_MODULE_DEPS)
11281161 $(FREEZE_MODULE) _collections_abc $(srcdir)/Lib/_collections_abc.py Python/frozen_modules/_collections_abc.h
11291162
1130- Python/frozen_modules/_sitebuiltins.h: $(FREEZE_MODULE) Lib/_sitebuiltins.py
1163+ Python/frozen_modules/_sitebuiltins.h: Lib/_sitebuiltins.py $(FREEZE_MODULE_DEPS)
11311164 $(FREEZE_MODULE) _sitebuiltins $(srcdir)/Lib/_sitebuiltins.py Python/frozen_modules/_sitebuiltins.h
11321165
1133- Python/frozen_modules/genericpath.h: $(FREEZE_MODULE) Lib/genericpath.py
1166+ Python/frozen_modules/genericpath.h: Lib/genericpath.py $(FREEZE_MODULE_DEPS)
11341167 $(FREEZE_MODULE) genericpath $(srcdir)/Lib/genericpath.py Python/frozen_modules/genericpath.h
11351168
1136- Python/frozen_modules/ntpath.h: $(FREEZE_MODULE) Lib/ntpath.py
1169+ Python/frozen_modules/ntpath.h: Lib/ntpath.py $(FREEZE_MODULE_DEPS)
11371170 $(FREEZE_MODULE) ntpath $(srcdir)/Lib/ntpath.py Python/frozen_modules/ntpath.h
11381171
1139- Python/frozen_modules/posixpath.h: $(FREEZE_MODULE) Lib/posixpath.py
1172+ Python/frozen_modules/posixpath.h: Lib/posixpath.py $(FREEZE_MODULE_DEPS)
11401173 $(FREEZE_MODULE) posixpath $(srcdir)/Lib/posixpath.py Python/frozen_modules/posixpath.h
11411174
1142- Python/frozen_modules/os.h: $(FREEZE_MODULE) Lib/os.py
1175+ Python/frozen_modules/os.h: Lib/os.py $(FREEZE_MODULE_DEPS)
11431176 $(FREEZE_MODULE) os $(srcdir)/Lib/os.py Python/frozen_modules/os.h
11441177
1145- Python/frozen_modules/site.h: $(FREEZE_MODULE) Lib/site.py
1178+ Python/frozen_modules/site.h: Lib/site.py $(FREEZE_MODULE_DEPS)
11461179 $(FREEZE_MODULE) site $(srcdir)/Lib/site.py Python/frozen_modules/site.h
11471180
1148- Python/frozen_modules/stat.h: $(FREEZE_MODULE) Lib/stat.py
1181+ Python/frozen_modules/stat.h: Lib/stat.py $(FREEZE_MODULE_DEPS)
11491182 $(FREEZE_MODULE) stat $(srcdir)/Lib/stat.py Python/frozen_modules/stat.h
11501183
1151- Python/frozen_modules/importlib.util.h: $(FREEZE_MODULE) Lib/importlib/util.py
1184+ Python/frozen_modules/importlib.util.h: Lib/importlib/util.py $(FREEZE_MODULE_DEPS)
11521185 $(FREEZE_MODULE) importlib.util $(srcdir)/Lib/importlib/util.py Python/frozen_modules/importlib.util.h
11531186
1154- Python/frozen_modules/importlib.machinery.h: $(FREEZE_MODULE) Lib/importlib/machinery.py
1187+ Python/frozen_modules/importlib.machinery.h: Lib/importlib/machinery.py $(FREEZE_MODULE_DEPS)
11551188 $(FREEZE_MODULE) importlib.machinery $(srcdir)/Lib/importlib/machinery.py Python/frozen_modules/importlib.machinery.h
11561189
1157- Python/frozen_modules/runpy.h: $(FREEZE_MODULE) Lib/runpy.py
1190+ Python/frozen_modules/runpy.h: Lib/runpy.py $(FREEZE_MODULE_DEPS)
11581191 $(FREEZE_MODULE) runpy $(srcdir)/Lib/runpy.py Python/frozen_modules/runpy.h
11591192
1160- Python/frozen_modules/__hello__.h: $(FREEZE_MODULE) Lib/__hello__.py
1193+ Python/frozen_modules/__hello__.h: Lib/__hello__.py $(FREEZE_MODULE_DEPS)
11611194 $(FREEZE_MODULE) __hello__ $(srcdir)/Lib/__hello__.py Python/frozen_modules/__hello__.h
11621195
1163- Python/frozen_modules/__phello__.h: $(FREEZE_MODULE) Lib/__phello__/__init__.py
1196+ Python/frozen_modules/__phello__.h: Lib/__phello__/__init__.py $(FREEZE_MODULE_DEPS)
11641197 $(FREEZE_MODULE) __phello__ $(srcdir)/Lib/__phello__/__init__.py Python/frozen_modules/__phello__.h
11651198
1166- Python/frozen_modules/__phello__.ham.h: $(FREEZE_MODULE) Lib/__phello__/ham/__init__.py
1199+ Python/frozen_modules/__phello__.ham.h: Lib/__phello__/ham/__init__.py $(FREEZE_MODULE_DEPS)
11671200 $(FREEZE_MODULE) __phello__.ham $(srcdir)/Lib/__phello__/ham/__init__.py Python/frozen_modules/__phello__.ham.h
11681201
1169- Python/frozen_modules/__phello__.ham.eggs.h: $(FREEZE_MODULE) Lib/__phello__/ham/eggs.py
1202+ Python/frozen_modules/__phello__.ham.eggs.h: Lib/__phello__/ham/eggs.py $(FREEZE_MODULE_DEPS)
11701203 $(FREEZE_MODULE) __phello__.ham.eggs $(srcdir)/Lib/__phello__/ham/eggs.py Python/frozen_modules/__phello__.ham.eggs.h
11711204
1172- Python/frozen_modules/__phello__.spam.h: $(FREEZE_MODULE) Lib/__phello__/spam.py
1205+ Python/frozen_modules/__phello__.spam.h: Lib/__phello__/spam.py $(FREEZE_MODULE_DEPS)
11731206 $(FREEZE_MODULE) __phello__.spam $(srcdir)/Lib/__phello__/spam.py Python/frozen_modules/__phello__.spam.h
11741207
1175- Python/frozen_modules/frozen_only.h: $(FREEZE_MODULE) Tools/freeze/flag.py
1208+ Python/frozen_modules/frozen_only.h: Tools/freeze/flag.py $(FREEZE_MODULE_DEPS)
11761209 $(FREEZE_MODULE) frozen_only $(srcdir)/Tools/freeze/flag.py Python/frozen_modules/frozen_only.h
11771210
11781211# END: freezing modules
11791212
1180- # We manually freeze getpath.py rather than through freeze_modules
1181- Python/frozen_modules/getpath.h: $(FREEZE_MODULE) Modules/getpath.py
1182- $(FREEZE_MODULE) getpath $(srcdir)/Modules/getpath.py Python/frozen_modules/getpath.h
1183-
11841213Tools/scripts/freeze_modules.py: $(FREEZE_MODULE)
11851214
11861215.PHONY: regen-frozen
0 commit comments