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.

mslink_sa.py 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. """mslink_sa
  2. Tool-specific initialization for the Microsoft linker.
  3. Based on SCons.Tool.mslink, without the MSVS 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.path
  28. import SCons.Action
  29. import SCons.Defaults
  30. import SCons.Errors
  31. import SCons.Platform.win32
  32. import SCons.Tool
  33. import SCons.Tool.msvc
  34. import SCons.Util
  35. def pdbGenerator(env, target, source, for_signature):
  36. try:
  37. return ['/PDB:%s' % target[0].attributes.pdb, '/DEBUG']
  38. except (AttributeError, IndexError):
  39. return None
  40. def windowsShlinkTargets(target, source, env, for_signature):
  41. listCmd = []
  42. dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
  43. if dll: listCmd.append("/out:%s"%dll.get_string(for_signature))
  44. implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
  45. if implib: listCmd.append("/implib:%s"%implib.get_string(for_signature))
  46. return listCmd
  47. def windowsShlinkSources(target, source, env, for_signature):
  48. listCmd = []
  49. deffile = env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")
  50. for src in source:
  51. if src == deffile:
  52. # Treat this source as a .def file.
  53. listCmd.append("/def:%s" % src.get_string(for_signature))
  54. else:
  55. # Just treat it as a generic source file.
  56. listCmd.append(src)
  57. return listCmd
  58. def windowsLibEmitter(target, source, env):
  59. SCons.Tool.msvc.validate_vars(env)
  60. extratargets = []
  61. extrasources = []
  62. dll = env.FindIxes(target, "SHLIBPREFIX", "SHLIBSUFFIX")
  63. no_import_lib = env.get('no_import_lib', 0)
  64. if not dll:
  65. raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
  66. insert_def = env.subst("$WINDOWS_INSERT_DEF")
  67. if not insert_def in ['', '0', 0] and \
  68. not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"):
  69. # append a def file to the list of sources
  70. extrasources.append(
  71. env.ReplaceIxes(dll,
  72. "SHLIBPREFIX", "SHLIBSUFFIX",
  73. "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"))
  74. if env.has_key('PDB') and env['PDB']:
  75. pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
  76. extratargets.append(pdb)
  77. target[0].attributes.pdb = pdb
  78. if not no_import_lib and \
  79. not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"):
  80. # Append an import library to the list of targets.
  81. extratargets.append(
  82. env.ReplaceIxes(dll,
  83. "SHLIBPREFIX", "SHLIBSUFFIX",
  84. "LIBPREFIX", "LIBSUFFIX"))
  85. # and .exp file is created if there are exports from a DLL
  86. extratargets.append(
  87. env.ReplaceIxes(dll,
  88. "SHLIBPREFIX", "SHLIBSUFFIX",
  89. "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX"))
  90. return (target+extratargets, source+extrasources)
  91. def prog_emitter(target, source, env):
  92. SCons.Tool.msvc.validate_vars(env)
  93. extratargets = []
  94. exe = env.FindIxes(target, "PROGPREFIX", "PROGSUFFIX")
  95. if not exe:
  96. raise SCons.Errors.UserError, "An executable should have exactly one target with the suffix: %s" % env.subst("$PROGSUFFIX")
  97. if env.has_key('PDB') and env['PDB']:
  98. pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
  99. extratargets.append(pdb)
  100. target[0].attributes.pdb = pdb
  101. return (target+extratargets,source)
  102. def RegServerFunc(target, source, env):
  103. if env.has_key('register') and env['register']:
  104. ret = regServerAction([target[0]], [source[0]], env)
  105. if ret:
  106. raise SCons.Errors.UserError, "Unable to register %s" % target[0]
  107. else:
  108. print "Registered %s sucessfully" % target[0]
  109. return ret
  110. return 0
  111. regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
  112. regServerCheck = SCons.Action.Action(RegServerFunc, None)
  113. shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
  114. compositeLinkAction = shlibLinkAction + regServerCheck
  115. def generate(env):
  116. """Add Builders and construction variables for ar to an Environment."""
  117. SCons.Tool.createSharedLibBuilder(env)
  118. SCons.Tool.createProgBuilder(env)
  119. env['SHLINK'] = '$LINK'
  120. env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll')
  121. env['_SHLINK_TARGETS'] = windowsShlinkTargets
  122. env['_SHLINK_SOURCES'] = windowsShlinkSources
  123. env['SHLINKCOM'] = compositeLinkAction
  124. env.Append(SHLIBEMITTER = [windowsLibEmitter])
  125. env['LINK'] = 'link'
  126. env['LINKFLAGS'] = SCons.Util.CLVar('/nologo')
  127. env['_PDB'] = pdbGenerator
  128. env['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $SOURCES.windows")}'
  129. env.Append(PROGEMITTER = [prog_emitter])
  130. env['LIBDIRPREFIX']='/LIBPATH:'
  131. env['LIBDIRSUFFIX']=''
  132. env['LIBLINKPREFIX']=''
  133. env['LIBLINKSUFFIX']='$LIBSUFFIX'
  134. env['WIN32DEFPREFIX'] = ''
  135. env['WIN32DEFSUFFIX'] = '.def'
  136. env['WIN32_INSERT_DEF'] = 0
  137. env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
  138. env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
  139. env['WINDOWS_INSERT_DEF'] = '${WIN32_INSERT_DEF}'
  140. env['WIN32EXPPREFIX'] = ''
  141. env['WIN32EXPSUFFIX'] = '.exp'
  142. env['WINDOWSEXPPREFIX'] = '${WIN32EXPPREFIX}'
  143. env['WINDOWSEXPSUFFIX'] = '${WIN32EXPSUFFIX}'
  144. env['WINDOWSSHLIBMANIFESTPREFIX'] = ''
  145. env['WINDOWSSHLIBMANIFESTSUFFIX'] = '${SHLIBSUFFIX}.manifest'
  146. env['WINDOWSPROGMANIFESTPREFIX'] = ''
  147. env['WINDOWSPROGMANIFESTSUFFIX'] = '${PROGSUFFIX}.manifest'
  148. env['REGSVRACTION'] = regServerCheck
  149. env['REGSVR'] = os.path.join(SCons.Platform.win32.get_system_root(),'System32','regsvr32')
  150. env['REGSVRFLAGS'] = '/s '
  151. env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.windows}'
  152. # For most platforms, a loadable module is the same as a shared
  153. # library. Platforms which are different can override these, but
  154. # setting them the same means that LoadableModule works everywhere.
  155. SCons.Tool.createLoadableModuleBuilder(env)
  156. env['LDMODULE'] = '$SHLINK'
  157. env['LDMODULEPREFIX'] = '$SHLIBPREFIX'
  158. env['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
  159. env['LDMODULEFLAGS'] = '$SHLINKFLAGS'
  160. # We can't use '$SHLINKCOM' here because that will stringify the
  161. # action list on expansion, and will then try to execute expanded
  162. # strings, with the upshot that it would try to execute RegServerFunc
  163. # as a command.
  164. env['LDMODULECOM'] = compositeLinkAction
  165. def exists(env):
  166. platform = env.get('PLATFORM', '')
  167. if platform in ('win32', 'cygwin'):
  168. # Only explicitly search for a 'link' executable on Windows
  169. # systems. Some other systems (e.g. Ubuntu Linux) have an
  170. # executable named 'link' and we don't want that to make SCons
  171. # think Visual Studio is installed.
  172. return env.Detect('link')
  173. return None
  174. # vim:set ts=4 sw=4 et: