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()
12 # Copyright (c) 2001, 2002, 2003, 2004 The SCons Foundation
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__
= "/home/scons/scons/branch.0/branch.96/baseline/src/engine/SCons/Tool/mingw.py 0.96.90.D001 2005/02/15 20:11:37 knight"
45 # This is what we search for to find mingw:
46 prefixes
= SCons
.Util
.Split("""
53 for prefix
in prefixes
:
54 # First search in the SCons path and then the OS path:
55 if env
.WhereIs(prefix
+ 'gcc') or SCons
.Util
.WhereIs(prefix
+ 'gcc'):
60 def shlib_generator(target
, source
, env
, for_signature
):
61 cmd
= SCons
.Util
.CLVar(['$SHLINK', '$SHLINKFLAGS'])
63 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
64 if dll
: cmd
.extend(['-o', dll
])
66 cmd
.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
68 implib
= env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX')
69 if implib
: cmd
.append('-Wl,--out-implib,'+implib
.get_string(for_signature
))
71 def_target
= env
.FindIxes(target
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
72 if def_target
: cmd
.append('-Wl,--output-def,'+def_target
.get_string(for_signature
))
76 def shlib_emitter(target
, source
, env
):
77 dll
= env
.FindIxes(target
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
78 no_import_lib
= env
.get('no_import_lib', 0)
81 raise SCons
.Errors
.UserError
, "A shared library should have exactly one target with the suffix: %s" % env
.subst("$SHLIBSUFFIX")
83 if not no_import_lib
and \
84 not env
.FindIxes(target
, 'LIBPREFIX', 'LIBSUFFIX'):
86 # Append an import library to the list of targets.
87 target
.append(env
.ReplaceIxes(dll
,
88 'SHLIBPREFIX', 'SHLIBSUFFIX',
89 'LIBPREFIX', 'LIBSUFFIX'))
91 # Append a def file target if there isn't already a def file target
92 # or a def file source. There is no option to disable def file
93 # target emitting, because I can't figure out why someone would ever
94 # want to turn it off.
95 def_source
= env
.FindIxes(source
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
96 def_target
= env
.FindIxes(target
, 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX')
97 if not def_source
and not def_target
:
98 target
.append(env
.ReplaceIxes(dll
,
99 'SHLIBPREFIX', 'SHLIBSUFFIX',
100 'WIN32DEFPREFIX', 'WIN32DEFSUFFIX'))
102 return (target
, source
)
105 shlib_action
= SCons
.Action
.Action(shlib_generator
, generator
=1)
107 res_action
= SCons
.Action
.Action('$RCCOM', '$RCCOMSTR')
109 res_builder
= SCons
.Builder
.Builder(action
=res_action
, suffix
='.o',
110 source_scanner
=SCons
.Tool
.SourceFileScanner
)
111 SCons
.Tool
.SourceFileScanner
.add_scanner('.rc', SCons
.Defaults
.CScan
)
114 mingw_prefix
= find(env
)
117 dir = os
.path
.dirname(env
.WhereIs(mingw_prefix
+ 'gcc') or SCons
.Util
.WhereIs(mingw_prefix
+ 'gcc'))
119 # The mingw bin directory must be added to the path:
120 path
= env
['ENV'].get('PATH', [])
123 if SCons
.Util
.is_String(path
):
124 path
= string
.split(path
, os
.pathsep
)
126 env
['ENV']['PATH'] = string
.join([dir] + path
, os
.pathsep
)
128 # Most of mingw is the same as gcc and friends...
129 gnu_tools
= ['gcc', 'g++', 'gnulink', 'ar', 'gas']
130 for tool
in gnu_tools
:
131 SCons
.Tool
.Tool(tool
)(env
)
133 #... but a few things differ:
134 env
['CC'] = mingw_prefix
+ 'gcc'
135 env
['SHCCFLAGS'] = SCons
.Util
.CLVar('$CCFLAGS')
136 env
['CPP'] = mingw_prefix
+ 'g++'
137 env
['CXX'] = mingw_prefix
+ 'g++'
138 env
['SHCXXFLAGS'] = SCons
.Util
.CLVar('$CXXFLAGS')
139 env
['SHLINKFLAGS'] = SCons
.Util
.CLVar('$LINKFLAGS -shared')
140 env
['SHLINKCOM'] = shlib_action
141 env
.Append(SHLIBEMITTER
= [shlib_emitter
])
142 env
['LINK_CC'] = mingw_prefix
+ 'gcc'
143 env
['LINK_CXX'] = mingw_prefix
+ 'g++'
144 env
['AS'] = mingw_prefix
+ 'as'
145 env
['AR'] = mingw_prefix
+ 'ar'
146 env
['RANLIB'] = mingw_prefix
+ 'ranlib'
147 env
['WIN32DEFPREFIX'] = ''
148 env
['WIN32DEFSUFFIX'] = '.def'
149 env
['SHOBJSUFFIX'] = '.o'
150 env
['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
152 env
['RC'] = mingw_prefix
+ 'windres'
153 env
['RCFLAGS'] = SCons
.Util
.CLVar('')
154 env
['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS ${INCPREFIX}${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
155 env
['BUILDERS']['RES'] = res_builder
157 # Some setting from the platform also have to be overridden:
158 env
['OBJPREFIX'] = ''
159 env
['OBJSUFFIX'] = '.o'
160 env
['SHOBJPREFIX'] = '$OBJPREFIX'
161 env
['SHOBJSUFFIX'] = '$OBJSUFFIX'
162 env
['PROGPREFIX'] = ''
163 env
['PROGSUFFIX'] = '.exe'
164 env
['LIBPREFIX'] = ''
165 env
['LIBSUFFIX'] = '.lib'
166 env
['SHLIBPREFIX'] = ''
167 env
['SHLIBSUFFIX'] = '.dll'
168 env
['LIBPREFIXES'] = [ '$LIBPREFIX' ]
169 env
['LIBSUFFIXES'] = [ '$LIBSUFFIX' ]