3
Tool-specific initialization for the Microsoft linker.
5
There normally shouldn't be any need to import this module directly.
6
It will usually be imported through the generic SCons.Tool.Tool()
12
# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
14
# Permission is hereby granted, free of charge, to any person obtaining
15
# a copy of this software and associated documentation files (the
16
# "Software"), to deal in the Software without restriction, including
17
# without limitation the rights to use, copy, modify, merge, publish,
18
# distribute, sublicense, and/or sell copies of the Software, and to
19
# permit persons to whom the Software is furnished to do so, subject to
20
# the following conditions:
22
# The above copyright notice and this permission notice shall be included
23
# in all copies or substantial portions of the Software.
25
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
26
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
__revision__ = "/home/scons/scons/branch.0/baseline/src/engine/SCons/Tool/mslink.py 0.96.1.D001 2004/08/23 09:55:29 knight"
41
import SCons.Platform.win32
43
import SCons.Tool.msvc
44
import SCons.Tool.msvs
47
def pdbGenerator(env, target, source, for_signature):
48
if target and env.has_key('PDB') and env['PDB']:
49
return ['/PDB:%s'%target[0].File(env['PDB']).get_string(for_signature),
53
def win32ShlinkTargets(target, source, env, for_signature):
55
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
56
if dll: listCmd.append("/out:%s"%dll.get_string(for_signature))
58
implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
59
if implib: listCmd.append("/implib:%s"%implib.get_string(for_signature))
63
def win32ShlinkSources(target, source, env, for_signature):
66
deffile = env.FindIxes(source, "WIN32DEFPREFIX", "WIN32DEFSUFFIX")
69
# Treat this source as a .def file.
70
listCmd.append("/def:%s" % src.get_string(for_signature))
72
# Just treat it as a generic source file.
76
def win32LibEmitter(target, source, env):
77
SCons.Tool.msvc.validate_vars(env)
79
dll = env.FindIxes(target, "SHLIBPREFIX", "SHLIBSUFFIX")
80
no_import_lib = env.get('no_import_lib', 0)
83
raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
85
if env.get("WIN32_INSERT_DEF", 0) and \
86
not env.FindIxes(source, "WIN32DEFPREFIX", "WIN32DEFSUFFIX"):
88
# append a def file to the list of sources
89
source.append(env.ReplaceIxes(dll,
90
"SHLIBPREFIX", "SHLIBSUFFIX",
91
"WIN32DEFPREFIX", "WIN32DEFSUFFIX"))
93
if env.has_key('PDB') and env['PDB']:
94
target.append(env['PDB'])
96
if not no_import_lib and \
97
not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"):
98
# Append an import library to the list of targets.
99
target.append(env.ReplaceIxes(dll,
100
"SHLIBPREFIX", "SHLIBSUFFIX",
101
"LIBPREFIX", "LIBSUFFIX"))
102
# and .exp file is created if there are exports from a DLL
103
target.append(env.ReplaceIxes(dll,
104
"SHLIBPREFIX", "SHLIBSUFFIX",
105
"WIN32EXPPREFIX", "WIN32EXPSUFFIX"))
107
return (target, source)
109
def prog_emitter(target, source, env):
110
SCons.Tool.msvc.validate_vars(env)
112
if env.has_key('PDB') and env['PDB']:
113
target.append(env['PDB'])
115
return (target,source)
117
def RegServerFunc(target, source, env):
118
if env.has_key('register') and env['register']:
119
ret = regServerAction([target[0]], [source[0]], env)
121
raise SCons.Errors.UserError, "Unable to register %s" % target[0]
123
print "Registered %s sucessfully" % target[0]
127
regServerAction = SCons.Action.Action("$REGSVRCOM")
128
regServerCheck = SCons.Action.Action(RegServerFunc, None)
129
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
130
compositeLinkAction = shlibLinkAction + regServerCheck
133
"""Add Builders and construction variables for ar to an Environment."""
134
SCons.Tool.createSharedLibBuilder(env)
135
SCons.Tool.createProgBuilder(env)
137
env['SHLINK'] = '$LINK'
138
env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll')
139
env['_SHLINK_TARGETS'] = win32ShlinkTargets
140
env['_SHLINK_SOURCES'] = win32ShlinkSources
141
env['SHLINKCOM'] = compositeLinkAction
142
env.Append(SHLIBEMITTER = [win32LibEmitter])
144
env['LINKFLAGS'] = SCons.Util.CLVar('/nologo')
145
env['_PDB'] = pdbGenerator
146
env['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.win32 $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $SOURCES.win32")}'
147
env.Append(PROGEMITTER = [prog_emitter])
148
env['LIBDIRPREFIX']='/LIBPATH:'
149
env['LIBDIRSUFFIX']=''
150
env['LIBLINKPREFIX']=''
151
env['LIBLINKSUFFIX']='$LIBSUFFIX'
153
env['WIN32DEFPREFIX'] = ''
154
env['WIN32DEFSUFFIX'] = '.def'
155
env['WIN32_INSERT_DEF'] = 0
157
env['WIN32EXPPREFIX'] = ''
158
env['WIN32EXPSUFFIX'] = '.exp'
160
env['REGSVRACTION'] = regServerCheck
161
env['REGSVR'] = os.path.join(SCons.Platform.win32.get_system_root(),'System32','regsvr32')
162
env['REGSVRFLAGS'] = '/s '
163
env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.win32}'
166
version = SCons.Tool.msvs.get_default_visualstudio_version(env)
168
if env.has_key('MSVS_IGNORE_IDE_PATHS') and env['MSVS_IGNORE_IDE_PATHS']:
169
include_path, lib_path, exe_path = SCons.Tool.msvc.get_msvc_default_paths(version)
171
include_path, lib_path, exe_path = SCons.Tool.msvc.get_msvc_paths(version)
173
# since other tools can set these, we just make sure that the
174
# relevant stuff from MSVS is in there somewhere.
175
env.PrependENVPath('INCLUDE', include_path)
176
env.PrependENVPath('LIB', lib_path)
177
env.PrependENVPath('PATH', exe_path)
178
except (SCons.Util.RegError, SCons.Errors.InternalError):
182
if SCons.Tool.msvs.is_msvs_installed():
183
# there's at least one version of MSVS installed.
186
return env.Detect('link')