···1+diff --git a/Makefile.pre.in b/Makefile.pre.in
2+--- a/Makefile.pre.in
3++++ b/Makefile.pre.in
4+@@ -71,12 +71,17 @@
5+ BASECFLAGS= @BASECFLAGS@
6+ BASECPPFLAGS= @BASECPPFLAGS@
7+ CONFIGURE_CFLAGS= @CFLAGS@
8++# CFLAGS_NODIST is used for building the interpreter and stdlib C extensions.
9++# Use it when a compiler flag should _not_ be part of the distutils CFLAGS
10++# once Python is installed (Issue #21121).
11++CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@
12+ CONFIGURE_CPPFLAGS= @CPPFLAGS@
13+ CONFIGURE_LDFLAGS= @LDFLAGS@
14+ # Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the
15+ # command line to append to these values without stomping the pre-set
16+ # values.
17+ PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
18++PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST)
19+ # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
20+ # be able to build extension modules using the directories specified in the
21+ # environment variables
22+@@ -91,7 +96,7 @@
23+ # Extra C flags added for building the interpreter object files.
24+ CFLAGSFORSHARED=@CFLAGSFORSHARED@
25+ # C flags used for building the interpreter object files
26+-PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
27++PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
28+29+30+ # Machine-dependent subdirectories
31+diff --git a/configure b/configure
32+--- a/configure
33++++ b/configure
34+@@ -662,6 +662,7 @@
35+ LIBTOOL_CRUFT
36+ OTHER_LIBTOOL_OPT
37+ UNIVERSAL_ARCH_FLAGS
38++CFLAGS_NODIST
39+ BASECFLAGS
40+ OPT
41+ ABIFLAGS
42+@@ -6504,7 +6505,7 @@
43+44+ if test $ac_cv_declaration_after_statement_warning = yes
45+ then
46+- BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement"
47++ CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement"
48+ fi
49+50+ # if using gcc on alpha, use -mieee to get (near) full IEEE 754
51+diff --git a/configure.ac b/configure.ac
52+--- a/configure.ac
53++++ b/configure.ac
54+@@ -1147,6 +1147,7 @@
55+ fi
56+57+ AC_SUBST(BASECFLAGS)
58++AC_SUBST(CFLAGS_NODIST)
59+60+ # The -arch flags for universal builds on OSX
61+ UNIVERSAL_ARCH_FLAGS=
62+@@ -1231,7 +1232,7 @@
63+64+ if test $ac_cv_declaration_after_statement_warning = yes
65+ then
66+- BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement"
67++ CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement"
68+ fi
69+70+ # if using gcc on alpha, use -mieee to get (near) full IEEE 754
71+diff --git a/setup.py b/setup.py
72+--- a/setup.py
73++++ b/setup.py
74+@@ -19,6 +19,12 @@
75+76+ cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
77+78++# Add special CFLAGS reserved for building the interpreter and the stdlib
79++# modules (Issue #21121).
80++cflags = sysconfig.get_config_var('CFLAGS')
81++py_cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST')
82++sysconfig.get_config_vars()['CFLAGS'] = cflags + ' ' + py_cflags_nodist
83++
84+ def get_platform():
85+ # cross build
86+ if "_PYTHON_HOST_PLATFORM" in os.environ: