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