blob: 06d8501afa2131c2b053e9a21f32b4c8c7e25bfc [file] [log] [blame]
Greg Warddbd12761999-08-29 18:15:07 +00001"""distutils.ccompiler
2
3Contains MSVCCompiler, an implementation of the abstract CCompiler class
Greg Warddf178f91999-09-29 12:29:10 +00004for the Microsoft Visual Studio."""
Greg Warddbd12761999-08-29 18:15:07 +00005
6
7# created 1999/08/19, Perry Stoll
Greg Ward32c4a8a2000-03-06 03:40:29 +00008# hacked by Robin Becker and Thomas Heller to do a better job of
9# finding DevStudio (through the registry)
10
Greg Ward3ce77fd2000-03-02 01:49:45 +000011__revision__ = "$Id$"
Greg Warddbd12761999-08-29 18:15:07 +000012
Greg Ward32c4a8a2000-03-06 03:40:29 +000013import sys, os, string
14from types import *
Greg Ward3add77f2000-05-30 02:02:49 +000015from distutils.errors import \
16 DistutilsExecError, DistutilsPlatformError, \
Greg Wardd1517112000-05-30 01:56:44 +000017 CompileError, LibError, LinkError
Greg Ward3add77f2000-05-30 02:02:49 +000018from distutils.ccompiler import \
19 CCompiler, gen_preprocess_options, gen_lib_options
Greg Ward62e33932000-02-10 02:52:42 +000020
Greg Ward7642f5c2000-03-31 16:47:40 +000021_can_read_reg = 0
22try:
23 import winreg
Greg Ward7642f5c2000-03-31 16:47:40 +000024 _can_read_reg = 1
Greg Ward19ce1662000-03-31 19:04:25 +000025 hkey_mod = winreg
26
27 RegOpenKeyEx = winreg.OpenKeyEx
28 RegEnumKey = winreg.EnumKey
29 RegEnumValue = winreg.EnumValue
30 RegError = winreg.error
31
Greg Ward7642f5c2000-03-31 16:47:40 +000032except ImportError:
33 try:
34 import win32api
35 import win32con
Greg Ward7642f5c2000-03-31 16:47:40 +000036 _can_read_reg = 1
Greg Ward1027e3f2000-03-31 16:53:42 +000037 hkey_mod = win32con
Greg Ward19ce1662000-03-31 19:04:25 +000038
39 RegOpenKeyEx = win32api.RegOpenKeyEx
40 RegEnumKey = win32api.RegEnumKey
41 RegEnumValue = win32api.RegEnumValue
42 RegError = win32api.error
43
Greg Ward7642f5c2000-03-31 16:47:40 +000044 except ImportError:
45 pass
Greg Ward1027e3f2000-03-31 16:53:42 +000046
47if _can_read_reg:
48 HKEY_CLASSES_ROOT = hkey_mod.HKEY_CLASSES_ROOT
49 HKEY_LOCAL_MACHINE = hkey_mod.HKEY_LOCAL_MACHINE
50 HKEY_CURRENT_USER = hkey_mod.HKEY_CURRENT_USER
51 HKEY_USERS = hkey_mod.HKEY_USERS
Greg Ward1027e3f2000-03-31 16:53:42 +000052
Greg Ward7642f5c2000-03-31 16:47:40 +000053
54
Greg Ward62e33932000-02-10 02:52:42 +000055def get_devstudio_versions ():
Greg Ward62e33932000-02-10 02:52:42 +000056 """Get list of devstudio versions from the Windows registry. Return a
Greg Ward69988092000-02-11 02:47:15 +000057 list of strings containing version numbers; the list will be
Greg Ward62e33932000-02-10 02:52:42 +000058 empty if we were unable to access the registry (eg. couldn't import
59 a registry-access module) or the appropriate registry keys weren't
Greg Ward69988092000-02-11 02:47:15 +000060 found."""
61
Greg Ward7642f5c2000-03-31 16:47:40 +000062 if not _can_read_reg:
Greg Ward62e33932000-02-10 02:52:42 +000063 return []
Greg Ward1b9c6f72000-02-08 02:39:44 +000064
65 K = 'Software\\Microsoft\\Devstudio'
66 L = []
Greg Ward1027e3f2000-03-31 16:53:42 +000067 for base in (HKEY_CLASSES_ROOT,
68 HKEY_LOCAL_MACHINE,
69 HKEY_CURRENT_USER,
70 HKEY_USERS):
Greg Ward1b9c6f72000-02-08 02:39:44 +000071 try:
Greg Ward1027e3f2000-03-31 16:53:42 +000072 k = RegOpenKeyEx(base,K)
Greg Ward1b9c6f72000-02-08 02:39:44 +000073 i = 0
74 while 1:
75 try:
Greg Ward1027e3f2000-03-31 16:53:42 +000076 p = RegEnumKey(k,i)
Greg Ward1b9c6f72000-02-08 02:39:44 +000077 if p[0] in '123456789' and p not in L:
78 L.append(p)
Greg Ward1027e3f2000-03-31 16:53:42 +000079 except RegError:
Greg Ward1b9c6f72000-02-08 02:39:44 +000080 break
81 i = i + 1
Greg Ward1027e3f2000-03-31 16:53:42 +000082 except RegError:
Greg Ward1b9c6f72000-02-08 02:39:44 +000083 pass
84 L.sort()
85 L.reverse()
86 return L
87
Greg Ward62e33932000-02-10 02:52:42 +000088# get_devstudio_versions ()
89
90
91def get_msvc_paths (path, version='6.0', platform='x86'):
Greg Ward69988092000-02-11 02:47:15 +000092 """Get a list of devstudio directories (include, lib or path). Return
93 a list of strings; will be empty list if unable to access the
94 registry or appropriate registry keys not found."""
95
Greg Ward7642f5c2000-03-31 16:47:40 +000096 if not _can_read_reg:
Greg Ward69988092000-02-11 02:47:15 +000097 return []
Greg Ward1b9c6f72000-02-08 02:39:44 +000098
99 L = []
Greg Ward62e33932000-02-10 02:52:42 +0000100 if path=='lib':
101 path= 'Library'
Greg Ward1b9c6f72000-02-08 02:39:44 +0000102 path = string.upper(path + ' Dirs')
Greg Ward62e33932000-02-10 02:52:42 +0000103 K = ('Software\\Microsoft\\Devstudio\\%s\\' +
104 'Build System\\Components\\Platforms\\Win32 (%s)\\Directories') % \
105 (version,platform)
Greg Ward1027e3f2000-03-31 16:53:42 +0000106 for base in (HKEY_CLASSES_ROOT,
107 HKEY_LOCAL_MACHINE,
108 HKEY_CURRENT_USER,
109 HKEY_USERS):
Greg Ward1b9c6f72000-02-08 02:39:44 +0000110 try:
Greg Ward1027e3f2000-03-31 16:53:42 +0000111 k = RegOpenKeyEx(base,K)
Greg Ward1b9c6f72000-02-08 02:39:44 +0000112 i = 0
113 while 1:
114 try:
Greg Ward1027e3f2000-03-31 16:53:42 +0000115 (p,v,t) = RegEnumValue(k,i)
Greg Ward62e33932000-02-10 02:52:42 +0000116 if string.upper(p) == path:
Greg Ward1b9c6f72000-02-08 02:39:44 +0000117 V = string.split(v,';')
118 for v in V:
Greg Ward62e33932000-02-10 02:52:42 +0000119 if v == '' or v in L: continue
Greg Ward1b9c6f72000-02-08 02:39:44 +0000120 L.append(v)
121 break
122 i = i + 1
Greg Ward1027e3f2000-03-31 16:53:42 +0000123 except RegError:
Greg Ward1b9c6f72000-02-08 02:39:44 +0000124 break
Greg Ward1027e3f2000-03-31 16:53:42 +0000125 except RegError:
Greg Ward1b9c6f72000-02-08 02:39:44 +0000126 pass
127 return L
128
Greg Ward62e33932000-02-10 02:52:42 +0000129# get_msvc_paths()
130
131
Greg Ward69988092000-02-11 02:47:15 +0000132def find_exe (exe, version_number):
133 """Try to find an MSVC executable program 'exe' (from version
134 'version_number' of MSVC) in several places: first, one of the MSVC
135 program search paths from the registry; next, the directories in the
136 PATH environment variable. If any of those work, return an absolute
137 path that is known to exist. If none of them work, just return the
138 original program name, 'exe'."""
Greg Ward1b9c6f72000-02-08 02:39:44 +0000139
Greg Ward69988092000-02-11 02:47:15 +0000140 for p in get_msvc_paths ('path', version_number):
141 fn = os.path.join (os.path.abspath(p), exe)
142 if os.path.isfile(fn):
143 return fn
144
145 # didn't find it; try existing path
146 for p in string.split (os.environ['Path'],';'):
147 fn = os.path.join(os.path.abspath(p),exe)
148 if os.path.isfile(fn):
149 return fn
150
151 return exe # last desperate hope
Greg Ward1b9c6f72000-02-08 02:39:44 +0000152
Greg Ward62e33932000-02-10 02:52:42 +0000153
Greg Ward5de8cee2000-02-11 02:52:39 +0000154def set_path_env_var (name, version_number):
155 """Set environment variable 'name' to an MSVC path type value obtained
156 from 'get_msvc_paths()'. This is equivalent to a SET command prior
157 to execution of spawned commands."""
Greg Ward69988092000-02-11 02:47:15 +0000158
Greg Ward5de8cee2000-02-11 02:52:39 +0000159 p = get_msvc_paths (name, version_number)
Greg Ward62e33932000-02-10 02:52:42 +0000160 if p:
Greg Ward5de8cee2000-02-11 02:52:39 +0000161 os.environ[name] = string.join (p,';')
Greg Ward62e33932000-02-10 02:52:42 +0000162
Greg Warddbd12761999-08-29 18:15:07 +0000163
Greg Ward3d50b901999-09-08 02:36:01 +0000164class MSVCCompiler (CCompiler) :
165 """Concrete class that implements an interface to Microsoft Visual C++,
166 as defined by the CCompiler abstract class."""
Greg Warddbd12761999-08-29 18:15:07 +0000167
Greg Warddf178f91999-09-29 12:29:10 +0000168 compiler_type = 'msvc'
169
Greg Ward32c4a8a2000-03-06 03:40:29 +0000170 # Private class data (need to distinguish C from C++ source for compiler)
171 _c_extensions = ['.c']
172 _cpp_extensions = ['.cc','.cpp']
173
174 # Needed for the filename generation methods provided by the
175 # base class, CCompiler.
176 src_extensions = _c_extensions + _cpp_extensions
177 obj_extension = '.obj'
178 static_lib_extension = '.lib'
179 shared_lib_extension = '.dll'
180 static_lib_format = shared_lib_format = '%s%s'
181 exe_extension = '.exe'
182
183
Greg Warddbd12761999-08-29 18:15:07 +0000184 def __init__ (self,
185 verbose=0,
Greg Wardc74138d1999-10-03 20:47:52 +0000186 dry_run=0,
187 force=0):
Greg Warddbd12761999-08-29 18:15:07 +0000188
Greg Wardc74138d1999-10-03 20:47:52 +0000189 CCompiler.__init__ (self, verbose, dry_run, force)
Greg Ward5de8cee2000-02-11 02:52:39 +0000190 versions = get_devstudio_versions ()
Greg Ward69988092000-02-11 02:47:15 +0000191
Greg Ward5de8cee2000-02-11 02:52:39 +0000192 if versions:
193 version = versions[0] # highest version
Greg Ward69988092000-02-11 02:47:15 +0000194
Greg Ward41b4dd62000-03-29 04:13:00 +0000195 self.cc = find_exe("cl.exe", version)
196 self.link = find_exe("link.exe", version)
197 self.lib = find_exe("lib.exe", version)
Greg Ward5de8cee2000-02-11 02:52:39 +0000198 set_path_env_var ('lib', version)
199 set_path_env_var ('include', version)
200 path=get_msvc_paths('path', version)
Greg Ward69988092000-02-11 02:47:15 +0000201 try:
202 for p in string.split(os.environ['path'],';'):
203 path.append(p)
204 except KeyError:
205 pass
206 os.environ['path'] = string.join(path,';')
207 else:
208 # devstudio not found in the registry
209 self.cc = "cl.exe"
210 self.link = "link.exe"
Greg Ward09fc5422000-03-10 01:49:26 +0000211 self.lib = "lib.exe"
Greg Ward69988092000-02-11 02:47:15 +0000212
Greg Warddbd12761999-08-29 18:15:07 +0000213 self.preprocess_options = None
Greg Ward69988092000-02-11 02:47:15 +0000214 self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3' ]
Greg Ward32c4a8a2000-03-06 03:40:29 +0000215 self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/Z7', '/D_DEBUG']
Greg Warddbd12761999-08-29 18:15:07 +0000216
Greg Ward1b9c6f72000-02-08 02:39:44 +0000217 self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000218 self.ldflags_shared_debug = [
219 '/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG'
220 ]
Greg Warddbd12761999-08-29 18:15:07 +0000221 self.ldflags_static = [ '/nologo']
222
Greg Warddbd12761999-08-29 18:15:07 +0000223
224 # -- Worker methods ------------------------------------------------
Greg Warddbd12761999-08-29 18:15:07 +0000225
Greg Warddbd12761999-08-29 18:15:07 +0000226 def compile (self,
227 sources,
Greg Warddf178f91999-09-29 12:29:10 +0000228 output_dir=None,
Greg Warddbd12761999-08-29 18:15:07 +0000229 macros=None,
Greg Ward0bdd90a1999-12-12 17:19:58 +0000230 include_dirs=None,
Greg Ward386b8442000-02-09 02:18:39 +0000231 debug=0,
Greg Warddf178f91999-09-29 12:29:10 +0000232 extra_preargs=None,
233 extra_postargs=None):
Greg Warddbd12761999-08-29 18:15:07 +0000234
Greg Ward32c4a8a2000-03-06 03:40:29 +0000235 (output_dir, macros, include_dirs) = \
236 self._fix_compile_args (output_dir, macros, include_dirs)
237 (objects, skip_sources) = self._prep_compile (sources, output_dir)
Greg Warddbd12761999-08-29 18:15:07 +0000238
Greg Ward32c4a8a2000-03-06 03:40:29 +0000239 if extra_postargs is None:
240 extra_postargs = []
Greg Warddbd12761999-08-29 18:15:07 +0000241
Greg Ward32c4a8a2000-03-06 03:40:29 +0000242 pp_opts = gen_preprocess_options (macros, include_dirs)
243 compile_opts = extra_preargs or []
244 compile_opts.append ('/c')
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000245 if debug:
Greg Ward32c4a8a2000-03-06 03:40:29 +0000246 compile_opts.extend (self.compile_options_debug)
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000247 else:
Greg Ward32c4a8a2000-03-06 03:40:29 +0000248 compile_opts.extend (self.compile_options)
Greg Warddbd12761999-08-29 18:15:07 +0000249
Greg Ward32c4a8a2000-03-06 03:40:29 +0000250 for i in range (len (sources)):
251 src = sources[i] ; obj = objects[i]
252 ext = (os.path.splitext (src))[1]
Greg Warddbd12761999-08-29 18:15:07 +0000253
Greg Ward32c4a8a2000-03-06 03:40:29 +0000254 if skip_sources[src]:
255 self.announce ("skipping %s (%s up-to-date)" % (src, obj))
256 else:
257 if ext in self._c_extensions:
258 input_opt = "/Tc" + src
259 elif ext in self._cpp_extensions:
260 input_opt = "/Tp" + src
Greg Warddbd12761999-08-29 18:15:07 +0000261
Greg Ward32c4a8a2000-03-06 03:40:29 +0000262 output_opt = "/Fo" + obj
Greg Warddbd12761999-08-29 18:15:07 +0000263
Greg Ward32c4a8a2000-03-06 03:40:29 +0000264 self.mkpath (os.path.dirname (obj))
Greg Wardd1517112000-05-30 01:56:44 +0000265 try:
266 self.spawn ([self.cc] + compile_opts + pp_opts +
267 [input_opt, output_opt] +
268 extra_postargs)
269 except DistutilsExecError, msg:
270 raise CompileError, msg
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000271
Greg Ward32c4a8a2000-03-06 03:40:29 +0000272 return objects
Greg Warddbd12761999-08-29 18:15:07 +0000273
Greg Ward32c4a8a2000-03-06 03:40:29 +0000274 # compile ()
Greg Ward3d50b901999-09-08 02:36:01 +0000275
276
Greg Ward09fc5422000-03-10 01:49:26 +0000277 def create_static_lib (self,
278 objects,
279 output_libname,
280 output_dir=None,
281 debug=0,
282 extra_preargs=None,
283 extra_postargs=None):
Greg Warddbd12761999-08-29 18:15:07 +0000284
Greg Ward2f557a22000-03-26 21:42:28 +0000285 (objects, output_dir) = self._fix_object_args (objects, output_dir)
Greg Ward32c4a8a2000-03-06 03:40:29 +0000286 output_filename = \
287 self.library_filename (output_libname, output_dir=output_dir)
Greg Warddbd12761999-08-29 18:15:07 +0000288
Greg Ward32c4a8a2000-03-06 03:40:29 +0000289 if self._need_link (objects, output_filename):
Greg Ward09fc5422000-03-10 01:49:26 +0000290 lib_args = objects + ['/OUT:' + output_filename]
Greg Ward32c4a8a2000-03-06 03:40:29 +0000291 if debug:
292 pass # XXX what goes here?
293 if extra_preargs:
Greg Ward09fc5422000-03-10 01:49:26 +0000294 lib_args[:0] = extra_preargs
Greg Ward32c4a8a2000-03-06 03:40:29 +0000295 if extra_postargs:
Greg Ward09fc5422000-03-10 01:49:26 +0000296 lib_args.extend (extra_postargs)
Greg Wardd1517112000-05-30 01:56:44 +0000297 try:
298 self.spawn ([self.link] + ld_args)
299 except DistutilsExecError, msg:
300 raise LibError, msg
301
Greg Ward32c4a8a2000-03-06 03:40:29 +0000302 else:
303 self.announce ("skipping %s (up-to-date)" % output_filename)
Greg Warddbd12761999-08-29 18:15:07 +0000304
Greg Ward09fc5422000-03-10 01:49:26 +0000305 # create_static_lib ()
Greg Warddbd12761999-08-29 18:15:07 +0000306
307
308 def link_shared_lib (self,
309 objects,
310 output_libname,
Greg Warddf178f91999-09-29 12:29:10 +0000311 output_dir=None,
Greg Warddbd12761999-08-29 18:15:07 +0000312 libraries=None,
313 library_dirs=None,
Greg Ward2f557a22000-03-26 21:42:28 +0000314 runtime_library_dirs=None,
Greg Ward5299b6a2000-05-20 13:23:21 +0000315 export_symbols=None,
Greg Ward386b8442000-02-09 02:18:39 +0000316 debug=0,
Greg Warddf178f91999-09-29 12:29:10 +0000317 extra_preargs=None,
318 extra_postargs=None):
319
Greg Warddf178f91999-09-29 12:29:10 +0000320 self.link_shared_object (objects,
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000321 self.shared_library_name(output_libname),
322 output_dir=output_dir,
323 libraries=libraries,
324 library_dirs=library_dirs,
Greg Ward5299b6a2000-05-20 13:23:21 +0000325 runtime_library_dirs=runtime_library_dirs,
326 export_symbols=export_symbols,
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000327 debug=debug,
328 extra_preargs=extra_preargs,
329 extra_postargs=extra_postargs)
330
Greg Warddbd12761999-08-29 18:15:07 +0000331
332 def link_shared_object (self,
333 objects,
334 output_filename,
Greg Warddf178f91999-09-29 12:29:10 +0000335 output_dir=None,
Greg Warddbd12761999-08-29 18:15:07 +0000336 libraries=None,
337 library_dirs=None,
Greg Ward2f557a22000-03-26 21:42:28 +0000338 runtime_library_dirs=None,
Greg Ward5299b6a2000-05-20 13:23:21 +0000339 export_symbols=None,
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000340 debug=0,
Greg Warddf178f91999-09-29 12:29:10 +0000341 extra_preargs=None,
342 extra_postargs=None):
Greg Ward32c4a8a2000-03-06 03:40:29 +0000343
Greg Ward2f557a22000-03-26 21:42:28 +0000344 (objects, output_dir) = self._fix_object_args (objects, output_dir)
345 (libraries, library_dirs, runtime_library_dirs) = \
346 self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
347
Greg Wardf70c6032000-04-19 02:16:49 +0000348 if runtime_library_dirs:
Greg Ward2f557a22000-03-26 21:42:28 +0000349 self.warn ("I don't know what to do with 'runtime_library_dirs': "
350 + str (runtime_library_dirs))
Greg Warddbd12761999-08-29 18:15:07 +0000351
Greg Wardd03f88a2000-03-18 15:19:51 +0000352 lib_opts = gen_lib_options (self,
Greg Ward2f557a22000-03-26 21:42:28 +0000353 library_dirs, runtime_library_dirs,
Greg Wardd03f88a2000-03-18 15:19:51 +0000354 libraries)
Greg Ward32c4a8a2000-03-06 03:40:29 +0000355 if output_dir is not None:
356 output_filename = os.path.join (output_dir, output_filename)
Greg Warddbd12761999-08-29 18:15:07 +0000357
Greg Ward32c4a8a2000-03-06 03:40:29 +0000358 if self._need_link (objects, output_filename):
359
360 if debug:
361 ldflags = self.ldflags_shared_debug
Greg Ward32c4a8a2000-03-06 03:40:29 +0000362 else:
363 ldflags = self.ldflags_shared
364
Greg Ward5299b6a2000-05-20 13:23:21 +0000365 export_opts = []
366 for sym in (export_symbols or []):
367 export_opts.append("/EXPORT:" + sym)
368
369 ld_args = (ldflags + lib_opts + export_opts +
370 objects + ['/OUT:' + output_filename])
Greg Ward32c4a8a2000-03-06 03:40:29 +0000371
372 if extra_preargs:
373 ld_args[:0] = extra_preargs
374 if extra_postargs:
375 ld_args.extend (extra_postargs)
376
Greg Ward02a1a2b2000-04-15 22:15:07 +0000377 print "link_shared_object():"
378 print " output_filename =", output_filename
379 print " mkpath'ing:", os.path.dirname (output_filename)
Greg Ward32c4a8a2000-03-06 03:40:29 +0000380 self.mkpath (os.path.dirname (output_filename))
Greg Wardd1517112000-05-30 01:56:44 +0000381 try:
382 self.spawn ([self.link] + ld_args)
383 except DistutilsExecError, msg:
384 raise LinkError, msg
Greg Ward32c4a8a2000-03-06 03:40:29 +0000385
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000386 else:
Greg Ward32c4a8a2000-03-06 03:40:29 +0000387 self.announce ("skipping %s (up-to-date)" % output_filename)
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000388
Greg Ward32c4a8a2000-03-06 03:40:29 +0000389 # link_shared_object ()
Greg Wardf70c6032000-04-19 02:16:49 +0000390
391
392 def link_executable (self,
393 objects,
394 output_progname,
395 output_dir=None,
396 libraries=None,
397 library_dirs=None,
398 runtime_library_dirs=None,
399 debug=0,
400 extra_preargs=None,
401 extra_postargs=None):
402
403 (objects, output_dir) = self._fix_object_args (objects, output_dir)
404 (libraries, library_dirs, runtime_library_dirs) = \
405 self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
406
407 if runtime_library_dirs:
408 self.warn ("I don't know what to do with 'runtime_library_dirs': "
409 + str (runtime_library_dirs))
410
411 lib_opts = gen_lib_options (self,
412 library_dirs, runtime_library_dirs,
413 libraries)
414 output_filename = output_progname + self.exe_extension
415 if output_dir is not None:
416 output_filename = os.path.join (output_dir, output_filename)
417
418 if self._need_link (objects, output_filename):
419
420 if debug:
421 ldflags = self.ldflags_shared_debug[1:]
422 else:
423 ldflags = self.ldflags_shared[1:]
424
425 ld_args = ldflags + lib_opts + \
426 objects + ['/OUT:' + output_filename]
427
428 if extra_preargs:
429 ld_args[:0] = extra_preargs
430 if extra_postargs:
431 ld_args.extend (extra_postargs)
432
433 self.mkpath (os.path.dirname (output_filename))
Greg Wardd1517112000-05-30 01:56:44 +0000434 try:
435 self.spawn ([self.link] + ld_args)
436 except DistutilsExecError, msg:
437 raise LinkError, msg
Greg Wardf70c6032000-04-19 02:16:49 +0000438 else:
439 self.announce ("skipping %s (up-to-date)" % output_filename)
Greg Ward32c4a8a2000-03-06 03:40:29 +0000440
Greg Ward4ba9b2e2000-02-10 02:15:52 +0000441
Greg Ward32c4a8a2000-03-06 03:40:29 +0000442 # -- Miscellaneous methods -----------------------------------------
443 # These are all used by the 'gen_lib_options() function, in
444 # ccompiler.py.
Greg Wardc74138d1999-10-03 20:47:52 +0000445
446 def library_dir_option (self, dir):
447 return "/LIBPATH:" + dir
448
Greg Wardd03f88a2000-03-18 15:19:51 +0000449 def runtime_library_dir_option (self, dir):
450 raise DistutilsPlatformError, \
451 "don't know how to set runtime library search path for MSVC++"
452
Greg Wardc74138d1999-10-03 20:47:52 +0000453 def library_option (self, lib):
454 return self.library_filename (lib)
455
456
457 def find_library_file (self, dirs, lib):
458
459 for dir in dirs:
460 libfile = os.path.join (dir, self.library_filename (lib))
461 if os.path.exists (libfile):
462 return libfile
463
464 else:
465 # Oops, didn't find it in *any* of 'dirs'
466 return None
467
468 # find_library_file ()
469
Greg Warddbd12761999-08-29 18:15:07 +0000470# class MSVCCompiler