···11+diff --git a/Makefile.pre.in b/Makefile.pre.in
22+--- a/Makefile.pre.in
33++++ b/Makefile.pre.in
44+@@ -71,12 +71,17 @@
55+ BASECFLAGS= @BASECFLAGS@
66+ BASECPPFLAGS= @BASECPPFLAGS@
77+ CONFIGURE_CFLAGS= @CFLAGS@
88++# CFLAGS_NODIST is used for building the interpreter and stdlib C extensions.
99++# Use it when a compiler flag should _not_ be part of the distutils CFLAGS
1010++# once Python is installed (Issue #21121).
1111++CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@
1212+ CONFIGURE_CPPFLAGS= @CPPFLAGS@
1313+ CONFIGURE_LDFLAGS= @LDFLAGS@
1414+ # Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the
1515+ # command line to append to these values without stomping the pre-set
1616+ # values.
1717+ PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
1818++PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST)
1919+ # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
2020+ # be able to build extension modules using the directories specified in the
2121+ # environment variables
2222+@@ -91,7 +96,7 @@
2323+ # Extra C flags added for building the interpreter object files.
2424+ CFLAGSFORSHARED=@CFLAGSFORSHARED@
2525+ # C flags used for building the interpreter object files
2626+-PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
2727++PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
2828+2929+3030+ # Machine-dependent subdirectories
3131+diff --git a/configure b/configure
3232+--- a/configure
3333++++ b/configure
3434+@@ -662,6 +662,7 @@
3535+ LIBTOOL_CRUFT
3636+ OTHER_LIBTOOL_OPT
3737+ UNIVERSAL_ARCH_FLAGS
3838++CFLAGS_NODIST
3939+ BASECFLAGS
4040+ OPT
4141+ ABIFLAGS
4242+@@ -6504,7 +6505,7 @@
4343+4444+ if test $ac_cv_declaration_after_statement_warning = yes
4545+ then
4646+- BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement"
4747++ CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement"
4848+ fi
4949+5050+ # if using gcc on alpha, use -mieee to get (near) full IEEE 754
5151+diff --git a/configure.ac b/configure.ac
5252+--- a/configure.ac
5353++++ b/configure.ac
5454+@@ -1147,6 +1147,7 @@
5555+ fi
5656+5757+ AC_SUBST(BASECFLAGS)
5858++AC_SUBST(CFLAGS_NODIST)
5959+6060+ # The -arch flags for universal builds on OSX
6161+ UNIVERSAL_ARCH_FLAGS=
6262+@@ -1231,7 +1232,7 @@
6363+6464+ if test $ac_cv_declaration_after_statement_warning = yes
6565+ then
6666+- BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement"
6767++ CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement"
6868+ fi
6969+7070+ # if using gcc on alpha, use -mieee to get (near) full IEEE 754
7171+diff --git a/setup.py b/setup.py
7272+--- a/setup.py
7373++++ b/setup.py
7474+@@ -19,6 +19,12 @@
7575+7676+ cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
7777+7878++# Add special CFLAGS reserved for building the interpreter and the stdlib
7979++# modules (Issue #21121).
8080++cflags = sysconfig.get_config_var('CFLAGS')
8181++py_cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST')
8282++sysconfig.get_config_vars()['CFLAGS'] = cflags + ' ' + py_cflags_nodist
8383++
8484+ def get_platform():
8585+ # cross build
8686+ if "_PYTHON_HOST_PLATFORM" in os.environ: