2000-06-28 01:29:09 +00:00
|
|
|
"""distutils.msvccompiler
|
1999-08-29 18:15:07 +00:00
|
|
|
|
|
|
|
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
1999-09-29 12:29:10 +00:00
|
|
|
for the Microsoft Visual Studio."""
|
1999-08-29 18:15:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
# created 1999/08/19, Perry Stoll
|
2000-03-06 03:40:29 +00:00
|
|
|
# hacked by Robin Becker and Thomas Heller to do a better job of
|
|
|
|
# finding DevStudio (through the registry)
|
|
|
|
|
2000-03-02 01:49:45 +00:00
|
|
|
__revision__ = "$Id$"
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
import sys, os, string
|
|
|
|
from types import *
|
2000-05-30 02:02:49 +00:00
|
|
|
from distutils.errors import \
|
|
|
|
DistutilsExecError, DistutilsPlatformError, \
|
2000-05-30 01:56:44 +00:00
|
|
|
CompileError, LibError, LinkError
|
2000-05-30 02:02:49 +00:00
|
|
|
from distutils.ccompiler import \
|
|
|
|
CCompiler, gen_preprocess_options, gen_lib_options
|
2000-02-10 02:52:42 +00:00
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
_can_read_reg = 0
|
|
|
|
try:
|
2000-06-30 19:37:59 +00:00
|
|
|
import _winreg
|
2000-06-29 23:04:59 +00:00
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
_can_read_reg = 1
|
2000-06-29 22:59:10 +00:00
|
|
|
hkey_mod = _winreg
|
2000-03-31 19:04:25 +00:00
|
|
|
|
2000-06-29 22:59:10 +00:00
|
|
|
RegOpenKeyEx = _winreg.OpenKeyEx
|
|
|
|
RegEnumKey = _winreg.EnumKey
|
|
|
|
RegEnumValue = _winreg.EnumValue
|
|
|
|
RegError = _winreg.error
|
2000-03-31 19:04:25 +00:00
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
except ImportError:
|
|
|
|
try:
|
|
|
|
import win32api
|
|
|
|
import win32con
|
|
|
|
_can_read_reg = 1
|
2000-03-31 16:53:42 +00:00
|
|
|
hkey_mod = win32con
|
2000-03-31 19:04:25 +00:00
|
|
|
|
|
|
|
RegOpenKeyEx = win32api.RegOpenKeyEx
|
|
|
|
RegEnumKey = win32api.RegEnumKey
|
|
|
|
RegEnumValue = win32api.RegEnumValue
|
|
|
|
RegError = win32api.error
|
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
except ImportError:
|
|
|
|
pass
|
2000-03-31 16:53:42 +00:00
|
|
|
|
|
|
|
if _can_read_reg:
|
|
|
|
HKEY_CLASSES_ROOT = hkey_mod.HKEY_CLASSES_ROOT
|
|
|
|
HKEY_LOCAL_MACHINE = hkey_mod.HKEY_LOCAL_MACHINE
|
|
|
|
HKEY_CURRENT_USER = hkey_mod.HKEY_CURRENT_USER
|
|
|
|
HKEY_USERS = hkey_mod.HKEY_USERS
|
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
|
|
|
|
|
2000-02-10 02:52:42 +00:00
|
|
|
def get_devstudio_versions ():
|
|
|
|
"""Get list of devstudio versions from the Windows registry. Return a
|
2000-02-11 02:47:15 +00:00
|
|
|
list of strings containing version numbers; the list will be
|
2000-02-10 02:52:42 +00:00
|
|
|
empty if we were unable to access the registry (eg. couldn't import
|
|
|
|
a registry-access module) or the appropriate registry keys weren't
|
2000-02-11 02:47:15 +00:00
|
|
|
found."""
|
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
if not _can_read_reg:
|
2000-02-10 02:52:42 +00:00
|
|
|
return []
|
2000-02-08 02:39:44 +00:00
|
|
|
|
|
|
|
K = 'Software\\Microsoft\\Devstudio'
|
|
|
|
L = []
|
2000-03-31 16:53:42 +00:00
|
|
|
for base in (HKEY_CLASSES_ROOT,
|
|
|
|
HKEY_LOCAL_MACHINE,
|
|
|
|
HKEY_CURRENT_USER,
|
|
|
|
HKEY_USERS):
|
2000-02-08 02:39:44 +00:00
|
|
|
try:
|
2000-03-31 16:53:42 +00:00
|
|
|
k = RegOpenKeyEx(base,K)
|
2000-02-08 02:39:44 +00:00
|
|
|
i = 0
|
|
|
|
while 1:
|
|
|
|
try:
|
2000-03-31 16:53:42 +00:00
|
|
|
p = RegEnumKey(k,i)
|
2000-02-08 02:39:44 +00:00
|
|
|
if p[0] in '123456789' and p not in L:
|
|
|
|
L.append(p)
|
2000-03-31 16:53:42 +00:00
|
|
|
except RegError:
|
2000-02-08 02:39:44 +00:00
|
|
|
break
|
|
|
|
i = i + 1
|
2000-03-31 16:53:42 +00:00
|
|
|
except RegError:
|
2000-02-08 02:39:44 +00:00
|
|
|
pass
|
|
|
|
L.sort()
|
|
|
|
L.reverse()
|
|
|
|
return L
|
|
|
|
|
2000-02-10 02:52:42 +00:00
|
|
|
# get_devstudio_versions ()
|
|
|
|
|
|
|
|
|
|
|
|
def get_msvc_paths (path, version='6.0', platform='x86'):
|
2000-02-11 02:47:15 +00:00
|
|
|
"""Get a list of devstudio directories (include, lib or path). Return
|
|
|
|
a list of strings; will be empty list if unable to access the
|
|
|
|
registry or appropriate registry keys not found."""
|
|
|
|
|
2000-03-31 16:47:40 +00:00
|
|
|
if not _can_read_reg:
|
2000-02-11 02:47:15 +00:00
|
|
|
return []
|
2000-02-08 02:39:44 +00:00
|
|
|
|
|
|
|
L = []
|
2000-02-10 02:52:42 +00:00
|
|
|
if path=='lib':
|
|
|
|
path= 'Library'
|
2000-02-08 02:39:44 +00:00
|
|
|
path = string.upper(path + ' Dirs')
|
2000-02-10 02:52:42 +00:00
|
|
|
K = ('Software\\Microsoft\\Devstudio\\%s\\' +
|
|
|
|
'Build System\\Components\\Platforms\\Win32 (%s)\\Directories') % \
|
|
|
|
(version,platform)
|
2000-03-31 16:53:42 +00:00
|
|
|
for base in (HKEY_CLASSES_ROOT,
|
|
|
|
HKEY_LOCAL_MACHINE,
|
|
|
|
HKEY_CURRENT_USER,
|
|
|
|
HKEY_USERS):
|
2000-02-08 02:39:44 +00:00
|
|
|
try:
|
2000-03-31 16:53:42 +00:00
|
|
|
k = RegOpenKeyEx(base,K)
|
2000-02-08 02:39:44 +00:00
|
|
|
i = 0
|
|
|
|
while 1:
|
|
|
|
try:
|
2000-03-31 16:53:42 +00:00
|
|
|
(p,v,t) = RegEnumValue(k,i)
|
2000-02-10 02:52:42 +00:00
|
|
|
if string.upper(p) == path:
|
2000-02-08 02:39:44 +00:00
|
|
|
V = string.split(v,';')
|
|
|
|
for v in V:
|
2000-02-10 02:52:42 +00:00
|
|
|
if v == '' or v in L: continue
|
2000-02-08 02:39:44 +00:00
|
|
|
L.append(v)
|
|
|
|
break
|
|
|
|
i = i + 1
|
2000-03-31 16:53:42 +00:00
|
|
|
except RegError:
|
2000-02-08 02:39:44 +00:00
|
|
|
break
|
2000-03-31 16:53:42 +00:00
|
|
|
except RegError:
|
2000-02-08 02:39:44 +00:00
|
|
|
pass
|
|
|
|
return L
|
|
|
|
|
2000-02-10 02:52:42 +00:00
|
|
|
# get_msvc_paths()
|
|
|
|
|
|
|
|
|
2000-02-11 02:47:15 +00:00
|
|
|
def find_exe (exe, version_number):
|
|
|
|
"""Try to find an MSVC executable program 'exe' (from version
|
|
|
|
'version_number' of MSVC) in several places: first, one of the MSVC
|
|
|
|
program search paths from the registry; next, the directories in the
|
|
|
|
PATH environment variable. If any of those work, return an absolute
|
|
|
|
path that is known to exist. If none of them work, just return the
|
|
|
|
original program name, 'exe'."""
|
2000-02-08 02:39:44 +00:00
|
|
|
|
2000-02-11 02:47:15 +00:00
|
|
|
for p in get_msvc_paths ('path', version_number):
|
|
|
|
fn = os.path.join (os.path.abspath(p), exe)
|
|
|
|
if os.path.isfile(fn):
|
|
|
|
return fn
|
|
|
|
|
|
|
|
# didn't find it; try existing path
|
|
|
|
for p in string.split (os.environ['Path'],';'):
|
|
|
|
fn = os.path.join(os.path.abspath(p),exe)
|
|
|
|
if os.path.isfile(fn):
|
|
|
|
return fn
|
|
|
|
|
|
|
|
return exe # last desperate hope
|
|
|
|
|
|
|
|
|
2000-02-11 02:52:39 +00:00
|
|
|
def set_path_env_var (name, version_number):
|
|
|
|
"""Set environment variable 'name' to an MSVC path type value obtained
|
|
|
|
from 'get_msvc_paths()'. This is equivalent to a SET command prior
|
|
|
|
to execution of spawned commands."""
|
2000-02-11 02:47:15 +00:00
|
|
|
|
2000-02-11 02:52:39 +00:00
|
|
|
p = get_msvc_paths (name, version_number)
|
2000-02-10 02:52:42 +00:00
|
|
|
if p:
|
2000-02-11 02:52:39 +00:00
|
|
|
os.environ[name] = string.join (p,';')
|
2000-02-10 02:52:42 +00:00
|
|
|
|
1999-08-29 18:15:07 +00:00
|
|
|
|
1999-09-08 02:36:01 +00:00
|
|
|
class MSVCCompiler (CCompiler) :
|
|
|
|
"""Concrete class that implements an interface to Microsoft Visual C++,
|
|
|
|
as defined by the CCompiler abstract class."""
|
1999-08-29 18:15:07 +00:00
|
|
|
|
1999-09-29 12:29:10 +00:00
|
|
|
compiler_type = 'msvc'
|
|
|
|
|
2000-06-25 02:31:16 +00:00
|
|
|
# Just set this so CCompiler's constructor doesn't barf. We currently
|
|
|
|
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
|
|
|
# as it really isn't necessary for this sort of single-compiler class.
|
|
|
|
# Would be nice to have a consistent interface with UnixCCompiler,
|
|
|
|
# though, so it's worth thinking about.
|
|
|
|
executables = {}
|
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
# Private class data (need to distinguish C from C++ source for compiler)
|
|
|
|
_c_extensions = ['.c']
|
|
|
|
_cpp_extensions = ['.cc','.cpp']
|
|
|
|
|
|
|
|
# Needed for the filename generation methods provided by the
|
|
|
|
# base class, CCompiler.
|
|
|
|
src_extensions = _c_extensions + _cpp_extensions
|
|
|
|
obj_extension = '.obj'
|
|
|
|
static_lib_extension = '.lib'
|
|
|
|
shared_lib_extension = '.dll'
|
|
|
|
static_lib_format = shared_lib_format = '%s%s'
|
|
|
|
exe_extension = '.exe'
|
|
|
|
|
|
|
|
|
1999-08-29 18:15:07 +00:00
|
|
|
def __init__ (self,
|
|
|
|
verbose=0,
|
1999-10-03 20:47:52 +00:00
|
|
|
dry_run=0,
|
|
|
|
force=0):
|
1999-08-29 18:15:07 +00:00
|
|
|
|
1999-10-03 20:47:52 +00:00
|
|
|
CCompiler.__init__ (self, verbose, dry_run, force)
|
2000-02-11 02:52:39 +00:00
|
|
|
versions = get_devstudio_versions ()
|
2000-02-11 02:47:15 +00:00
|
|
|
|
2000-02-11 02:52:39 +00:00
|
|
|
if versions:
|
|
|
|
version = versions[0] # highest version
|
2000-02-11 02:47:15 +00:00
|
|
|
|
2000-03-29 04:13:00 +00:00
|
|
|
self.cc = find_exe("cl.exe", version)
|
|
|
|
self.link = find_exe("link.exe", version)
|
|
|
|
self.lib = find_exe("lib.exe", version)
|
2000-02-11 02:52:39 +00:00
|
|
|
set_path_env_var ('lib', version)
|
|
|
|
set_path_env_var ('include', version)
|
|
|
|
path=get_msvc_paths('path', version)
|
2000-02-11 02:47:15 +00:00
|
|
|
try:
|
|
|
|
for p in string.split(os.environ['path'],';'):
|
|
|
|
path.append(p)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
os.environ['path'] = string.join(path,';')
|
|
|
|
else:
|
|
|
|
# devstudio not found in the registry
|
|
|
|
self.cc = "cl.exe"
|
|
|
|
self.link = "link.exe"
|
2000-03-10 01:49:26 +00:00
|
|
|
self.lib = "lib.exe"
|
2000-02-11 02:47:15 +00:00
|
|
|
|
1999-08-29 18:15:07 +00:00
|
|
|
self.preprocess_options = None
|
2000-02-11 02:47:15 +00:00
|
|
|
self.compile_options = [ '/nologo', '/Ox', '/MD', '/W3' ]
|
2000-03-06 03:40:29 +00:00
|
|
|
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/Z7', '/D_DEBUG']
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-02-08 02:39:44 +00:00
|
|
|
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
2000-02-10 02:15:52 +00:00
|
|
|
self.ldflags_shared_debug = [
|
|
|
|
'/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG'
|
|
|
|
]
|
1999-08-29 18:15:07 +00:00
|
|
|
self.ldflags_static = [ '/nologo']
|
|
|
|
|
|
|
|
|
|
|
|
# -- Worker methods ------------------------------------------------
|
|
|
|
|
|
|
|
def compile (self,
|
|
|
|
sources,
|
1999-09-29 12:29:10 +00:00
|
|
|
output_dir=None,
|
1999-08-29 18:15:07 +00:00
|
|
|
macros=None,
|
1999-12-12 17:19:58 +00:00
|
|
|
include_dirs=None,
|
2000-02-09 02:18:39 +00:00
|
|
|
debug=0,
|
1999-09-29 12:29:10 +00:00
|
|
|
extra_preargs=None,
|
|
|
|
extra_postargs=None):
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
(output_dir, macros, include_dirs) = \
|
|
|
|
self._fix_compile_args (output_dir, macros, include_dirs)
|
|
|
|
(objects, skip_sources) = self._prep_compile (sources, output_dir)
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
if extra_postargs is None:
|
|
|
|
extra_postargs = []
|
2000-02-10 02:15:52 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
pp_opts = gen_preprocess_options (macros, include_dirs)
|
|
|
|
compile_opts = extra_preargs or []
|
|
|
|
compile_opts.append ('/c')
|
2000-02-10 02:15:52 +00:00
|
|
|
if debug:
|
2000-03-06 03:40:29 +00:00
|
|
|
compile_opts.extend (self.compile_options_debug)
|
2000-02-10 02:15:52 +00:00
|
|
|
else:
|
2000-03-06 03:40:29 +00:00
|
|
|
compile_opts.extend (self.compile_options)
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
for i in range (len (sources)):
|
|
|
|
src = sources[i] ; obj = objects[i]
|
|
|
|
ext = (os.path.splitext (src))[1]
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
if skip_sources[src]:
|
|
|
|
self.announce ("skipping %s (%s up-to-date)" % (src, obj))
|
|
|
|
else:
|
|
|
|
if ext in self._c_extensions:
|
|
|
|
input_opt = "/Tc" + src
|
|
|
|
elif ext in self._cpp_extensions:
|
|
|
|
input_opt = "/Tp" + src
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
output_opt = "/Fo" + obj
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
self.mkpath (os.path.dirname (obj))
|
2000-05-30 01:56:44 +00:00
|
|
|
try:
|
|
|
|
self.spawn ([self.cc] + compile_opts + pp_opts +
|
|
|
|
[input_opt, output_opt] +
|
|
|
|
extra_postargs)
|
|
|
|
except DistutilsExecError, msg:
|
|
|
|
raise CompileError, msg
|
2000-02-10 02:15:52 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
return objects
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
# compile ()
|
1999-09-08 02:36:01 +00:00
|
|
|
|
|
|
|
|
2000-03-10 01:49:26 +00:00
|
|
|
def create_static_lib (self,
|
|
|
|
objects,
|
|
|
|
output_libname,
|
|
|
|
output_dir=None,
|
|
|
|
debug=0,
|
|
|
|
extra_preargs=None,
|
|
|
|
extra_postargs=None):
|
1999-09-29 12:29:10 +00:00
|
|
|
|
2000-03-26 21:42:28 +00:00
|
|
|
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
2000-03-06 03:40:29 +00:00
|
|
|
output_filename = \
|
|
|
|
self.library_filename (output_libname, output_dir=output_dir)
|
|
|
|
|
|
|
|
if self._need_link (objects, output_filename):
|
2000-03-10 01:49:26 +00:00
|
|
|
lib_args = objects + ['/OUT:' + output_filename]
|
2000-03-06 03:40:29 +00:00
|
|
|
if debug:
|
|
|
|
pass # XXX what goes here?
|
|
|
|
if extra_preargs:
|
2000-03-10 01:49:26 +00:00
|
|
|
lib_args[:0] = extra_preargs
|
2000-03-06 03:40:29 +00:00
|
|
|
if extra_postargs:
|
2000-03-10 01:49:26 +00:00
|
|
|
lib_args.extend (extra_postargs)
|
2000-05-30 01:56:44 +00:00
|
|
|
try:
|
2000-06-25 02:31:16 +00:00
|
|
|
self.spawn ([self.lib] + lib_args)
|
2000-05-30 01:56:44 +00:00
|
|
|
except DistutilsExecError, msg:
|
|
|
|
raise LibError, msg
|
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
else:
|
|
|
|
self.announce ("skipping %s (up-to-date)" % output_filename)
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-10 01:49:26 +00:00
|
|
|
# create_static_lib ()
|
1999-08-29 18:15:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def link_shared_lib (self,
|
|
|
|
objects,
|
|
|
|
output_libname,
|
1999-09-29 12:29:10 +00:00
|
|
|
output_dir=None,
|
1999-08-29 18:15:07 +00:00
|
|
|
libraries=None,
|
|
|
|
library_dirs=None,
|
2000-03-26 21:42:28 +00:00
|
|
|
runtime_library_dirs=None,
|
2000-05-20 13:23:21 +00:00
|
|
|
export_symbols=None,
|
2000-02-09 02:18:39 +00:00
|
|
|
debug=0,
|
1999-09-29 12:29:10 +00:00
|
|
|
extra_preargs=None,
|
2000-06-28 01:29:09 +00:00
|
|
|
extra_postargs=None,
|
|
|
|
build_temp=None):
|
1999-09-29 12:29:10 +00:00
|
|
|
|
|
|
|
self.link_shared_object (objects,
|
2000-02-10 02:15:52 +00:00
|
|
|
self.shared_library_name(output_libname),
|
|
|
|
output_dir=output_dir,
|
|
|
|
libraries=libraries,
|
|
|
|
library_dirs=library_dirs,
|
2000-05-20 13:23:21 +00:00
|
|
|
runtime_library_dirs=runtime_library_dirs,
|
|
|
|
export_symbols=export_symbols,
|
2000-02-10 02:15:52 +00:00
|
|
|
debug=debug,
|
|
|
|
extra_preargs=extra_preargs,
|
2000-06-28 01:29:09 +00:00
|
|
|
extra_postargs=extra_postargs,
|
|
|
|
build_temp=build_temp)
|
2000-02-10 02:15:52 +00:00
|
|
|
|
1999-08-29 18:15:07 +00:00
|
|
|
|
|
|
|
def link_shared_object (self,
|
|
|
|
objects,
|
|
|
|
output_filename,
|
1999-09-29 12:29:10 +00:00
|
|
|
output_dir=None,
|
1999-08-29 18:15:07 +00:00
|
|
|
libraries=None,
|
|
|
|
library_dirs=None,
|
2000-03-26 21:42:28 +00:00
|
|
|
runtime_library_dirs=None,
|
2000-05-20 13:23:21 +00:00
|
|
|
export_symbols=None,
|
2000-02-10 02:15:52 +00:00
|
|
|
debug=0,
|
1999-09-29 12:29:10 +00:00
|
|
|
extra_preargs=None,
|
2000-06-28 01:29:09 +00:00
|
|
|
extra_postargs=None,
|
|
|
|
build_temp=None):
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-26 21:42:28 +00:00
|
|
|
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
|
|
|
(libraries, library_dirs, runtime_library_dirs) = \
|
|
|
|
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
|
|
|
|
|
2000-04-19 02:16:49 +00:00
|
|
|
if runtime_library_dirs:
|
2000-03-26 21:42:28 +00:00
|
|
|
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
|
|
|
+ str (runtime_library_dirs))
|
2000-03-06 03:40:29 +00:00
|
|
|
|
2000-03-18 15:19:51 +00:00
|
|
|
lib_opts = gen_lib_options (self,
|
2000-03-26 21:42:28 +00:00
|
|
|
library_dirs, runtime_library_dirs,
|
2000-03-18 15:19:51 +00:00
|
|
|
libraries)
|
2000-03-06 03:40:29 +00:00
|
|
|
if output_dir is not None:
|
|
|
|
output_filename = os.path.join (output_dir, output_filename)
|
|
|
|
|
|
|
|
if self._need_link (objects, output_filename):
|
|
|
|
|
|
|
|
if debug:
|
|
|
|
ldflags = self.ldflags_shared_debug
|
|
|
|
else:
|
|
|
|
ldflags = self.ldflags_shared
|
|
|
|
|
2000-05-20 13:23:21 +00:00
|
|
|
export_opts = []
|
|
|
|
for sym in (export_symbols or []):
|
|
|
|
export_opts.append("/EXPORT:" + sym)
|
|
|
|
|
|
|
|
ld_args = (ldflags + lib_opts + export_opts +
|
|
|
|
objects + ['/OUT:' + output_filename])
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-08-02 00:00:30 +00:00
|
|
|
# The MSVC linker generates .lib and .exp files, which cannot be
|
|
|
|
# suppressed by any linker switches. The .lib files may even be
|
|
|
|
# needed! Make sure they are generated in the temporary build
|
|
|
|
# directory. Since they have different names for debug and release
|
|
|
|
# builds, they can go into the same directory.
|
|
|
|
(dll_name, dll_ext) = os.path.splitext(
|
|
|
|
os.path.basename(output_filename))
|
|
|
|
implib_file = os.path.join(
|
|
|
|
os.path.dirname(objects[0]),
|
|
|
|
self.library_filename(dll_name))
|
|
|
|
ld_args.append ('/IMPLIB:' + implib_file)
|
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
if extra_preargs:
|
|
|
|
ld_args[:0] = extra_preargs
|
|
|
|
if extra_postargs:
|
2000-08-02 00:00:30 +00:00
|
|
|
ld_args.extend(extra_postargs)
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
self.mkpath (os.path.dirname (output_filename))
|
2000-05-30 01:56:44 +00:00
|
|
|
try:
|
|
|
|
self.spawn ([self.link] + ld_args)
|
|
|
|
except DistutilsExecError, msg:
|
|
|
|
raise LinkError, msg
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
else:
|
|
|
|
self.announce ("skipping %s (up-to-date)" % output_filename)
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
# link_shared_object ()
|
2000-04-19 02:16:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def link_executable (self,
|
|
|
|
objects,
|
|
|
|
output_progname,
|
|
|
|
output_dir=None,
|
|
|
|
libraries=None,
|
|
|
|
library_dirs=None,
|
|
|
|
runtime_library_dirs=None,
|
|
|
|
debug=0,
|
|
|
|
extra_preargs=None,
|
|
|
|
extra_postargs=None):
|
|
|
|
|
|
|
|
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
|
|
|
(libraries, library_dirs, runtime_library_dirs) = \
|
|
|
|
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
|
|
|
|
|
|
|
|
if runtime_library_dirs:
|
|
|
|
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
|
|
|
+ str (runtime_library_dirs))
|
|
|
|
|
|
|
|
lib_opts = gen_lib_options (self,
|
|
|
|
library_dirs, runtime_library_dirs,
|
|
|
|
libraries)
|
|
|
|
output_filename = output_progname + self.exe_extension
|
|
|
|
if output_dir is not None:
|
|
|
|
output_filename = os.path.join (output_dir, output_filename)
|
|
|
|
|
|
|
|
if self._need_link (objects, output_filename):
|
|
|
|
|
|
|
|
if debug:
|
|
|
|
ldflags = self.ldflags_shared_debug[1:]
|
|
|
|
else:
|
|
|
|
ldflags = self.ldflags_shared[1:]
|
|
|
|
|
|
|
|
ld_args = ldflags + lib_opts + \
|
|
|
|
objects + ['/OUT:' + output_filename]
|
|
|
|
|
|
|
|
if extra_preargs:
|
|
|
|
ld_args[:0] = extra_preargs
|
|
|
|
if extra_postargs:
|
|
|
|
ld_args.extend (extra_postargs)
|
|
|
|
|
|
|
|
self.mkpath (os.path.dirname (output_filename))
|
2000-05-30 01:56:44 +00:00
|
|
|
try:
|
|
|
|
self.spawn ([self.link] + ld_args)
|
|
|
|
except DistutilsExecError, msg:
|
|
|
|
raise LinkError, msg
|
2000-04-19 02:16:49 +00:00
|
|
|
else:
|
|
|
|
self.announce ("skipping %s (up-to-date)" % output_filename)
|
2000-03-06 03:40:29 +00:00
|
|
|
|
1999-08-29 18:15:07 +00:00
|
|
|
|
2000-03-06 03:40:29 +00:00
|
|
|
# -- Miscellaneous methods -----------------------------------------
|
|
|
|
# These are all used by the 'gen_lib_options() function, in
|
|
|
|
# ccompiler.py.
|
1999-10-03 20:47:52 +00:00
|
|
|
|
|
|
|
def library_dir_option (self, dir):
|
|
|
|
return "/LIBPATH:" + dir
|
|
|
|
|
2000-03-18 15:19:51 +00:00
|
|
|
def runtime_library_dir_option (self, dir):
|
|
|
|
raise DistutilsPlatformError, \
|
|
|
|
"don't know how to set runtime library search path for MSVC++"
|
|
|
|
|
1999-10-03 20:47:52 +00:00
|
|
|
def library_option (self, lib):
|
|
|
|
return self.library_filename (lib)
|
|
|
|
|
|
|
|
|
|
|
|
def find_library_file (self, dirs, lib):
|
|
|
|
|
|
|
|
for dir in dirs:
|
|
|
|
libfile = os.path.join (dir, self.library_filename (lib))
|
|
|
|
if os.path.exists (libfile):
|
|
|
|
return libfile
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Oops, didn't find it in *any* of 'dirs'
|
|
|
|
return None
|
|
|
|
|
|
|
|
# find_library_file ()
|
|
|
|
|
1999-08-29 18:15:07 +00:00
|
|
|
# class MSVCCompiler
|