3 Tool specification for the LinkLoc linker for the Phar Lap ETS embedded
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()
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:
23 # The above copyright notice and this permission notice shall be included
24 # in all copies or substantial portions of the Software.
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.
35 __revision__
= "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
45 from SCons
.Tool
.MSCommon
import msvs_exists
, merge_default_version
46 from SCons
.Tool
.PharLapCommon
import addPharLapPaths
48 _re_linker_command
= re
.compile(r
'(\s)@\s*([^\s]+)')
50 def repl_linker_command(m
):
51 # Replaces any linker command file directives (e.g. "@foo.lnk") with
52 # the actual contents of the file.
54 with
open(m
.group(2)) as f
:
55 return m
.group(1) + f
.read()
57 # the linker should return an error if it can't
58 # find the linker command file so we will remain quiet.
59 # However, we will replace the @ with a # so we will not continue
60 # to find it with recursive substitution
61 return m
.group(1) + '#' + m
.group(2)
63 class LinklocGenerator
:
64 def __init__(self
, cmdline
) -> None:
65 self
.cmdline
= cmdline
67 def __call__(self
, env
, target
, source
, for_signature
):
69 # Expand the contents of any linker command files recursively
71 strsub
= env
.subst(self
.cmdline
, target
=target
, source
=source
)
73 strsub
, subs
= _re_linker_command
.subn(repl_linker_command
, strsub
)
76 return "${TEMPFILE('" + self
.cmdline
+ "')}"
78 def generate(env
) -> None:
79 """Add Builders and construction variables for ar to an Environment."""
80 SCons
.Tool
.createSharedLibBuilder(env
)
81 SCons
.Tool
.createProgBuilder(env
)
83 env
['SUBST_CMD_FILE'] = LinklocGenerator
84 env
['SHLINK'] = '$LINK'
85 env
['SHLINKFLAGS'] = SCons
.Util
.CLVar('$LINKFLAGS')
86 env
['SHLINKCOM'] = '${SUBST_CMD_FILE("$SHLINK $SHLINKFLAGS $_LIBDIRFLAGS $_LIBFLAGS -dll $TARGET $SOURCES")}'
87 env
['SHLIBEMITTER']= None
88 env
['LDMODULEEMITTER']= 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'
97 # Set-up ms tools paths for default version
98 merge_default_version(env
)
104 return env
.Detect('linkloc')
110 # indent-tabs-mode:nil
112 # vim: set expandtab tabstop=4 shiftwidth=4: