You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.9 KiB

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