3 Tool-specific initialization for the Microsoft linker.
5 Based on SCons.Tool.mslink, without the MSVS detection.
10 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
12 # Permission is hereby granted, free of charge, to any person obtaining
13 # a copy of this software and associated documentation files (the
14 # "Software"), to deal in the Software without restriction, including
15 # without limitation the rights to use, copy, modify, merge, publish,
16 # distribute, sublicense, and/or sell copies of the Software, and to
17 # permit persons to whom the Software is furnished to do so, subject to
18 # the following conditions:
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
24 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 import SCons
.Platform
.win32
39 import SCons
.Tool
.msvc
42 def pdbGenerator(env
, target
, source
, for_signature
):
44 return ['/PDB:%s' % target
[0].attributes
.pdb
, '/DEBUG']
45 except (AttributeError, IndexError):
48 def windowsShlinkTargets(target
, source
, env
, for_signature
):
50 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
51 if dll
: listCmd
.append("/out:%s"%dll
.get_string(for_signature
))
53 implib
= env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX')
54 if implib
: listCmd
.append("/implib:%s"%implib
.get_string(for_signature
))
58 def windowsShlinkSources(target
, source
, env
, for_signature
):
61 deffile
= env
.FindIxes(source
, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")
64 # Treat this source as a .def file.
65 listCmd
.append("/def:%s" % src
.get_string(for_signature
))
67 # Just treat it as a generic source file.
71 def windowsLibEmitter(target
, source
, env
):
72 SCons
.Tool
.msvc
.validate_vars(env
)
77 dll
= env
.FindIxes(target
, "SHLIBPREFIX", "SHLIBSUFFIX")
78 no_import_lib
= env
.get('no_import_lib', 0)
81 raise SCons
.Errors
.UserError
, "A shared library should have exactly one target with the suffix: %s" % env
.subst("$SHLIBSUFFIX")
83 insert_def
= env
.subst("$WINDOWS_INSERT_DEF")
84 if not insert_def
in ['', '0', 0] and \
85 not env
.FindIxes(source
, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"):
87 # append a def file to the list of sources
90 "SHLIBPREFIX", "SHLIBSUFFIX",
91 "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"))
93 if env
.has_key('PDB') and env
['PDB']:
94 pdb
= env
.arg2nodes('$PDB', target
=target
, source
=source
)[0]
95 extratargets
.append(pdb
)
96 target
[0].attributes
.pdb
= pdb
98 if not no_import_lib
and \
99 not env
.FindIxes(target
, "LIBPREFIX", "LIBSUFFIX"):
100 # Append an import library to the list of targets.
103 "SHLIBPREFIX", "SHLIBSUFFIX",
104 "LIBPREFIX", "LIBSUFFIX"))
105 # and .exp file is created if there are exports from a DLL
108 "SHLIBPREFIX", "SHLIBSUFFIX",
109 "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX"))
111 return (target
+extratargets
, source
+extrasources
)
113 def prog_emitter(target
, source
, env
):
114 SCons
.Tool
.msvc
.validate_vars(env
)
118 exe
= env
.FindIxes(target
, "PROGPREFIX", "PROGSUFFIX")
120 raise SCons
.Errors
.UserError
, "An executable should have exactly one target with the suffix: %s" % env
.subst("$PROGSUFFIX")
122 if env
.has_key('PDB') and env
['PDB']:
123 pdb
= env
.arg2nodes('$PDB', target
=target
, source
=source
)[0]
124 extratargets
.append(pdb
)
125 target
[0].attributes
.pdb
= pdb
127 return (target
+extratargets
,source
)
129 def RegServerFunc(target
, source
, env
):
130 if env
.has_key('register') and env
['register']:
131 ret
= regServerAction([target
[0]], [source
[0]], env
)
133 raise SCons
.Errors
.UserError
, "Unable to register %s" % target
[0]
135 print "Registered %s sucessfully" % target
[0]
139 regServerAction
= SCons
.Action
.Action("$REGSVRCOM", "$REGSVRCOMSTR")
140 regServerCheck
= SCons
.Action
.Action(RegServerFunc
, None)
141 shlibLinkAction
= SCons
.Action
.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
142 compositeLinkAction
= shlibLinkAction
+ regServerCheck
145 """Add Builders and construction variables for ar to an Environment."""
146 SCons
.Tool
.createSharedLibBuilder(env
)
147 SCons
.Tool
.createProgBuilder(env
)
149 env
['SHLINK'] = '$LINK'
150 env
['SHLINKFLAGS'] = SCons
.Util
.CLVar('$LINKFLAGS /dll')
151 env
['_SHLINK_TARGETS'] = windowsShlinkTargets
152 env
['_SHLINK_SOURCES'] = windowsShlinkSources
153 env
['SHLINKCOM'] = compositeLinkAction
154 env
.Append(SHLIBEMITTER
= [windowsLibEmitter
])
156 env
['LINKFLAGS'] = SCons
.Util
.CLVar('/nologo')
157 env
['_PDB'] = pdbGenerator
158 env
['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $SOURCES.windows")}'
159 env
.Append(PROGEMITTER
= [prog_emitter
])
160 env
['LIBDIRPREFIX']='/LIBPATH:'
161 env
['LIBDIRSUFFIX']=''
162 env
['LIBLINKPREFIX']=''
163 env
['LIBLINKSUFFIX']='$LIBSUFFIX'
165 env
['WIN32DEFPREFIX'] = ''
166 env
['WIN32DEFSUFFIX'] = '.def'
167 env
['WIN32_INSERT_DEF'] = 0
168 env
['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
169 env
['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
170 env
['WINDOWS_INSERT_DEF'] = '${WIN32_INSERT_DEF}'
172 env
['WIN32EXPPREFIX'] = ''
173 env
['WIN32EXPSUFFIX'] = '.exp'
174 env
['WINDOWSEXPPREFIX'] = '${WIN32EXPPREFIX}'
175 env
['WINDOWSEXPSUFFIX'] = '${WIN32EXPSUFFIX}'
177 env
['WINDOWSSHLIBMANIFESTPREFIX'] = ''
178 env
['WINDOWSSHLIBMANIFESTSUFFIX'] = '${SHLIBSUFFIX}.manifest'
179 env
['WINDOWSPROGMANIFESTPREFIX'] = ''
180 env
['WINDOWSPROGMANIFESTSUFFIX'] = '${PROGSUFFIX}.manifest'
182 env
['REGSVRACTION'] = regServerCheck
183 env
['REGSVR'] = os
.path
.join(SCons
.Platform
.win32
.get_system_root(),'System32','regsvr32')
184 env
['REGSVRFLAGS'] = '/s '
185 env
['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.windows}'
187 # For most platforms, a loadable module is the same as a shared
188 # library. Platforms which are different can override these, but
189 # setting them the same means that LoadableModule works everywhere.
190 SCons
.Tool
.createLoadableModuleBuilder(env
)
191 env
['LDMODULE'] = '$SHLINK'
192 env
['LDMODULEPREFIX'] = '$SHLIBPREFIX'
193 env
['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
194 env
['LDMODULEFLAGS'] = '$SHLINKFLAGS'
195 # We can't use '$SHLINKCOM' here because that will stringify the
196 # action list on expansion, and will then try to execute expanded
197 # strings, with the upshot that it would try to execute RegServerFunc
199 env
['LDMODULECOM'] = compositeLinkAction
202 platform
= env
.get('PLATFORM', '')
203 if platform
in ('win32', 'cygwin'):
204 # Only explicitly search for a 'link' executable on Windows
205 # systems. Some other systems (e.g. Ubuntu Linux) have an
206 # executable named 'link' and we don't want that to make SCons
207 # think Visual Studio is installed.
208 return env
.Detect('link')
211 # vim:set ts=4 sw=4 et: