Tweak svn/git ignores
[zxing.git] / cpp / scons / scons-local-2.0.0.final.0 / SCons / Tool / linkloc.py
1 """SCons.Tool.linkloc
2
3 Tool specification for the LinkLoc linker for the Phar Lap ETS embedded
4 operating system.
5
6 There normally shouldn't be any need to import this module directly.
7 It will usually be imported through the generic SCons.Tool.Tool()
8 selection method.
9
10 """
11
12 #
13 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
14 #
15 # Permission is hereby granted, free of charge, to any person obtaining
16 # a copy of this software and associated documentation files (the
17 # "Software"), to deal in the Software without restriction, including
18 # without limitation the rights to use, copy, modify, merge, publish,
19 # distribute, sublicense, and/or sell copies of the Software, and to
20 # permit persons to whom the Software is furnished to do so, subject to
21 # the following conditions:
22 #
23 # The above copyright notice and this permission notice shall be included
24 # in all copies or substantial portions of the Software.
25 #
26 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
27 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
28 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #
34
35 __revision__ = "src/engine/SCons/Tool/linkloc.py 5023 2010/06/14 22:05:46 scons"
36
37 import os.path
38 import re
39
40 import SCons.Action
41 import SCons.Defaults
42 import SCons.Errors
43 import SCons.Tool
44 import SCons.Util
45
46 from SCons.Tool.MSCommon import msvs_exists, merge_default_version
47 from SCons.Tool.PharLapCommon import addPharLapPaths
48
49 _re_linker_command = re.compile(r'(\s)@\s*([^\s]+)')
50
51 def repl_linker_command(m):
52     # Replaces any linker command file directives (e.g. "@foo.lnk") with
53     # the actual contents of the file.
54     try:
55         f=open(m.group(2), "r")
56         return m.group(1) + f.read()
57     except IOError:
58         # the linker should return an error if it can't
59         # find the linker command file so we will remain quiet.
60         # However, we will replace the @ with a # so we will not continue
61         # to find it with recursive substitution
62         return m.group(1) + '#' + m.group(2)
63
64 class LinklocGenerator(object):
65     def __init__(self, cmdline):
66         self.cmdline = cmdline
67
68     def __call__(self, env, target, source, for_signature):
69         if for_signature:
70             # Expand the contents of any linker command files recursively
71             subs = 1
72             strsub = env.subst(self.cmdline, target=target, source=source)
73             while subs:
74                 strsub, subs = _re_linker_command.subn(repl_linker_command, strsub)
75             return strsub
76         else:
77             return "${TEMPFILE('" + self.cmdline + "')}"
78
79 def generate(env):
80     """Add Builders and construction variables for ar to an Environment."""
81     SCons.Tool.createSharedLibBuilder(env)
82     SCons.Tool.createProgBuilder(env)
83
84     env['SUBST_CMD_FILE'] = LinklocGenerator
85     env['SHLINK']      = '$LINK'
86     env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS')
87     env['SHLINKCOM']   = '${SUBST_CMD_FILE("$SHLINK $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS -dll $TARGET $SOURCES")}'
88     env['SHLIBEMITTER']= None
89     env['LINK']        = "linkloc"
90     env['LINKFLAGS']   = SCons.Util.CLVar('')
91     env['LINKCOM']     = '${SUBST_CMD_FILE("$LINK $LINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS -exe $TARGET $SOURCES")}'
92     env['LIBDIRPREFIX']='-libpath '
93     env['LIBDIRSUFFIX']=''
94     env['LIBLINKPREFIX']='-lib '
95     env['LIBLINKSUFFIX']='$LIBSUFFIX'
96
97     # Set-up ms tools paths for default version
98     merge_default_version(env)
99
100     addPharLapPaths(env)
101
102 def exists(env):
103     if msvs_exists():
104         return env.Detect('linkloc')
105     else:
106         return 0
107
108 # Local Variables:
109 # tab-width:4
110 # indent-tabs-mode:nil
111 # End:
112 # vim: set expandtab tabstop=4 shiftwidth=4: