PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/couchjs/scons/scons-local-2.0.1/SCons/Tool/mwcc.py

http://github.com/cloudant/bigcouch
Python | 207 lines | 196 code | 0 blank | 11 comment | 0 complexity | 04bd10c00a6c94765df58d1bd5124cf7 MD5 | raw file
Possible License(s): Apache-2.0
  1. """SCons.Tool.mwcc
  2. Tool-specific initialization for the Metrowerks CodeWarrior compiler.
  3. There normally shouldn't be any need to import this module directly.
  4. It will usually be imported through the generic SCons.Tool.Tool()
  5. selection method.
  6. """
  7. #
  8. # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
  9. #
  10. # Permission is hereby granted, free of charge, to any person obtaining
  11. # a copy of this software and associated documentation files (the
  12. # "Software"), to deal in the Software without restriction, including
  13. # without limitation the rights to use, copy, modify, merge, publish,
  14. # distribute, sublicense, and/or sell copies of the Software, and to
  15. # permit persons to whom the Software is furnished to do so, subject to
  16. # the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included
  19. # in all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  22. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  23. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. #
  29. __revision__ = "src/engine/SCons/Tool/mwcc.py 5134 2010/08/16 23:02:40 bdeegan"
  30. import os
  31. import os.path
  32. import SCons.Util
  33. def set_vars(env):
  34. """Set MWCW_VERSION, MWCW_VERSIONS, and some codewarrior environment vars
  35. MWCW_VERSIONS is set to a list of objects representing installed versions
  36. MWCW_VERSION is set to the version object that will be used for building.
  37. MWCW_VERSION can be set to a string during Environment
  38. construction to influence which version is chosen, otherwise
  39. the latest one from MWCW_VERSIONS is used.
  40. Returns true if at least one version is found, false otherwise
  41. """
  42. desired = env.get('MWCW_VERSION', '')
  43. # return right away if the variables are already set
  44. if isinstance(desired, MWVersion):
  45. return 1
  46. elif desired is None:
  47. return 0
  48. versions = find_versions()
  49. version = None
  50. if desired:
  51. for v in versions:
  52. if str(v) == desired:
  53. version = v
  54. elif versions:
  55. version = versions[-1]
  56. env['MWCW_VERSIONS'] = versions
  57. env['MWCW_VERSION'] = version
  58. if version is None:
  59. return 0
  60. env.PrependENVPath('PATH', version.clpath)
  61. env.PrependENVPath('PATH', version.dllpath)
  62. ENV = env['ENV']
  63. ENV['CWFolder'] = version.path
  64. ENV['LM_LICENSE_FILE'] = version.license
  65. plus = lambda x: '+%s' % x
  66. ENV['MWCIncludes'] = os.pathsep.join(map(plus, version.includes))
  67. ENV['MWLibraries'] = os.pathsep.join(map(plus, version.libs))
  68. return 1
  69. def find_versions():
  70. """Return a list of MWVersion objects representing installed versions"""
  71. versions = []
  72. ### This function finds CodeWarrior by reading from the registry on
  73. ### Windows. Some other method needs to be implemented for other
  74. ### platforms, maybe something that calls env.WhereIs('mwcc')
  75. if SCons.Util.can_read_reg:
  76. try:
  77. HLM = SCons.Util.HKEY_LOCAL_MACHINE
  78. product = 'SOFTWARE\\Metrowerks\\CodeWarrior\\Product Versions'
  79. product_key = SCons.Util.RegOpenKeyEx(HLM, product)
  80. i = 0
  81. while True:
  82. name = product + '\\' + SCons.Util.RegEnumKey(product_key, i)
  83. name_key = SCons.Util.RegOpenKeyEx(HLM, name)
  84. try:
  85. version = SCons.Util.RegQueryValueEx(name_key, 'VERSION')
  86. path = SCons.Util.RegQueryValueEx(name_key, 'PATH')
  87. mwv = MWVersion(version[0], path[0], 'Win32-X86')
  88. versions.append(mwv)
  89. except SCons.Util.RegError:
  90. pass
  91. i = i + 1
  92. except SCons.Util.RegError:
  93. pass
  94. return versions
  95. class MWVersion(object):
  96. def __init__(self, version, path, platform):
  97. self.version = version
  98. self.path = path
  99. self.platform = platform
  100. self.clpath = os.path.join(path, 'Other Metrowerks Tools',
  101. 'Command Line Tools')
  102. self.dllpath = os.path.join(path, 'Bin')
  103. # The Metrowerks tools don't store any configuration data so they
  104. # are totally dumb when it comes to locating standard headers,
  105. # libraries, and other files, expecting all the information
  106. # to be handed to them in environment variables. The members set
  107. # below control what information scons injects into the environment
  108. ### The paths below give a normal build environment in CodeWarrior for
  109. ### Windows, other versions of CodeWarrior might need different paths.
  110. msl = os.path.join(path, 'MSL')
  111. support = os.path.join(path, '%s Support' % platform)
  112. self.license = os.path.join(path, 'license.dat')
  113. self.includes = [msl, support]
  114. self.libs = [msl, support]
  115. def __str__(self):
  116. return self.version
  117. CSuffixes = ['.c', '.C']
  118. CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
  119. def generate(env):
  120. """Add Builders and construction variables for the mwcc to an Environment."""
  121. import SCons.Defaults
  122. import SCons.Tool
  123. set_vars(env)
  124. static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
  125. for suffix in CSuffixes:
  126. static_obj.add_action(suffix, SCons.Defaults.CAction)
  127. shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
  128. for suffix in CXXSuffixes:
  129. static_obj.add_action(suffix, SCons.Defaults.CXXAction)
  130. shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
  131. env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -nolink -o $TARGET $SOURCES'
  132. env['CC'] = 'mwcc'
  133. env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
  134. env['CXX'] = 'mwcc'
  135. env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
  136. env['SHCC'] = '$CC'
  137. env['SHCCFLAGS'] = '$CCFLAGS'
  138. env['SHCFLAGS'] = '$CFLAGS'
  139. env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
  140. env['SHCXX'] = '$CXX'
  141. env['SHCXXFLAGS'] = '$CXXFLAGS'
  142. env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
  143. env['CFILESUFFIX'] = '.c'
  144. env['CXXFILESUFFIX'] = '.cpp'
  145. env['CPPDEFPREFIX'] = '-D'
  146. env['CPPDEFSUFFIX'] = ''
  147. env['INCPREFIX'] = '-I'
  148. env['INCSUFFIX'] = ''
  149. #env['PCH'] = ?
  150. #env['PCHSTOP'] = ?
  151. def exists(env):
  152. return set_vars(env)
  153. # Local Variables:
  154. # tab-width:4
  155. # indent-tabs-mode:nil
  156. # End:
  157. # vim: set expandtab tabstop=4 shiftwidth=4: