~ubuntu-branches/ubuntu/utopic/scons/utopic-proposed

« back to all changes in this revision

Viewing changes to engine/SCons/Tool/mslink.py

  • Committer: Bazaar Package Importer
  • Author(s): Mark Brown
  • Date: 2004-08-24 08:57:22 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040824085722-hfk4f0pjbyu0ebxv
Tags: 0.96.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""SCons.Tool.mslink
 
2
 
 
3
Tool-specific initialization for the Microsoft linker.
 
4
 
 
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()
 
7
selection method.
 
8
 
 
9
"""
 
10
 
 
11
#
 
12
# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
 
13
#
 
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:
 
21
#
 
22
# The above copyright notice and this permission notice shall be included
 
23
# in all copies or substantial portions of the Software.
 
24
#
 
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.
 
32
#
 
33
 
 
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"
 
35
 
 
36
import os.path
 
37
 
 
38
import SCons.Action
 
39
import SCons.Defaults
 
40
import SCons.Errors
 
41
import SCons.Platform.win32
 
42
import SCons.Tool
 
43
import SCons.Tool.msvc
 
44
import SCons.Tool.msvs
 
45
import SCons.Util
 
46
 
 
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),
 
50
                '/DEBUG']
 
51
    return None
 
52
 
 
53
def win32ShlinkTargets(target, source, env, for_signature):
 
54
    listCmd = []
 
55
    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
 
56
    if dll: listCmd.append("/out:%s"%dll.get_string(for_signature))
 
57
 
 
58
    implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
 
59
    if implib: listCmd.append("/implib:%s"%implib.get_string(for_signature))
 
60
 
 
61
    return listCmd
 
62
 
 
63
def win32ShlinkSources(target, source, env, for_signature):
 
64
    listCmd = []
 
65
 
 
66
    deffile = env.FindIxes(source, "WIN32DEFPREFIX", "WIN32DEFSUFFIX")
 
67
    for src in source:
 
68
        if src == deffile:
 
69
            # Treat this source as a .def file.
 
70
            listCmd.append("/def:%s" % src.get_string(for_signature))
 
71
        else:
 
72
            # Just treat it as a generic source file.
 
73
            listCmd.append(src)
 
74
    return listCmd
 
75
    
 
76
def win32LibEmitter(target, source, env):
 
77
    SCons.Tool.msvc.validate_vars(env)
 
78
    
 
79
    dll = env.FindIxes(target, "SHLIBPREFIX", "SHLIBSUFFIX")
 
80
    no_import_lib = env.get('no_import_lib', 0)
 
81
    
 
82
    if not dll:
 
83
        raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
 
84
 
 
85
    if env.get("WIN32_INSERT_DEF", 0) and \
 
86
       not env.FindIxes(source, "WIN32DEFPREFIX", "WIN32DEFSUFFIX"):
 
87
 
 
88
        # append a def file to the list of sources
 
89
        source.append(env.ReplaceIxes(dll, 
 
90
                                      "SHLIBPREFIX", "SHLIBSUFFIX",
 
91
                                      "WIN32DEFPREFIX", "WIN32DEFSUFFIX"))
 
92
 
 
93
    if env.has_key('PDB') and env['PDB']:
 
94
        target.append(env['PDB'])
 
95
 
 
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"))
 
106
 
 
107
    return (target, source)
 
108
 
 
109
def prog_emitter(target, source, env):
 
110
    SCons.Tool.msvc.validate_vars(env)
 
111
    
 
112
    if env.has_key('PDB') and env['PDB']:
 
113
        target.append(env['PDB'])
 
114
        
 
115
    return (target,source)
 
116
 
 
117
def RegServerFunc(target, source, env):
 
118
    if env.has_key('register') and env['register']:
 
119
        ret = regServerAction([target[0]], [source[0]], env)
 
120
        if ret:
 
121
            raise SCons.Errors.UserError, "Unable to register %s" % target[0]
 
122
        else:
 
123
            print "Registered %s sucessfully" % target[0]
 
124
        return ret
 
125
    return 0
 
126
 
 
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
 
131
 
 
132
def generate(env):
 
133
    """Add Builders and construction variables for ar to an Environment."""
 
134
    SCons.Tool.createSharedLibBuilder(env)
 
135
    SCons.Tool.createProgBuilder(env)
 
136
    
 
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])
 
143
    env['LINK']        = 'link'
 
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'
 
152
 
 
153
    env['WIN32DEFPREFIX']        = ''
 
154
    env['WIN32DEFSUFFIX']        = '.def'
 
155
    env['WIN32_INSERT_DEF']      = 0
 
156
 
 
157
    env['WIN32EXPPREFIX']        = ''
 
158
    env['WIN32EXPSUFFIX']        = '.exp'
 
159
 
 
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}'
 
164
 
 
165
    try:
 
166
        version = SCons.Tool.msvs.get_default_visualstudio_version(env)
 
167
 
 
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)
 
170
        else:
 
171
            include_path, lib_path, exe_path = SCons.Tool.msvc.get_msvc_paths(version)
 
172
 
 
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):
 
179
        pass
 
180
 
 
181
def exists(env):
 
182
    if SCons.Tool.msvs.is_msvs_installed():
 
183
        # there's at least one version of MSVS installed.
 
184
        return 1
 
185
    else:
 
186
        return env.Detect('link')