at master 12 kB view raw
1--- a/Lib/_osx_support.py 2+++ b/Lib/_osx_support.py 3@@ -14,13 +14,13 @@ __all__ = [ 4 # configuration variables that may contain universal build flags, 5 # like "-arch" or "-isdkroot", that may need customization for 6 # the user environment 7-_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS', 8- 'BLDSHARED', 'LDSHARED', 'CC', 'CXX', 9- 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', 10- 'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS') 11+_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS', 12+ 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 13+ 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 14+ 'PY_CPPFLAGS', 'PY_CORE_LDFLAGS', 'PY_CORE_CFLAGS') 15 16 # configuration variables that may contain compiler calls 17-_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX') 18+_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX') 19 20 # prefix added to original configuration variable names 21 _INITPRE = '_OSX_SUPPORT_INITIAL_' 22--- a/Lib/distutils/cygwinccompiler.py 23+++ b/Lib/distutils/cygwinccompiler.py 24@@ -125,8 +125,10 @@ class CygwinCCompiler(UnixCCompiler): 25 # dllwrap 2.10.90 is buggy 26 if self.ld_version >= "2.10.90": 27 self.linker_dll = "gcc" 28+ self.linker_dll_cxx = "g++" 29 else: 30 self.linker_dll = "dllwrap" 31+ self.linker_dll_cxx = "dllwrap" 32 33 # ld_version >= "2.13" support -shared so use it instead of 34 # -mdll -static 35@@ -140,9 +142,13 @@ class CygwinCCompiler(UnixCCompiler): 36 self.set_executables(compiler='gcc -mcygwin -O -Wall', 37 compiler_so='gcc -mcygwin -mdll -O -Wall', 38 compiler_cxx='g++ -mcygwin -O -Wall', 39+ compiler_so_cxx='g++ -mcygwin -mdll -O -Wall', 40 linker_exe='gcc -mcygwin', 41 linker_so=('%s -mcygwin %s' % 42- (self.linker_dll, shared_option))) 43+ (self.linker_dll, shared_option)), 44+ linker_exe_cxx='g++ -mcygwin', 45+ linker_so_cxx=('%s -mcygwin %s' % 46+ (self.linker_dll_cxx, shared_option))) 47 48 # cygwin and mingw32 need different sets of libraries 49 if self.gcc_version == "2.91.57": 50@@ -166,8 +172,12 @@ class CygwinCCompiler(UnixCCompiler): 51 raise CompileError(msg) 52 else: # for other files use the C-compiler 53 try: 54- self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 55- extra_postargs) 56+ if self.detect_language(src) == 'c++': 57+ self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] + 58+ extra_postargs) 59+ else: 60+ self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 61+ extra_postargs) 62 except DistutilsExecError as msg: 63 raise CompileError(msg) 64 65@@ -302,9 +312,14 @@ class Mingw32CCompiler(CygwinCCompiler): 66 self.set_executables(compiler='gcc -O -Wall', 67 compiler_so='gcc -mdll -O -Wall', 68 compiler_cxx='g++ -O -Wall', 69+ compiler_so_cxx='g++ -mdll -O -Wall', 70 linker_exe='gcc', 71 linker_so='%s %s %s' 72 % (self.linker_dll, shared_option, 73+ entry_point), 74+ linker_exe_cxx='g++', 75+ linker_so_cxx='%s %s %s' 76+ % (self.linker_dll_cxx, shared_option, 77 entry_point)) 78 # Maybe we should also append -mthreads, but then the finished 79 # dlls need another dll (mingwm10.dll see Mingw32 docs) 80--- a/Lib/distutils/sysconfig.py 81+++ b/Lib/distutils/sysconfig.py 82@@ -170,9 +170,11 @@ def customize_compiler(compiler): 83 _osx_support.customize_compiler(_config_vars) 84 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' 85 86- (cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \ 87- get_config_vars('CC', 'CXX', 'CFLAGS', 88- 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') 89+ (cc, cxx, cflags, ccshared, ldshared, ldcxxshared, shlib_suffix, ar, ar_flags) = \ 90+ get_config_vars('CC', 'CXX', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED', 91+ 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') 92+ 93+ cxxflags = cflags 94 95 if 'CC' in os.environ: 96 newcc = os.environ['CC'] 97@@ -187,19 +189,27 @@ def customize_compiler(compiler): 98 cxx = os.environ['CXX'] 99 if 'LDSHARED' in os.environ: 100 ldshared = os.environ['LDSHARED'] 101+ if 'LDCXXSHARED' in os.environ: 102+ ldcxxshared = os.environ['LDCXXSHARED'] 103 if 'CPP' in os.environ: 104 cpp = os.environ['CPP'] 105 else: 106 cpp = cc + " -E" # not always 107 if 'LDFLAGS' in os.environ: 108 ldshared = ldshared + ' ' + os.environ['LDFLAGS'] 109+ ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS'] 110 if 'CFLAGS' in os.environ: 111- cflags = cflags + ' ' + os.environ['CFLAGS'] 112+ cflags = os.environ['CFLAGS'] 113 ldshared = ldshared + ' ' + os.environ['CFLAGS'] 114+ if 'CXXFLAGS' in os.environ: 115+ cxxflags = os.environ['CXXFLAGS'] 116+ ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS'] 117 if 'CPPFLAGS' in os.environ: 118 cpp = cpp + ' ' + os.environ['CPPFLAGS'] 119 cflags = cflags + ' ' + os.environ['CPPFLAGS'] 120+ cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS'] 121 ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] 122+ ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS'] 123 if 'AR' in os.environ: 124 ar = os.environ['AR'] 125 if 'ARFLAGS' in os.environ: 126@@ -208,13 +218,17 @@ def customize_compiler(compiler): 127 archiver = ar + ' ' + ar_flags 128 129 cc_cmd = cc + ' ' + cflags 130+ cxx_cmd = cxx + ' ' + cxxflags 131 compiler.set_executables( 132 preprocessor=cpp, 133 compiler=cc_cmd, 134 compiler_so=cc_cmd + ' ' + ccshared, 135- compiler_cxx=cxx, 136+ compiler_cxx=cxx_cmd, 137+ compiler_so_cxx=cxx_cmd + ' ' + ccshared, 138 linker_so=ldshared, 139 linker_exe=cc, 140+ linker_so_cxx=ldcxxshared, 141+ linker_exe_cxx=cxx, 142 archiver=archiver) 143 144 compiler.shared_lib_extension = shlib_suffix 145--- a/Lib/distutils/unixccompiler.py 146+++ b/Lib/distutils/unixccompiler.py 147@@ -52,14 +52,17 @@ class UnixCCompiler(CCompiler): 148 # are pretty generic; they will probably have to be set by an outsider 149 # (eg. using information discovered by the sysconfig about building 150 # Python extensions). 151- executables = {'preprocessor' : None, 152- 'compiler' : ["cc"], 153- 'compiler_so' : ["cc"], 154- 'compiler_cxx' : ["cc"], 155- 'linker_so' : ["cc", "-shared"], 156- 'linker_exe' : ["cc"], 157- 'archiver' : ["ar", "-cr"], 158- 'ranlib' : None, 159+ executables = {'preprocessor' : None, 160+ 'compiler' : ["cc"], 161+ 'compiler_so' : ["cc"], 162+ 'compiler_cxx' : ["c++"], 163+ 'compiler_so_cxx' : ["c++"], 164+ 'linker_so' : ["cc", "-shared"], 165+ 'linker_exe' : ["cc"], 166+ 'linker_so_cxx' : ["c++", "-shared"], 167+ 'linker_exe_cxx' : ["c++"], 168+ 'archiver' : ["ar", "-cr"], 169+ 'ranlib' : None, 170 } 171 172 if sys.platform[:6] == "darwin": 173@@ -110,12 +113,19 @@ class UnixCCompiler(CCompiler): 174 175 def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): 176 compiler_so = self.compiler_so 177+ compiler_so_cxx = self.compiler_so_cxx 178 if sys.platform == 'darwin': 179 compiler_so = _osx_support.compiler_fixup(compiler_so, 180 cc_args + extra_postargs) 181+ compiler_so_cxx = _osx_support.compiler_fixup(compiler_so_cxx, 182+ cc_args + extra_postargs) 183 try: 184- self.spawn(compiler_so + cc_args + [src, '-o', obj] + 185- extra_postargs) 186+ if self.detect_language(src) == 'c++': 187+ self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] + 188+ extra_postargs) 189+ else: 190+ self.spawn(compiler_so + cc_args + [src, '-o', obj] + 191+ extra_postargs) 192 except DistutilsExecError as msg: 193 raise CompileError(msg) 194 195@@ -173,30 +183,16 @@ class UnixCCompiler(CCompiler): 196 ld_args.extend(extra_postargs) 197 self.mkpath(os.path.dirname(output_filename)) 198 try: 199- if target_desc == CCompiler.EXECUTABLE: 200- linker = self.linker_exe[:] 201+ if target_lang == "c++": 202+ if target_desc == CCompiler.EXECUTABLE: 203+ linker = self.linker_exe_cxx[:] 204+ else: 205+ linker = self.linker_so_cxx[:] 206 else: 207- linker = self.linker_so[:] 208- if target_lang == "c++" and self.compiler_cxx: 209- # skip over environment variable settings if /usr/bin/env 210- # is used to set up the linker's environment. 211- # This is needed on OSX. Note: this assumes that the 212- # normal and C++ compiler have the same environment 213- # settings. 214- i = 0 215- if os.path.basename(linker[0]) == "env": 216- i = 1 217- while '=' in linker[i]: 218- i += 1 219- 220- if os.path.basename(linker[i]) == 'ld_so_aix': 221- # AIX platforms prefix the compiler with the ld_so_aix 222- # script, so we need to adjust our linker index 223- offset = 1 224+ if target_desc == CCompiler.EXECUTABLE: 225+ linker = self.linker_exe[:] 226 else: 227- offset = 0 228- 229- linker[i+offset] = self.compiler_cxx[i] 230+ linker = self.linker_so[:] 231 232 if sys.platform == 'darwin': 233 linker = _osx_support.compiler_fixup(linker, ld_args) 234--- a/Makefile.pre.in 235+++ b/Makefile.pre.in 236@@ -584,10 +584,10 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o 237 *\ -s*|s*) quiet="-q";; \ 238 *) quiet="";; \ 239 esac; \ 240- echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ 241+ echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \ 242 _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ 243 $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \ 244- $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ 245+ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \ 246 _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ 247 $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build 248