nv50: fix texturing from >=4GiB mark
[mesa/mesa-lb.git] / scons / mslib_sa.py
blobbdc0dd9251170f318cdeed27aa76b7b8e52f1506
1 """mslib_sa
3 Tool-specific initialization for lib (MicroSoft library archiver).
5 Based on SCons.Tool.mslib, without the MSVC detection.
7 """
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.
32 import os
33 import tempfile
34 import string
36 import SCons.Defaults
37 import SCons.Tool
38 import SCons.Util
39 import SCons.Errors
41 class TempFileMunge:
42 """Same as SCons.Platform.TempFileMunge, but preserves LINK /LIB
43 together."""
45 def __init__(self, cmd):
46 self.cmd = cmd
48 def __call__(self, target, source, env, for_signature):
49 if for_signature:
50 return self.cmd
51 cmd = env.subst_list(self.cmd, 0, target, source)[0]
52 try:
53 maxline = int(env.subst('$MAXLINELENGTH'))
54 except ValueError:
55 maxline = 2048
57 if (reduce(lambda x, y: x + len(y), cmd, 0) + len(cmd)) <= maxline:
58 return self.cmd
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
63 # switch and barfs.
65 # We use the .lnk suffix for the benefit of the Phar Lap
66 # linkloc linker, which likes to append an .lnk suffix if
67 # none is given.
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'
78 else:
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
81 # Windows path names.
82 rm = 'del'
84 prefix = env.subst('$TEMPFILEPREFIX')
85 if not prefix:
86 prefix = '@'
88 if cmd[0:2] == ['link', '/lib']:
89 split = 2
90 else:
91 split = 1
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 ]
115 def generate(env):
116 """Add Builders and construction variables for lib to an Environment."""
117 SCons.Tool.createStaticLibBuilder(env)
119 if env.Detect('lib'):
120 env['AR'] = 'lib'
121 else:
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'
130 def exists(env):
131 return env.Detect('lib') or env.Detect('link')
133 # Local Variables:
134 # tab-width:4
135 # indent-tabs-mode:nil
136 # End:
137 # vim: set expandtab tabstop=4 shiftwidth=4: