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()
14 # Permission is hereby granted, free of charge, to any person obtaining
15 # a copy of this software and associated documentation files (the
16 # "Software"), to deal in the Software without restriction, including
17 # without limitation the rights to use, copy, modify, merge, publish,
18 # distribute, sublicense, and/or sell copies of the Software, and to
19 # permit persons to whom the Software is furnished to do so, subject to
20 # the following conditions:
22 # The above copyright notice and this permission notice shall be included
23 # in all copies or substantial portions of the Software.
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
45 # This is what we search for to find mingw:
46 key_program = 'mingw32-gcc'
49 # First search in the SCons path and then the OS path:
50 return env.WhereIs(key_program) or SCons.Util.WhereIs(key_program)
52 def shlib_generator(target, source, env, for_signature):
53 cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
55 dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
56 if dll: cmd.extend(['-o', dll])
58 cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
60 implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
61 if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
63 def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
64 insert_def = env.subst("$WINDOWS_INSERT_DEF")
65 if not insert_def in ['', '0', 0] and def_target: \
66 cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
70 def shlib_emitter(target, source, env):
71 dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
72 no_import_lib = env.get('no_import_lib', 0)
75 raise SCons.Errors.UserError("A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX"))
77 if not no_import_lib and \
78 not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
80 # Append an import library to the list of targets.
81 target.append(env.ReplaceIxes(dll,
82 'SHLIBPREFIX', 'SHLIBSUFFIX',
83 'LIBPREFIX', 'LIBSUFFIX'))
85 # Append a def file target if there isn't already a def file target
86 # or a def file source. There is no option to disable def file
87 # target emitting, because I can't figure out why someone would ever
88 # want to turn it off.
89 def_source = env.FindIxes(source, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
90 def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
91 if not def_source and not def_target:
92 target.append(env.ReplaceIxes(dll,
93 'SHLIBPREFIX', 'SHLIBSUFFIX',
94 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX'))
96 return (target, source)
99 shlib_action = SCons.Action.Action(shlib_generator, generator=1)
101 res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
103 res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
104 source_scanner=SCons.Tool.SourceFileScanner)
105 SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
110 dir = os.path.dirname(mingw)
111 env.PrependENVPath('PATH', dir )
114 # Most of mingw is the same as gcc and friends...
115 gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4']
116 for tool in gnu_tools:
117 SCons.Tool.Tool(tool)(env)
119 #... but a few things differ:
121 env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
123 env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
124 env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
125 env['SHLINKCOM'] = shlib_action
126 env['LDMODULECOM'] = shlib_action
127 env.Append(SHLIBEMITTER = [shlib_emitter])
130 env['WIN32DEFPREFIX'] = ''
131 env['WIN32DEFSUFFIX'] = '.def'
132 env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
133 env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
135 env['SHOBJSUFFIX'] = '.o'
136 env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
138 env['RC'] = 'windres'
139 env['RCFLAGS'] = SCons.Util.CLVar('')
140 env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
141 env['RCINCPREFIX'] = '--include-dir '
142 env['RCINCSUFFIX'] = ''
143 env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
144 env['BUILDERS']['RES'] = res_builder
146 # Some setting from the platform also have to be overridden:
147 env['OBJSUFFIX'] = '.o'
148 env['LIBPREFIX'] = 'lib'
149 env['LIBSUFFIX'] = '.a'
156 # indent-tabs-mode:nil
158 # vim: set expandtab tabstop=4 shiftwidth=4: