3
Tool-specific initialization for lib (MicroSoft library archiver).
5
Based on SCons.Tool.mslib, without the MSVC detection.
10
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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.
42
"""Same as SCons.Platform.TempFileMunge, but preserves LINK /LIB
45
def __init__(self, cmd):
48
def __call__(self, target, source, env, for_signature):
51
cmd = env.subst_list(self.cmd, 0, target, source)[0]
53
maxline = int(env.subst('$MAXLINELENGTH'))
57
if (reduce(lambda x, y: x + len(y), cmd, 0) + len(cmd)) <= maxline:
60
# We do a normpath because mktemp() has what appears to be
61
# a bug in Windows that will use a forward slash as a path
62
# delimiter. Windows's link mistakes that for a command line
65
# We use the .lnk suffix for the benefit of the Phar Lap
66
# linkloc linker, which likes to append an .lnk suffix if
68
tmp = os.path.normpath(tempfile.mktemp('.lnk'))
69
native_tmp = SCons.Util.get_native_path(tmp)
71
if env['SHELL'] and env['SHELL'] == 'sh':
72
# The sh shell will try to escape the backslashes in the
73
# path, so unescape them.
74
native_tmp = string.replace(native_tmp, '\\', r'\\\\')
75
# In Cygwin, we want to use rm to delete the temporary
76
# file, because del does not exist in the sh shell.
77
rm = env.Detect('rm') or 'del'
79
# Don't use 'rm' if the shell is not sh, because rm won't
80
# work with the Windows shells (cmd.exe or command.com) or
84
prefix = env.subst('$TEMPFILEPREFIX')
88
if cmd[0:2] == ['link', '/lib']:
93
args = map(SCons.Subst.quote_spaces, cmd[split:])
94
open(tmp, 'w').write(string.join(args, " ") + "\n")
95
# XXX Using the SCons.Action.print_actions value directly
96
# like this is bogus, but expedient. This class should
97
# really be rewritten as an Action that defines the
98
# __call__() and strfunction() methods and lets the
99
# normal action-execution logic handle whether or not to
100
# print/execute the action. The problem, though, is all
101
# of that is decided before we execute this method as
102
# part of expanding the $TEMPFILE construction variable.
103
# Consequently, refactoring this will have to wait until
104
# we get more flexible with allowing Actions to exist
105
# independently and get strung together arbitrarily like
106
# Ant tasks. In the meantime, it's going to be more
107
# user-friendly to not let obsession with architectural
108
# purity get in the way of just being helpful, so we'll
109
# reach into SCons.Action directly.
110
if SCons.Action.print_actions:
111
print("Using tempfile "+native_tmp+" for command line:\n"+
112
" ".join(map(str,cmd)))
113
return cmd[:split] + [ prefix + native_tmp + '\n' + rm, native_tmp ]
116
"""Add Builders and construction variables for lib to an Environment."""
117
SCons.Tool.createStaticLibBuilder(env)
119
if env.Detect('lib'):
122
# Recent WINDDK versions do not ship with lib.
123
env['AR'] = 'link /lib'
124
env['TEMPFILE'] = TempFileMunge
125
env['ARFLAGS'] = SCons.Util.CLVar('/nologo')
126
env['ARCOM'] = "${TEMPFILE('$AR $ARFLAGS /OUT:$TARGET $SOURCES')}"
127
env['LIBPREFIX'] = ''
128
env['LIBSUFFIX'] = '.lib'
131
return env.Detect('lib') or env.Detect('link')
135
# indent-tabs-mode:nil
137
# vim: set expandtab tabstop=4 shiftwidth=4: