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 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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, 2009 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 _dllTargets(target, source, env, for_signature, paramtp):
  41. listCmd = []
  42. dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp)
  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 _dllSources(target, source, env, for_signature, paramtp):
  48. listCmd = []
  49. deffile = env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")
  50. for src in source:
  51. # Check explicitly for a non-None deffile so that the __cmp__
  52. # method of the base SCons.Util.Proxy class used for some Node
  53. # proxies doesn't try to use a non-existent __dict__ attribute.
  54. if deffile and src == deffile:
  55. # Treat this source as a .def file.
  56. listCmd.append("/def:%s" % src.get_string(for_signature))
  57. else:
  58. # Just treat it as a generic source file.
  59. listCmd.append(src)
  60. return listCmd
  61. def windowsShlinkTargets(target, source, env, for_signature):
  62. return _dllTargets(target, source, env, for_signature, 'SHLIB')
  63. def windowsShlinkSources(target, source, env, for_signature):
  64. return _dllSources(target, source, env, for_signature, 'SHLIB')
  65. def _windowsLdmodTargets(target, source, env, for_signature):
  66. """Get targets for loadable modules."""
  67. return _dllTargets(target, source, env, for_signature, 'LDMODULE')
  68. def _windowsLdmodSources(target, source, env, for_signature):
  69. """Get sources for loadable modules."""
  70. return _dllSources(target, source, env, for_signature, 'LDMODULE')
  71. def _dllEmitter(target, source, env, paramtp):
  72. """Common implementation of dll emitter."""
  73. SCons.Tool.msvc.validate_vars(env)
  74. extratargets = []
  75. extrasources = []
  76. dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp)
  77. no_import_lib = env.get('no_import_lib', 0)
  78. if not dll:
  79. raise SCons.Errors.UserError, 'A shared library should have exactly one target with the suffix: %s' % env.subst('$%sSUFFIX' % paramtp)
  80. insert_def = env.subst("$WINDOWS_INSERT_DEF")
  81. if not insert_def in ['', '0', 0] and \
  82. not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"):
  83. # append a def file to the list of sources
  84. extrasources.append(
  85. env.ReplaceIxes(dll,
  86. '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
  87. "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"))
  88. if env.has_key('PDB') and env['PDB']:
  89. pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
  90. extratargets.append(pdb)
  91. target[0].attributes.pdb = pdb
  92. if not no_import_lib and \
  93. not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"):
  94. # Append an import library to the list of targets.
  95. extratargets.append(
  96. env.ReplaceIxes(dll,
  97. '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
  98. "LIBPREFIX", "LIBSUFFIX"))
  99. # and .exp file is created if there are exports from a DLL
  100. extratargets.append(
  101. env.ReplaceIxes(dll,
  102. '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp,
  103. "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX"))
  104. return (target+extratargets, source+extrasources)
  105. def windowsLibEmitter(target, source, env):
  106. return _dllEmitter(target, source, env, 'SHLIB')
  107. def ldmodEmitter(target, source, env):
  108. """Emitter for loadable modules.
  109. Loadable modules are identical to shared libraries on Windows, but building
  110. them is subject to different parameters (LDMODULE*).
  111. """
  112. return _dllEmitter(target, source, env, 'LDMODULE')
  113. def prog_emitter(target, source, env):
  114. SCons.Tool.msvc.validate_vars(env)
  115. extratargets = []
  116. exe = env.FindIxes(target, "PROGPREFIX", "PROGSUFFIX")
  117. if not exe:
  118. raise SCons.Errors.UserError, "An executable should have exactly one target with the suffix: %s" % env.subst("$PROGSUFFIX")
  119. if env.has_key('PDB') and env['PDB']:
  120. pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
  121. extratargets.append(pdb)
  122. target[0].attributes.pdb = pdb
  123. return (target+extratargets,source)
  124. def RegServerFunc(target, source, env):
  125. if env.has_key('register') and env['register']:
  126. ret = regServerAction([target[0]], [source[0]], env)
  127. if ret:
  128. raise SCons.Errors.UserError, "Unable to register %s" % target[0]
  129. else:
  130. print "Registered %s sucessfully" % target[0]
  131. return ret
  132. return 0
  133. regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
  134. regServerCheck = SCons.Action.Action(RegServerFunc, None)
  135. shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
  136. compositeShLinkAction = shlibLinkAction + regServerCheck
  137. ldmodLinkAction = SCons.Action.Action('${TEMPFILE("$LDMODULE $LDMODULEFLAGS $_LDMODULE_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_LDMODULE_SOURCES")}')
  138. compositeLdmodAction = ldmodLinkAction + regServerCheck
  139. def generate(env):
  140. """Add Builders and construction variables for ar to an Environment."""
  141. SCons.Tool.createSharedLibBuilder(env)
  142. SCons.Tool.createProgBuilder(env)
  143. env['SHLINK'] = '$LINK'
  144. env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll')
  145. env['_SHLINK_TARGETS'] = windowsShlinkTargets
  146. env['_SHLINK_SOURCES'] = windowsShlinkSources
  147. env['SHLINKCOM'] = compositeShLinkAction
  148. env.Append(SHLIBEMITTER = [windowsLibEmitter])
  149. env['LINK'] = 'link'
  150. env['LINKFLAGS'] = SCons.Util.CLVar('/nologo')
  151. env['_PDB'] = pdbGenerator
  152. env['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $_LIBDIRFLAGS $_LIBFLAGS $_PDB $SOURCES.windows")}'
  153. env.Append(PROGEMITTER = [prog_emitter])
  154. env['LIBDIRPREFIX']='/LIBPATH:'
  155. env['LIBDIRSUFFIX']=''
  156. env['LIBLINKPREFIX']=''
  157. env['LIBLINKSUFFIX']='$LIBSUFFIX'
  158. env['WIN32DEFPREFIX'] = ''
  159. env['WIN32DEFSUFFIX'] = '.def'
  160. env['WIN32_INSERT_DEF'] = 0
  161. env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
  162. env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
  163. env['WINDOWS_INSERT_DEF'] = '${WIN32_INSERT_DEF}'
  164. env['WIN32EXPPREFIX'] = ''
  165. env['WIN32EXPSUFFIX'] = '.exp'
  166. env['WINDOWSEXPPREFIX'] = '${WIN32EXPPREFIX}'
  167. env['WINDOWSEXPSUFFIX'] = '${WIN32EXPSUFFIX}'
  168. env['WINDOWSSHLIBMANIFESTPREFIX'] = ''
  169. env['WINDOWSSHLIBMANIFESTSUFFIX'] = '${SHLIBSUFFIX}.manifest'
  170. env['WINDOWSPROGMANIFESTPREFIX'] = ''
  171. env['WINDOWSPROGMANIFESTSUFFIX'] = '${PROGSUFFIX}.manifest'
  172. env['REGSVRACTION'] = regServerCheck
  173. env['REGSVR'] = os.path.join(SCons.Platform.win32.get_system_root(),'System32','regsvr32')
  174. env['REGSVRFLAGS'] = '/s '
  175. env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.windows}'
  176. # Loadable modules are on Windows the same as shared libraries, but they
  177. # are subject to different build parameters (LDMODULE* variables).
  178. # Therefore LDMODULE* variables correspond as much as possible to
  179. # SHLINK*/SHLIB* ones.
  180. SCons.Tool.createLoadableModuleBuilder(env)
  181. env['LDMODULE'] = '$SHLINK'
  182. env['LDMODULEPREFIX'] = '$SHLIBPREFIX'
  183. env['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
  184. env['LDMODULEFLAGS'] = '$SHLINKFLAGS'
  185. env['_LDMODULE_TARGETS'] = _windowsLdmodTargets
  186. env['_LDMODULE_SOURCES'] = _windowsLdmodSources
  187. env['LDMODULEEMITTER'] = [ldmodEmitter]
  188. env['LDMODULECOM'] = compositeLdmodAction
  189. def exists(env):
  190. platform = env.get('PLATFORM', '')
  191. if platform in ('win32', 'cygwin'):
  192. # Only explicitly search for a 'link' executable on Windows
  193. # systems. Some other systems (e.g. Ubuntu Linux) have an
  194. # executable named 'link' and we don't want that to make SCons
  195. # think Visual Studio is installed.
  196. return env.Detect('link')
  197. return None
  198. # Local Variables:
  199. # tab-width:4
  200. # indent-tabs-mode:nil
  201. # End:
  202. # vim: set expandtab tabstop=4 shiftwidth=4: