2006-02-01 00:09:52 +01:00
|
|
|
"""SCons.Tool.gcc
|
|
|
|
|
|
|
|
Tool-specific initialization for MinGW (http://www.mingw.org/)
|
|
|
|
|
|
|
|
There normally shouldn't be any need to import this module directly.
|
|
|
|
It will usually be imported through the generic SCons.Tool.Tool()
|
|
|
|
selection method.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
#
|
2007-08-07 17:50:34 +02:00
|
|
|
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 The SCons Foundation
|
2006-02-01 00:09:52 +01:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included
|
|
|
|
# in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
|
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
#
|
|
|
|
|
2008-02-07 10:59:49 +01:00
|
|
|
__revision__ = "src/engine/SCons/Tool/mingw.py 2523 2007/12/12 09:37:41 knight"
|
2006-02-01 00:09:52 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import string
|
|
|
|
|
2007-08-07 17:50:34 +02:00
|
|
|
import SCons.Action
|
|
|
|
import SCons.Builder
|
|
|
|
import SCons.Defaults
|
2006-02-01 00:09:52 +01:00
|
|
|
import SCons.Tool
|
|
|
|
import SCons.Util
|
|
|
|
|
|
|
|
# This is what we search for to find mingw:
|
|
|
|
key_program = 'mingw32-gcc'
|
|
|
|
|
|
|
|
def find(env):
|
|
|
|
# First search in the SCons path and then the OS path:
|
|
|
|
return env.WhereIs(key_program) or SCons.Util.WhereIs(key_program)
|
|
|
|
|
|
|
|
def shlib_generator(target, source, env, for_signature):
|
|
|
|
cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
|
|
|
|
|
|
|
|
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
|
|
|
|
if dll: cmd.extend(['-o', dll])
|
|
|
|
|
|
|
|
cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
|
|
|
|
|
|
|
|
implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
|
|
|
|
if implib: cmd.append('-Wl,--out-implib,'+implib.get_string(for_signature))
|
|
|
|
|
2007-08-07 17:50:34 +02:00
|
|
|
def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
|
2006-02-01 00:09:52 +01:00
|
|
|
if def_target: cmd.append('-Wl,--output-def,'+def_target.get_string(for_signature))
|
|
|
|
|
|
|
|
return [cmd]
|
|
|
|
|
|
|
|
def shlib_emitter(target, source, env):
|
|
|
|
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
|
|
|
|
no_import_lib = env.get('no_import_lib', 0)
|
|
|
|
|
|
|
|
if not dll:
|
|
|
|
raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
|
|
|
|
|
|
|
|
if not no_import_lib and \
|
|
|
|
not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
|
|
|
|
|
|
|
|
# Append an import library to the list of targets.
|
|
|
|
target.append(env.ReplaceIxes(dll,
|
|
|
|
'SHLIBPREFIX', 'SHLIBSUFFIX',
|
|
|
|
'LIBPREFIX', 'LIBSUFFIX'))
|
|
|
|
|
|
|
|
# Append a def file target if there isn't already a def file target
|
|
|
|
# or a def file source. There is no option to disable def file
|
|
|
|
# target emitting, because I can't figure out why someone would ever
|
|
|
|
# want to turn it off.
|
2007-08-07 17:50:34 +02:00
|
|
|
def_source = env.FindIxes(source, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
|
|
|
|
def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
|
2006-02-01 00:09:52 +01:00
|
|
|
if not def_source and not def_target:
|
|
|
|
target.append(env.ReplaceIxes(dll,
|
|
|
|
'SHLIBPREFIX', 'SHLIBSUFFIX',
|
2007-08-07 17:50:34 +02:00
|
|
|
'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX'))
|
2006-02-01 00:09:52 +01:00
|
|
|
|
|
|
|
return (target, source)
|
|
|
|
|
|
|
|
|
2007-08-07 17:50:34 +02:00
|
|
|
shlib_action = SCons.Action.Action(shlib_generator, generator=1)
|
2006-02-01 00:09:52 +01:00
|
|
|
|
2007-08-07 17:50:34 +02:00
|
|
|
res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
|
|
|
|
|
|
|
|
res_builder = SCons.Builder.Builder(action=res_action, suffix='.o',
|
|
|
|
source_scanner=SCons.Tool.SourceFileScanner)
|
|
|
|
SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
|
2006-02-01 00:09:52 +01:00
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
mingw = find(env)
|
|
|
|
if mingw:
|
|
|
|
dir = os.path.dirname(mingw)
|
2008-02-07 10:59:49 +01:00
|
|
|
env.PrependENVPath('PATH', dir )
|
2006-02-01 00:09:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Most of mingw is the same as gcc and friends...
|
2007-08-07 17:50:34 +02:00
|
|
|
gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4']
|
2006-02-01 00:09:52 +01:00
|
|
|
for tool in gnu_tools:
|
|
|
|
SCons.Tool.Tool(tool)(env)
|
|
|
|
|
|
|
|
#... but a few things differ:
|
|
|
|
env['CC'] = 'gcc'
|
|
|
|
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
|
|
|
|
env['CXX'] = 'g++'
|
|
|
|
env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
|
|
|
|
env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
|
|
|
|
env['SHLINKCOM'] = shlib_action
|
|
|
|
env.Append(SHLIBEMITTER = [shlib_emitter])
|
|
|
|
env['AS'] = 'as'
|
2007-08-07 17:50:34 +02:00
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
env['WIN32DEFPREFIX'] = ''
|
|
|
|
env['WIN32DEFSUFFIX'] = '.def'
|
2007-08-07 17:50:34 +02:00
|
|
|
env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
|
|
|
|
env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
|
|
|
|
|
2006-02-01 00:09:52 +01:00
|
|
|
env['SHOBJSUFFIX'] = '.o'
|
|
|
|
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
|
|
|
|
|
|
|
|
env['RC'] = 'windres'
|
|
|
|
env['RCFLAGS'] = SCons.Util.CLVar('')
|
2007-08-07 17:50:34 +02:00
|
|
|
env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
|
2006-02-01 00:09:52 +01:00
|
|
|
env['RCINCPREFIX'] = '--include-dir '
|
|
|
|
env['RCINCSUFFIX'] = ''
|
2007-08-07 17:50:34 +02:00
|
|
|
env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
|
2006-02-01 00:09:52 +01:00
|
|
|
env['BUILDERS']['RES'] = res_builder
|
|
|
|
|
|
|
|
# Some setting from the platform also have to be overridden:
|
|
|
|
env['OBJSUFFIX'] = '.o'
|
|
|
|
env['LIBPREFIX'] = 'lib'
|
|
|
|
env['LIBSUFFIX'] = '.a'
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return find(env)
|