mapnik/scons/scons-local-4.1.0/SCons/Tool/mingw.py

216 lines
7.6 KiB
Python
Raw Normal View History

2021-03-05 11:18:26 +01:00
# MIT License
2015-10-01 15:25:41 +02:00
#
2021-03-05 11:18:26 +01:00
# Copyright The SCons Foundation
2015-10-01 15:25:41 +02: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.
2021-03-05 11:18:26 +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.
"""
2015-10-01 15:25:41 +02:00
import os
import os.path
2021-03-05 11:18:26 +01:00
import glob
2015-10-01 15:25:41 +02:00
import SCons.Action
import SCons.Builder
import SCons.Defaults
import SCons.Tool
import SCons.Util
2021-03-05 11:18:26 +01:00
mingw_paths = [
r'c:\MinGW\bin',
r'C:\cygwin64\bin',
r'C:\msys64',
r'C:\msys64\mingw64\bin',
r'C:\cygwin\bin',
r'C:\msys',
r'C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin'
]
2015-10-01 15:25:41 +02:00
def shlib_generator(target, source, env, for_signature):
2021-03-05 11:18:26 +01:00
cmd = SCons.Util.CLVar(['$SHLINK', '$SHLINKFLAGS'])
2015-10-01 15:25:41 +02:00
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
if dll: cmd.extend(['-o', dll])
cmd.extend(['$SOURCES', '$_LIBDIRFLAGS', '$_LIBFLAGS'])
implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
2021-03-05 11:18:26 +01:00
if implib: cmd.append('-Wl,--out-implib,' + implib.get_string(for_signature))
2015-10-01 15:25:41 +02:00
def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
insert_def = env.subst("$WINDOWS_INSERT_DEF")
2021-03-05 11:18:26 +01:00
if insert_def not in ['', '0', 0] and def_target: \
cmd.append('-Wl,--output-def,' + def_target.get_string(for_signature))
2015-10-01 15:25:41 +02:00
return [cmd]
2021-03-05 11:18:26 +01:00
2015-10-01 15:25:41 +02:00
def shlib_emitter(target, source, env):
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
no_import_lib = env.get('no_import_lib', 0)
if not dll:
2021-03-05 11:18:26 +01:00
raise SCons.Errors.UserError(
"A shared library should have exactly one target with the suffix: %s Target(s) are:%s" % \
2017-11-16 11:59:55 +01:00
(env.subst("$SHLIBSUFFIX"), ",".join([str(t) for t in target])))
2015-10-01 15:25:41 +02:00
2021-03-05 11:18:26 +01:00
if not no_import_lib and \
not env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX'):
2015-10-01 15:25:41 +02:00
# Create list of target libraries as strings
2021-03-05 11:18:26 +01:00
targetStrings = env.ReplaceIxes(dll,
'SHLIBPREFIX', 'SHLIBSUFFIX',
'LIBPREFIX', 'LIBSUFFIX')
2015-10-01 15:25:41 +02:00
# Now add file nodes to target list
target.append(env.fs.File(targetStrings))
# Append a def file target if there isn't already a def file target
# or a def file source or the user has explicitly asked for the target
# to be emitted.
def_source = env.FindIxes(source, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
def_target = env.FindIxes(target, 'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
skip_def_insert = env.subst("$WINDOWS_INSERT_DEF") in ['', '0', 0]
if not def_source and not def_target and not skip_def_insert:
# Create list of target libraries and def files as strings
2021-03-05 11:18:26 +01:00
targetStrings = env.ReplaceIxes(dll,
'SHLIBPREFIX', 'SHLIBSUFFIX',
'WINDOWSDEFPREFIX', 'WINDOWSDEFSUFFIX')
2015-10-01 15:25:41 +02:00
# Now add file nodes to target list
target.append(env.fs.File(targetStrings))
return (target, source)
2021-03-05 11:18:26 +01:00
shlib_action = SCons.Action.Action(shlib_generator, '$SHLINKCOMSTR', generator=1)
ldmodule_action = SCons.Action.Action(shlib_generator, '$LDMODULECOMSTR', generator=1)
2015-10-01 15:25:41 +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)
2021-03-05 11:18:26 +01:00
# This is what we search for to find mingw:
# key_program = 'mingw32-gcc'
key_program = 'mingw32-make'
def find_version_specific_mingw_paths():
r"""
One example of default mingw install paths is:
C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64\bin
Use glob'ing to find such and add to mingw_paths
"""
new_paths = glob.glob(r"C:\mingw-w64\*\mingw64\bin")
return new_paths
2015-10-01 15:25:41 +02:00
def generate(env):
2021-03-05 11:18:26 +01:00
global mingw_paths
# Check for reasoanble mingw default paths
mingw_paths += find_version_specific_mingw_paths()
mingw = SCons.Tool.find_program_path(env, key_program, default_paths=mingw_paths)
2015-10-01 15:25:41 +02:00
if mingw:
2021-03-05 11:18:26 +01:00
mingw_bin_dir = os.path.dirname(mingw)
# Adjust path if we found it in a chocolatey install
if mingw_bin_dir == r'C:\ProgramData\chocolatey\bin':
mingw_bin_dir = r'C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin'
env.AppendENVPath('PATH', mingw_bin_dir)
2015-10-01 15:25:41 +02:00
# Most of mingw is the same as gcc and friends...
gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'gfortran', 'm4']
for tool in gnu_tools:
SCons.Tool.Tool(tool)(env)
2021-03-05 11:18:26 +01:00
# ... but a few things differ:
2015-10-01 15:25:41 +02:00
env['CC'] = 'gcc'
2021-03-05 11:18:26 +01:00
# make sure the msvc tool doesnt break us, it added a /flag
if 'CCFLAGS' in env:
# make sure its a CLVar to handle list or str cases
if type(env['CCFLAGS']) is not SCons.Util.CLVar:
env['CCFLAGS'] = SCons.Util.CLVar(env['CCFLAGS'])
env['CCFLAGS'] = SCons.Util.CLVar(str(env['CCFLAGS']).replace('/nologo', ''))
2015-10-01 15:25:41 +02:00
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
env['CXX'] = 'g++'
env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS -shared')
2021-03-05 11:18:26 +01:00
env['SHLINKCOM'] = shlib_action
env['SHLINKCOMSTR'] = shlib_generator
env['LDMODULECOM'] = ldmodule_action
env.Append(SHLIBEMITTER=[shlib_emitter])
env.Append(LDMODULEEMITTER=[shlib_emitter])
2015-10-01 15:25:41 +02:00
env['AS'] = 'as'
2021-03-05 11:18:26 +01:00
env['WIN32DEFPREFIX'] = ''
env['WIN32DEFSUFFIX'] = '.def'
env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
2015-10-01 15:25:41 +02:00
env['SHOBJSUFFIX'] = '.o'
env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
env['RC'] = 'windres'
env['RCFLAGS'] = SCons.Util.CLVar('')
env['RCINCFLAGS'] = '$( ${_concat(RCINCPREFIX, CPPPATH, RCINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
env['RCINCPREFIX'] = '--include-dir '
env['RCINCSUFFIX'] = ''
env['RCCOM'] = '$RC $_CPPDEFFLAGS $RCINCFLAGS ${RCINCPREFIX} ${SOURCE.dir} $RCFLAGS -i $SOURCE -o $TARGET'
env['BUILDERS']['RES'] = res_builder
2021-03-05 11:18:26 +01:00
2015-10-01 15:25:41 +02:00
# Some setting from the platform also have to be overridden:
env['OBJSUFFIX'] = '.o'
env['LIBPREFIX'] = 'lib'
env['LIBSUFFIX'] = '.a'
env['PROGSUFFIX'] = '.exe'
2021-03-05 11:18:26 +01:00
# Handle new versioned shared library logic
env['_SHLIBSUFFIX'] = '$SHLIBSUFFIX'
env["SHLIBPREFIX"] = ""
2015-10-01 15:25:41 +02:00
def exists(env):
2021-03-05 11:18:26 +01:00
mingw = SCons.Tool.find_program_path(env, key_program, default_paths=mingw_paths)
if mingw:
mingw_bin_dir = os.path.dirname(mingw)
env.AppendENVPath('PATH', mingw_bin_dir)
return mingw
2015-10-01 15:25:41 +02:00
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4: