Clone of mesa.
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. """mslib_sa
  2. Tool-specific initialization for lib (MicroSoft library archiver).
  3. Based on SCons.Tool.mslib, without the MSVC detection.
  4. """
  5. #
  6. # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining
  9. # a copy of this software and associated documentation files (the
  10. # "Software"), to deal in the Software without restriction, including
  11. # without limitation the rights to use, copy, modify, merge, publish,
  12. # distribute, sublicense, and/or sell copies of the Software, and to
  13. # permit persons to whom the Software is furnished to do so, subject to
  14. # the following conditions:
  15. #
  16. # The above copyright notice and this permission notice shall be included
  17. # in all copies or substantial portions of the Software.
  18. #
  19. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  20. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  21. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. #
  27. import os
  28. import tempfile
  29. import string
  30. import SCons.Defaults
  31. import SCons.Tool
  32. import SCons.Util
  33. import SCons.Errors
  34. class TempFileMunge:
  35. """Same as SCons.Platform.TempFileMunge, but preserves LINK /LIB
  36. together."""
  37. def __init__(self, cmd):
  38. self.cmd = cmd
  39. def __call__(self, target, source, env, for_signature):
  40. if for_signature:
  41. return self.cmd
  42. cmd = env.subst_list(self.cmd, 0, target, source)[0]
  43. try:
  44. maxline = int(env.subst('$MAXLINELENGTH'))
  45. except ValueError:
  46. maxline = 2048
  47. if (reduce(lambda x, y: x + len(y), cmd, 0) + len(cmd)) <= maxline:
  48. return self.cmd
  49. # We do a normpath because mktemp() has what appears to be
  50. # a bug in Windows that will use a forward slash as a path
  51. # delimiter. Windows's link mistakes that for a command line
  52. # switch and barfs.
  53. #
  54. # We use the .lnk suffix for the benefit of the Phar Lap
  55. # linkloc linker, which likes to append an .lnk suffix if
  56. # none is given.
  57. tmp = os.path.normpath(tempfile.mktemp('.lnk'))
  58. native_tmp = SCons.Util.get_native_path(tmp)
  59. if env['SHELL'] and env['SHELL'] == 'sh':
  60. # The sh shell will try to escape the backslashes in the
  61. # path, so unescape them.
  62. native_tmp = string.replace(native_tmp, '\\', r'\\\\')
  63. # In Cygwin, we want to use rm to delete the temporary
  64. # file, because del does not exist in the sh shell.
  65. rm = env.Detect('rm') or 'del'
  66. else:
  67. # Don't use 'rm' if the shell is not sh, because rm won't
  68. # work with the Windows shells (cmd.exe or command.com) or
  69. # Windows path names.
  70. rm = 'del'
  71. prefix = env.subst('$TEMPFILEPREFIX')
  72. if not prefix:
  73. prefix = '@'
  74. if cmd[0:2] == ['link', '/lib']:
  75. split = 2
  76. else:
  77. split = 1
  78. args = map(SCons.Subst.quote_spaces, cmd[split:])
  79. open(tmp, 'w').write(string.join(args, " ") + "\n")
  80. # XXX Using the SCons.Action.print_actions value directly
  81. # like this is bogus, but expedient. This class should
  82. # really be rewritten as an Action that defines the
  83. # __call__() and strfunction() methods and lets the
  84. # normal action-execution logic handle whether or not to
  85. # print/execute the action. The problem, though, is all
  86. # of that is decided before we execute this method as
  87. # part of expanding the $TEMPFILE construction variable.
  88. # Consequently, refactoring this will have to wait until
  89. # we get more flexible with allowing Actions to exist
  90. # independently and get strung together arbitrarily like
  91. # Ant tasks. In the meantime, it's going to be more
  92. # user-friendly to not let obsession with architectural
  93. # purity get in the way of just being helpful, so we'll
  94. # reach into SCons.Action directly.
  95. if SCons.Action.print_actions:
  96. print("Using tempfile "+native_tmp+" for command line:\n"+
  97. " ".join(map(str,cmd)))
  98. return cmd[:split] + [ prefix + native_tmp + '\n' + rm, native_tmp ]
  99. def generate(env):
  100. """Add Builders and construction variables for lib to an Environment."""
  101. SCons.Tool.createStaticLibBuilder(env)
  102. if env.Detect('lib'):
  103. env['AR'] = 'lib'
  104. else:
  105. # Recent WINDDK versions do not ship with lib.
  106. env['AR'] = 'link /lib'
  107. env['TEMPFILE'] = TempFileMunge
  108. env['ARFLAGS'] = SCons.Util.CLVar('/nologo')
  109. env['ARCOM'] = "${TEMPFILE('$AR $ARFLAGS /OUT:$TARGET $SOURCES')}"
  110. env['LIBPREFIX'] = ''
  111. env['LIBSUFFIX'] = '.lib'
  112. def exists(env):
  113. return env.Detect('lib') or env.Detect('link')
  114. # vim:set ts=4 sw=4 et: