3 Tool-specific initialization for MinGW (http://www.mingw.org/)
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()
9 See also http://www.scons.org/wiki/CrossCompilingMingw
13 # Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
15 # Permission is hereby granted, free of charge, to any person obtaining
16 # a copy of this software and associated documentation files (the
17 # "Software"), to deal in the Software without restriction, including
18 # without limitation the rights to use, copy, modify, merge, publish,
19 # distribute, sublicense, and/or sell copies of the Software, and to
20 # permit persons to whom the Software is furnished to do so, subject to
21 # the following conditions:
23 # The above copyright notice and this permission notice shall be included
24 # in all copies or substantial portions of the Software.
26 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
27 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
28 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 # This is what we search for to find mingw:
45 prefixes32
= SCons
.Util
.Split("""
58 prefixes64
= SCons
.Util
.Split("""
65 if env
['machine'] == 'x86_64':
69 for prefix
in prefixes
:
70 # First search in the SCons path and then the OS path:
71 if env
.WhereIs(prefix
+ 'gcc') or SCons
.Util
.WhereIs(prefix
+ 'gcc'):
76 def shlib_generator(target
, source
, env
, for_signature
):
77 cmd
= SCons
.Util
.CLVar(['$SHLINK', '$SHLINKFLAGS'])
79 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
80 if dll
: cmd
.extend(['-o', dll
])
82 cmd
.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
84 implib
= env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX')
85 if implib
: cmd
.append('-Wl,--out-implib,'+implib
.get_string(for_signature
))
87 def_target
= env
.FindIxes(target
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
88 if def_target
: cmd
.append('-Wl,--output-def,'+def_target
.get_string(for_signature
))
92 def shlib_emitter(target
, source
, env
):
93 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
94 no_import_lib
= env
.get('no_import_lib', 0)
97 raise SCons
.Errors
.UserError
, "A shared library should have exactly one target with the suffix: %s" % env
.subst("$SHLIBSUFFIX")
99 if not no_import_lib
and \
100 not env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX'):
102 # Append an import library to the list of targets.
103 target
.append(env
.ReplaceIxes(dll
,
104 'SHLIBPREFIX', 'SHLIBSUFFIX',
105 'LIBPREFIX', 'LIBSUFFIX'))
107 # Append a def file target if there isn't already a def file target
108 # or a def file source. There is no option to disable def file
109 # target emitting, because I can't figure out why someone would ever
110 # want to turn it off.
111 def_source
= env
.FindIxes(source
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
112 def_target
= env
.FindIxes(target
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
113 if not def_source
and not def_target
:
114 target
.append(env
.ReplaceIxes(dll
,
115 'SHLIBPREFIX', 'SHLIBSUFFIX',
116 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
118 return (target
, source
)
121 shlib_action
= SCons
.Action
.Action(shlib_generator
, '$SHLINKCOMSTR', generator
=1)
123 res_action
= SCons
.Action
.Action('$RCCOM', '$RCCOMSTR')
125 res_builder
= SCons
.Builder
.Builder(action
=res_action
, suffix
='.o',
126 source_scanner
=SCons
.Tool
.SourceFileScanner
)
127 SCons
.Tool
.SourceFileScanner
.add_scanner('.rc', SCons
.Defaults
.CScan
)
130 mingw_prefix
= find(env
)
133 dir = os
.path
.dirname(env
.WhereIs(mingw_prefix
+ 'gcc') or SCons
.Util
.WhereIs(mingw_prefix
+ 'gcc'))
135 # The mingw bin directory must be added to the path:
136 path
= env
['ENV'].get('PATH', [])
139 if SCons
.Util
.is_String(path
):
140 path
= string
.split(path
, os
.pathsep
)
142 env
['ENV']['PATH'] = string
.join([dir] + path
, os
.pathsep
)
144 # Most of mingw is the same as gcc and friends...
145 gnu_tools
= ['gcc', 'g++', 'gnulink', 'ar', 'gas']
146 for tool
in gnu_tools
:
147 SCons
.Tool
.Tool(tool
)(env
)
149 #... but a few things differ:
150 env
['CC'] = mingw_prefix
+ 'gcc'
151 env
['SHCCFLAGS'] = SCons
.Util
.CLVar('$CCFLAGS')
152 env
['CXX'] = mingw_prefix
+ 'g++'
153 env
['SHCXXFLAGS'] = SCons
.Util
.CLVar('$CXXFLAGS')
154 env
['SHLINKFLAGS'] = SCons
.Util
.CLVar('$LINKFLAGS -shared')
155 env
['SHLINKCOM'] = shlib_action
156 env
.Append(SHLIBEMITTER
= [shlib_emitter
])
157 env
['LINK'] = mingw_prefix
+ 'g++'
158 env
['AR'] = mingw_prefix
+ 'ar'
159 env
['RANLIB'] = mingw_prefix
+ 'ranlib'
160 env
['LINK'] = mingw_prefix
+ 'g++'
161 env
['AS'] = mingw_prefix
+ 'as'
162 env
['WIN32DEFPREFIX'] = ''
163 env
['WIN32DEFSUFFIX'] = '.def'
164 env
['SHOBJSUFFIX'] = '.o'
165 env
['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
167 env
['RC'] = mingw_prefix
+ 'windres'
168 env
['RCFLAGS'] = SCons
.Util
.CLVar('')
169 env
['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${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
['SHOBJPREFIX'] = '$OBJPREFIX'
176 env
['SHOBJSUFFIX'] = '$OBJSUFFIX'
177 env
['PROGPREFIX'] = ''
178 env
['PROGSUFFIX'] = '.exe'
179 env
['LIBPREFIX'] = 'lib'
180 env
['LIBSUFFIX'] = '.a'
181 env
['SHLIBPREFIX'] = ''
182 env
['SHLIBSUFFIX'] = '.dll'
183 env
['LIBPREFIXES'] = [ 'lib', '' ]
184 env
['LIBSUFFIXES'] = [ '.a', '.lib' ]
186 # MinGW port of gdb does not handle well dwarf debug info which is the
187 # default in recent gcc versions
188 env
.AppendUnique(CCFLAGS
= ['-gstabs'])
190 env
.AppendUnique(CPPDEFINES
= [('__MSVCRT_VERSION__', '0x0700')])
191 #env.AppendUnique(LIBS = ['iberty'])
192 env
.AppendUnique(SHLINKFLAGS
= ['-Wl,--enable-stdcall-fixup'])
193 #env.AppendUnique(SHLINKFLAGS = ['-Wl,--kill-at'])