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()
13
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
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__ = "src/engine/SCons/Tool/linkloc.py 3842 2008/12/20 22:59:52 scons"
46
from SCons.Tool.msvc import get_msvc_paths
47
from SCons.Tool.PharLapCommon import addPharLapPaths
49
_re_linker_command = re.compile(r'(\s)@\s*([^\s]+)')
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.
55
f=open(m.group(2), "r")
56
return m.group(1) + f.read()
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)
64
class LinklocGenerator:
65
def __init__(self, cmdline):
66
self.cmdline = cmdline
68
def __call__(self, env, target, source, for_signature):
70
# Expand the contents of any linker command files recursively
72
strsub = env.subst(self.cmdline, target=target, source=source)
74
strsub, subs = _re_linker_command.subn(repl_linker_command, strsub)
77
return "${TEMPFILE('" + self.cmdline + "')}"
80
"""Add Builders and construction variables for ar to an Environment."""
81
SCons.Tool.createSharedLibBuilder(env)
82
SCons.Tool.createProgBuilder(env)
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'
97
msvs_version = env.get('MSVS_VERSION')
98
include_path, lib_path, exe_path = get_msvc_paths(env, version = msvs_version)
99
env['ENV']['LIB'] = lib_path
100
env.PrependENVPath('PATH', exe_path)
105
return env.Detect('linkloc')