3 Tool-specific initialization for the Metrowerks CodeWarrior compiler.
5 There normally shouldn't be any need to import this module directly.
6 It will usually be imported through the generic SCons.Tool.Tool()
11 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
13 # Permission is hereby granted, free of charge, to any person obtaining
14 # a copy of this software and associated documentation files (the
15 # "Software"), to deal in the Software without restriction, including
16 # without limitation the rights to use, copy, modify, merge, publish,
17 # distribute, sublicense, and/or sell copies of the Software, and to
18 # permit persons to whom the Software is furnished to do so, subject to
19 # the following conditions:
21 # The above copyright notice and this permission notice shall be included
22 # in all copies or substantial portions of the Software.
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
26 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 __revision__ = "src/engine/SCons/Tool/mwcc.py 3842 2008/12/20 22:59:52 scons"
42 """Set MWCW_VERSION, MWCW_VERSIONS, and some codewarrior environment vars
44 MWCW_VERSIONS is set to a list of objects representing installed versions
46 MWCW_VERSION is set to the version object that will be used for building.
47 MWCW_VERSION can be set to a string during Environment
48 construction to influence which version is chosen, otherwise
49 the latest one from MWCW_VERSIONS is used.
51 Returns true if at least one version is found, false otherwise
53 desired = env.get('MWCW_VERSION', '')
55 # return right away if the variables are already set
56 if isinstance(desired, MWVersion):
61 versions = find_versions()
69 version = versions[-1]
71 env['MWCW_VERSIONS'] = versions
72 env['MWCW_VERSION'] = version
77 env.PrependENVPath('PATH', version.clpath)
78 env.PrependENVPath('PATH', version.dllpath)
80 ENV['CWFolder'] = version.path
81 ENV['LM_LICENSE_FILE'] = version.license
82 plus = lambda x: '+%s' % x
83 ENV['MWCIncludes'] = string.join(map(plus, version.includes), os.pathsep)
84 ENV['MWLibraries'] = string.join(map(plus, version.libs), os.pathsep)
89 """Return a list of MWVersion objects representing installed versions"""
92 ### This function finds CodeWarrior by reading from the registry on
93 ### Windows. Some other method needs to be implemented for other
94 ### platforms, maybe something that calls env.WhereIs('mwcc')
96 if SCons.Util.can_read_reg:
98 HLM = SCons.Util.HKEY_LOCAL_MACHINE
99 product = 'SOFTWARE\\Metrowerks\\CodeWarrior\\Product Versions'
100 product_key = SCons.Util.RegOpenKeyEx(HLM, product)
104 name = product + '\\' + SCons.Util.RegEnumKey(product_key, i)
105 name_key = SCons.Util.RegOpenKeyEx(HLM, name)
108 version = SCons.Util.RegQueryValueEx(name_key, 'VERSION')
109 path = SCons.Util.RegQueryValueEx(name_key, 'PATH')
110 mwv = MWVersion(version[0], path[0], 'Win32-X86')
112 except SCons.Util.RegError:
117 except SCons.Util.RegError:
124 def __init__(self, version, path, platform):
125 self.version = version
127 self.platform = platform
128 self.clpath = os.path.join(path, 'Other Metrowerks Tools',
129 'Command Line Tools')
130 self.dllpath = os.path.join(path, 'Bin')
132 # The Metrowerks tools don't store any configuration data so they
133 # are totally dumb when it comes to locating standard headers,
134 # libraries, and other files, expecting all the information
135 # to be handed to them in environment variables. The members set
136 # below control what information scons injects into the environment
138 ### The paths below give a normal build environment in CodeWarrior for
139 ### Windows, other versions of CodeWarrior might need different paths.
141 msl = os.path.join(path, 'MSL')
142 support = os.path.join(path, '%s Support' % platform)
144 self.license = os.path.join(path, 'license.dat')
145 self.includes = [msl, support]
146 self.libs = [msl, support]
152 CSuffixes = ['.c', '.C']
153 CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
157 """Add Builders and construction variables for the mwcc to an Environment."""
158 import SCons.Defaults
163 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
165 for suffix in CSuffixes:
166 static_obj.add_action(suffix, SCons.Defaults.CAction)
167 shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
169 for suffix in CXXSuffixes:
170 static_obj.add_action(suffix, SCons.Defaults.CXXAction)
171 shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
173 env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -nolink -o $TARGET $SOURCES'
176 env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
179 env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
182 env['SHCCFLAGS'] = '$CCFLAGS'
183 env['SHCFLAGS'] = '$CFLAGS'
184 env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
186 env['SHCXX'] = '$CXX'
187 env['SHCXXFLAGS'] = '$CXXFLAGS'
188 env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
190 env['CFILESUFFIX'] = '.c'
191 env['CXXFILESUFFIX'] = '.cpp'
192 env['CPPDEFPREFIX'] = '-D'
193 env['CPPDEFSUFFIX'] = ''
194 env['INCPREFIX'] = '-I'
195 env['INCSUFFIX'] = ''