1 #coments are #JB where this file was altered by Jasen Betts
2 # email: 'n@tres'.join(['jase','hna.com'])
6 Tool-specific initialization for MinGW (http://www.mingw.org/)
8 There normally shouldn't be any need to import this module directly.
9 It will usually be imported through the generic SCons.Tool.Tool()
15 # Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
17 # Permission is hereby granted, free of charge, to any person obtaining
18 # a copy of this software and associated documentation files (the
19 # "Software"), to deal in the Software without restriction, including
20 # without limitation the rights to use, copy, modify, merge, publish,
21 # distribute, sublicense, and/or sell copies of the Software, and to
22 # permit persons to whom the Software is furnished to do so, subject to
23 # the following conditions:
25 # The above copyright notice and this permission notice shall be included
26 # in all copies or substantial portions of the Software.
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
29 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
30 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 __revision__
= "/home/scons/scons/branch.0/branch.96/baseline/src/engine/SCons/Tool/mingw.py 0.96.91.D001 2005/09/08 09:14:36 knight"
48 # This is what we search for to find mingw:
49 prefixes
= SCons
.Util
.Split("""
58 for prefix
in prefixes
:
59 # First search in the SCons path and then the OS path:
60 if env
.WhereIs(prefix
+ 'gcc') or SCons
.Util
.WhereIs(prefix
+ 'gcc'):
65 def shlib_generator(target
, source
, env
, for_signature
):
66 cmd
= SCons
.Util
.CLVar(['$SHLINK', '$SHLINKFLAGS'])
68 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
69 if dll
: cmd
.extend(['-o', dll
])
71 cmd
.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
73 implib
= env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX')
74 if implib
: cmd
.append('-Wl,--out-implib,'+implib
.get_string(for_signature
))
76 def_target
= env
.FindIxes(target
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
77 if def_target
: cmd
.append('-Wl,--output-def,'+def_target
.get_string(for_signature
))
81 def shlib_emitter(target
, source
, env
):
82 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
83 no_import_lib
= env
.get('no_import_lib', 0)
86 raise SCons
.Errors
.UserError
, "A shared library should have exactly one target with the suffix: %s" % env
.subst("$SHLIBSUFFIX")
88 if not no_import_lib
and \
89 not env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX'):
91 # Append an import library to the list of targets.
92 target
.append(env
.ReplaceIxes(dll
,
93 'SHLIBPREFIX', 'SHLIBSUFFIX',
94 'LIBPREFIX', 'LIBSUFFIX'))
96 # Append a def file target if there isn't already a def file target
97 # or a def file source. There is no option to disable def file
98 # target emitting, because I can't figure out why someone would ever
99 # want to turn it off.
100 def_source
= env
.FindIxes(source
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
101 def_target
= env
.FindIxes(target
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
102 if not def_source
and not def_target
:
103 target
.append(env
.ReplaceIxes(dll
,
104 'SHLIBPREFIX', 'SHLIBSUFFIX',
105 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
107 return (target
, source
)
109 #JB """ I'm blindly susbstuting lines from the mingw.py
110 #JB file becase these lines cause python errors here. """
111 #JB shlib_action = SCons.Action.Action(shlib_generator,generator=1)
112 shlib_action
= SCons
.Action
.CommandGenerator(shlib_generator
)
114 res_action
= SCons
.Action
.Action('$RCCOM', '$RCCOMSTR')
116 #JB """ changed for what was in mingw.py """
117 #JB res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
118 #JB source_scanner=SCons.Tool.SourceFileScanner)
120 res_builder
= SCons
.Builder
.Builder(action
='$RCCOM', suffix
='.o',
121 source_scanner
=SCons
.Defaults
.ObjSourceScan
)
123 #JB SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
124 SCons
.Defaults
.ObjSourceScan
.add_scanner('.rc', SCons
.Defaults
.CScan
)
125 #JB """ no more changes """
128 mingw_prefix
= find(env
)
131 dir = os
.path
.dirname(env
.WhereIs(mingw_prefix
+ 'gcc') or SCons
.Util
.WhereIs(mingw_prefix
+ 'gcc'))
133 # The mingw bin directory must be added to the path:
134 path
= env
['ENV'].get('PATH', [])
137 if SCons
.Util
.is_String(path
):
138 path
= string
.split(path
, os
.pathsep
)
140 env
['ENV']['PATH'] = string
.join([dir] + path
, os
.pathsep
)
142 # Most of mingw is the same as gcc and friends...
143 gnu_tools
= ['gcc', 'g++', 'gnulink', 'ar', 'gas']
144 for tool
in gnu_tools
:
145 SCons
.Tool
.Tool(tool
)(env
)
147 #... but a few things differ:
148 env
['CC'] = mingw_prefix
+ 'gcc'
149 env
['SHCCFLAGS'] = SCons
.Util
.CLVar('$CCFLAGS')
150 env
['CXX'] = mingw_prefix
+ 'g++'
151 env
['SHCXXFLAGS'] = SCons
.Util
.CLVar('$CXXFLAGS')
152 env
['SHLINKFLAGS'] = SCons
.Util
.CLVar('$LINKFLAGS -shared')
153 env
['SHLINKCOM'] = shlib_action
154 env
['AR'] = mingw_prefix
+ 'ar'
155 env
['RANLIB'] = mingw_prefix
+ 'ranlib'
156 env
.Append(SHLIBEMITTER
= [shlib_emitter
])
157 env
['LINK'] = mingw_prefix
+ 'gcc'
158 env
['AS'] = mingw_prefix
+ 'as'
159 env
['WIN32DEFPREFIX'] = ''
160 env
['WIN32DEFSUFFIX'] = '.def'
161 env
['SHOBJSUFFIX'] = '.o'
162 env
['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
164 env
['RC'] = mingw_prefix
+ 'windres'
165 env
['RCFLAGS'] = SCons
.Util
.CLVar('')
166 env
['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET)} $)'
167 env
['RCINCPREFIX'] = '--include-dir '
168 env
['RCINCSUFFIX'] = ''
169 env
['RCCOM'] = '$RC $RCINCFLAGS $RCINCPREFIX $SOURCE.dir $RCFLAGS -i $SOURCE -o $TARGET'
170 env
['BUILDERS']['RES'] = res_builder
172 # Some setting from the platform also have to be overridden:
173 env
['OBJPREFIX'] = ''
174 env
['OBJSUFFIX'] = '.o'
175 env
['LIBPREFIX'] = 'lib'
176 env
['LIBSUFFIX'] = '.a'
177 env
['SHOBJPREFIX'] = '$OBJPREFIX'
178 env
['SHOBJSUFFIX'] = '$OBJSUFFIX'
179 env
['PROGPREFIX'] = ''
180 env
['PROGSUFFIX'] = '.exe'
181 env
['LIBPREFIX'] = ''
182 env
['LIBSUFFIX'] = '.lib'
183 env
['SHLIBPREFIX'] = ''
184 env
['SHLIBSUFFIX'] = '.dll'
185 env
['LIBPREFIXES'] = [ '$LIBPREFIX' ]
186 env
['LIBSUFFIXES'] = [ '$LIBSUFFIX' ]