Allow overriding COMPILER with UNVERSIONED_COMPILER

Introduce UNVERSIONED_COMPILER variable in Makefile.pre.in to allow
overriding the COMPILER macro definition during the build of
Python/getcompiler.o.

This enables reproducible builds by providing a way to set a generic
compiler identification string (e.g., "[GCC]") instead of the default
versioned one.

The rule is made conditional on UNVERSIONED_COMPILER being defined.

References: https://discuss.python.org/t/unversioned-compiler-symbol-for-getcompiler-c/91735
Fixes: https://github.com/python/cpython/issues/144121
This commit is contained in:
Matěj Cepl 2026-01-21 17:10:46 +01:00
parent 1f55caf97e
commit 382b56d4ae
2 changed files with 9 additions and 0 deletions

View file

@ -1926,6 +1926,13 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
-DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \
-o $@ $(srcdir)/Modules/getbuildinfo.c
ifdef UNVERSIONED_COMPILER
Python/getcompiler.o: $(srcdir)/Python/getcompiler.c Makefile
$(CC) -c $(PY_CORE_CFLAGS) \
-DCOMPILER='"$(UNVERSIONED_COMPILER)"' \
-o $@ $(srcdir)/Python/getcompiler.c
endif
Modules/getpath.o: $(srcdir)/Modules/getpath.c Python/frozen_modules/getpath.h Makefile $(PYTHON_HEADERS)
$(CC) -c $(PY_CORE_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
-DPREFIX='"$(host_prefix)"' \

View file

@ -0,0 +1,2 @@
Make it possible for the COMPILER definition in getcompiler.c to be static
in order to make builds reproducible.