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, 2009, 2010 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 5023 2010/06/14 22:05:46 scons"
41 """Set MWCW_VERSION, MWCW_VERSIONS, and some codewarrior environment vars
43 MWCW_VERSIONS is set to a list of objects representing installed versions
45 MWCW_VERSION is set to the version object that will be used for building.
46 MWCW_VERSION can be set to a string during Environment
47 construction to influence which version is chosen, otherwise
48 the latest one from MWCW_VERSIONS is used.
50 Returns true if at least one version is found, false otherwise
52 desired = env.get('MWCW_VERSION', '')
54 # return right away if the variables are already set
55 if isinstance(desired, MWVersion):
60 versions = find_versions()
68 version = versions[-1]
70 env['MWCW_VERSIONS'] = versions
71 env['MWCW_VERSION'] = version
76 env.PrependENVPath('PATH', version.clpath)
77 env.PrependENVPath('PATH', version.dllpath)
79 ENV['CWFolder'] = version.path
80 ENV['LM_LICENSE_FILE'] = version.license
81 plus = lambda x: '+%s' % x
82 ENV['MWCIncludes'] = os.pathsep.join(map(plus, version.includes))
83 ENV['MWLibraries'] = os.pathsep.join(map(plus, version.libs))
88 """Return a list of MWVersion objects representing installed versions"""
91 ### This function finds CodeWarrior by reading from the registry on
92 ### Windows. Some other method needs to be implemented for other
93 ### platforms, maybe something that calls env.WhereIs('mwcc')
95 if SCons.Util.can_read_reg:
97 HLM = SCons.Util.HKEY_LOCAL_MACHINE
98 product = 'SOFTWARE\\Metrowerks\\CodeWarrior\\Product Versions'
99 product_key = SCons.Util.RegOpenKeyEx(HLM, product)
103 name = product + '\\' + SCons.Util.RegEnumKey(product_key, i)
104 name_key = SCons.Util.RegOpenKeyEx(HLM, name)
107 version = SCons.Util.RegQueryValueEx(name_key, 'VERSION')
108 path = SCons.Util.RegQueryValueEx(name_key, 'PATH')
109 mwv = MWVersion(version[0], path[0], 'Win32-X86')
111 except SCons.Util.RegError:
116 except SCons.Util.RegError:
122 class MWVersion(object):
123 def __init__(self, version, path, platform):
124 self.version = version
126 self.platform = platform
127 self.clpath = os.path.join(path, 'Other Metrowerks Tools',
128 'Command Line Tools')
129 self.dllpath = os.path.join(path, 'Bin')
131 # The Metrowerks tools don't store any configuration data so they
132 # are totally dumb when it comes to locating standard headers,
133 # libraries, and other files, expecting all the information
134 # to be handed to them in environment variables. The members set
135 # below control what information scons injects into the environment
137 ### The paths below give a normal build environment in CodeWarrior for
138 ### Windows, other versions of CodeWarrior might need different paths.
140 msl = os.path.join(path, 'MSL')
141 support = os.path.join(path, '%s Support' % platform)
143 self.license = os.path.join(path, 'license.dat')
144 self.includes = [msl, support]
145 self.libs = [msl, support]
151 CSuffixes = ['.c', '.C']
152 CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
156 """Add Builders and construction variables for the mwcc to an Environment."""
157 import SCons.Defaults
162 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
164 for suffix in CSuffixes:
165 static_obj.add_action(suffix, SCons.Defaults.CAction)
166 shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
168 for suffix in CXXSuffixes:
169 static_obj.add_action(suffix, SCons.Defaults.CXXAction)
170 shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
172 env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -nolink -o $TARGET $SOURCES'
175 env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
178 env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
181 env['SHCCFLAGS'] = '$CCFLAGS'
182 env['SHCFLAGS'] = '$CFLAGS'
183 env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
185 env['SHCXX'] = '$CXX'
186 env['SHCXXFLAGS'] = '$CXXFLAGS'
187 env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
189 env['CFILESUFFIX'] = '.c'
190 env['CXXFILESUFFIX'] = '.cpp'
191 env['CPPDEFPREFIX'] = '-D'
192 env['CPPDEFSUFFIX'] = ''
193 env['INCPREFIX'] = '-I'
194 env['INCSUFFIX'] = ''
205 # indent-tabs-mode:nil
207 # vim: set expandtab tabstop=4 shiftwidth=4: