diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -571,7 +571,10 @@ if args: vals = [] for name in args: - vals.append(_CONFIG_VARS.get(name)) + v = _CONFIG_VARS.get(name) + if _PYTHON_BUILD and name == 'CFLAGS': + v += ' ' + _CONFIG_VARS.get('PY_CFLAGS_NODIST') + vals.append(v) return vals else: return _CONFIG_VARS @@ -586,7 +589,11 @@ if name == 'SO': import warnings warnings.warn('SO is deprecated, use EXT_SUFFIX', DeprecationWarning, 2) - return get_config_vars().get(name) + v = get_config_vars().get(name) + if _PYTHON_BUILD and name == 'CFLAGS': + return v + ' ' + _CONFIG_VARS.get('PY_CFLAGS_NODIST') + else: + return v def get_platform(): diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -71,12 +71,17 @@ BASECFLAGS= @BASECFLAGS@ BASECPPFLAGS= @BASECPPFLAGS@ CONFIGURE_CFLAGS= @CFLAGS@ +# CFLAGS_NODIST is used for building the interpreter and stdlib C extensions. +# Use it when a compiler flag should _not_ be part of the distutils CFLAGS +# once Python is installed (Issue #21121). +CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@ CONFIGURE_CPPFLAGS= @CPPFLAGS@ CONFIGURE_LDFLAGS= @LDFLAGS@ # Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the # command line to append to these values without stomping the pre-set # values. PY_CFLAGS= $(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) +PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables @@ -91,7 +96,7 @@ # Extra C flags added for building the interpreter object files. CFLAGSFORSHARED=@CFLAGSFORSHARED@ # C flags used for building the interpreter object files -PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE +PY_CORE_CFLAGS= $(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE # Machine-dependent subdirectories diff --git a/configure b/configure --- a/configure +++ b/configure @@ -662,6 +662,7 @@ LIBTOOL_CRUFT OTHER_LIBTOOL_OPT UNIVERSAL_ARCH_FLAGS +CFLAGS_NODIST BASECFLAGS OPT ABIFLAGS @@ -6504,7 +6505,7 @@ if test $ac_cv_declaration_after_statement_warning = yes then - BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement" + CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement" fi # if using gcc on alpha, use -mieee to get (near) full IEEE 754 diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1147,6 +1147,7 @@ fi AC_SUBST(BASECFLAGS) +AC_SUBST(CFLAGS_NODIST) # The -arch flags for universal builds on OSX UNIVERSAL_ARCH_FLAGS= @@ -1231,7 +1232,7 @@ if test $ac_cv_declaration_after_statement_warning = yes then - BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement" + CFLAGS_NODIST="$CFLAGS_NODIST -Werror=declaration-after-statement" fi # if using gcc on alpha, use -mieee to get (near) full IEEE 754