1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org"""SCons.Tool.gcc
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgTool-specific initialization for MinGW (http://www.mingw.org/)
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgThere normally shouldn't be any need to import this module directly.
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgIt will usually be imported through the generic SCons.Tool.Tool()
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgselection method.
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgSee also http://www.scons.org/wiki/CrossCompilingMingw
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org"""
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# Permission is hereby granted, free of charge, to any person obtaining
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# a copy of this software and associated documentation files (the
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# "Software"), to deal in the Software without restriction, including
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# without limitation the rights to use, copy, modify, merge, publish,
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# distribute, sublicense, and/or sell copies of the Software, and to
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# permit persons to whom the Software is furnished to do so, subject to
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# the following conditions:
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# The above copyright notice and this permission notice shall be included
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# in all copies or substantial portions of the Software.
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport os
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport os.path
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport string
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport SCons.Action
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport SCons.Builder
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport SCons.Tool
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport SCons.Util
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# This is what we search for to find mingw:
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprefixes32 = SCons.Util.Split("""
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    mingw32-
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    mingw32msvc-
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i386-mingw32-
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i486-mingw32-
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i586-mingw32-
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i686-mingw32-
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i386-mingw32msvc-
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i486-mingw32msvc-
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i586-mingw32msvc-
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i686-mingw32msvc-
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i686-pc-mingw32-
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    i686-w64-mingw32-
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org""")
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprefixes64 = SCons.Util.Split("""
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    x86_64-w64-mingw32-
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    amd64-mingw32-
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    amd64-mingw32msvc-
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    amd64-pc-mingw32-
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org""")
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef find(env):
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if env['machine'] == 'x86_64':
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        prefixes = prefixes64
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    else:
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        prefixes = prefixes32
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    for prefix in prefixes:
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        # First search in the SCons path and then the OS path:
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return prefix
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return ''
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef shlib_generator(target, source, env, for_signature):
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if dll: cmd.extend(['-o', dll])
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return [cmd]
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef shlib_emitter(target, source, env):
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    no_import_lib = env.get('no_import_lib', 0)
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if not dll:
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if not no_import_lib and \
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        # Append an import library to the list of targets.
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        target.append(env.ReplaceIxes(dll,
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      'SHLIBPREFIX', 'SHLIBSUFFIX',
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      'LIBPREFIX', 'LIBSUFFIX'))
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Append a def file target if there isn't already a def file target
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # or a def file source. There is no option to disable def file
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # target emitting, because I can't figure out why someone would ever
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # want to turn it off.
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    def_source = env.FindIxes(source, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    def_target = env.FindIxes(target, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if not def_source and not def_target:
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        target.append(env.ReplaceIxes(dll,
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      'SHLIBPREFIX', 'SHLIBSUFFIX',
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return (target, source)
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgshlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgres_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgres_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    source_scanner=SCons.Tool.SourceFileScanner)
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgSCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef compile_without_gstabs(env, sources, c_file):
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    '''This is a hack used to compile some source files without the
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    -gstabs option.
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    It seems that some versions of mingw32's gcc (4.4.2 at least) die
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    when compiling large files with the -gstabs option.  -gstabs is
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    related to debug symbols and can be omitted from the effected
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    files.
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    This function compiles the given c_file without -gstabs, removes
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    the c_file from the sources list, then appends the new .o file to
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    sources.  Then return the new sources list.
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    '''
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Modify CCFLAGS to not have -gstabs option:
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env2 = env.Clone()
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    flags = str(env2['CCFLAGS'])
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    flags = flags.replace("-gstabs", "")
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env2['CCFLAGS'] = SCons.Util.CLVar(flags)
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Build the special-case files:
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    obj_file = env2.SharedObject(c_file)
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Replace ".cpp" or ".c" with ".o"
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    o_file = c_file.replace(".cpp", ".o")
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    o_file = o_file.replace(".c", ".o")
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Replace the .c files with the specially-compiled .o file
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    sources.remove(c_file)
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    sources.append(o_file)
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return sources
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef generate(env):
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    mingw_prefix = find(env)
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if mingw_prefix:
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        dir = os.path.dirname(env.WhereIs(mingw_prefix + 'gcc') or SCons.Util.WhereIs(mingw_prefix + 'gcc'))
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        # The mingw bin directory must be added to the path:
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        path = env['ENV'].get('PATH', [])
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if not path:
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            path = []
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if SCons.Util.is_String(path):
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            path = string.split(path, os.pathsep)
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        env['ENV']['PATH'] = string.join([dir] + path, os.pathsep)
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Most of mingw is the same as gcc and friends...
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas']
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    for tool in gnu_tools:
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        SCons.Tool.Tool(tool)(env)
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    #... but a few things differ:
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['CC'] = mingw_prefix + 'gcc'
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['CXX'] = mingw_prefix + 'g++'
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHLINKCOM']   = shlib_action
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env.Append(SHLIBEMITTER = [shlib_emitter])
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['LINK'] = mingw_prefix + 'g++'
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['AR'] = mingw_prefix + 'ar'
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['RANLIB'] = mingw_prefix + 'ranlib'
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['LINK'] = mingw_prefix + 'g++'
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['AS'] = mingw_prefix + 'as'
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['WIN32DEFPREFIX']        = ''
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['WIN32DEFSUFFIX']        = '.def'
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHOBJSUFFIX'] = '.o'
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['RC'] = mingw_prefix + 'windres'
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['RCFLAGS'] = SCons.Util.CLVar('')
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['BUILDERS']['RES'] = res_builder
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # Some setting from the platform also have to be overridden:
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['OBJPREFIX']      = ''
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['OBJSUFFIX']      = '.o'
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHOBJPREFIX']    = '$OBJPREFIX'
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHOBJSUFFIX']    = '$OBJSUFFIX'
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['PROGPREFIX']     = ''
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['PROGSUFFIX']     = '.exe'
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['LIBPREFIX']      = 'lib'
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['LIBSUFFIX']      = '.a'
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHLIBPREFIX']    = ''
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['SHLIBSUFFIX']    = '.dll'
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['LIBPREFIXES']    = [ 'lib', '' ]
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env['LIBSUFFIXES']    = [ '.a', '.lib' ]
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # MinGW x86 port of gdb does not handle well dwarf debug info which is the
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # default in recent gcc versions.  The x64 port gdb from mingw-w64 seems to
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    # handle it fine though, so stick with the default there.
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if env['machine'] != 'x86_64':
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        env.AppendUnique(CCFLAGS = ['-gstabs'])
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    env.AddMethod(compile_without_gstabs, 'compile_without_gstabs')
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdef exists(env):
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return find(env)
234