mapnik/scons/scons-local-0.97.0d20071212/SCons/Tool/mslink.py

240 lines
9.8 KiB
Python
Raw Normal View History

2006-02-01 00:09:52 +01:00
"""SCons.Tool.mslink
Tool-specific initialization for the Microsoft linker.
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/mslink.py 2523 2007/12/12 09:37:41 knight"
2006-02-01 00:09:52 +01:00
import os.path
import SCons.Action
import SCons.Defaults
import SCons.Errors
import SCons.Platform.win32
import SCons.Tool
import SCons.Tool.msvc
import SCons.Tool.msvs
import SCons.Util
def pdbGenerator(env, target, source, for_signature):
2008-02-07 10:59:49 +01:00
try:
return ['/PDB:%s' % target[0].attributes.pdb, '/DEBUG']
except (AttributeError, IndexError):
return None
2006-02-01 00:09:52 +01:00
2007-08-07 17:50:34 +02:00
def windowsShlinkTargets(target, source, env, for_signature):
2006-02-01 00:09:52 +01:00
listCmd = []
dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX')
if dll: listCmd.append("/out:%s"%dll.get_string(for_signature))
implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
if implib: listCmd.append("/implib:%s"%implib.get_string(for_signature))
return listCmd
2007-08-07 17:50:34 +02:00
def windowsShlinkSources(target, source, env, for_signature):
2006-02-01 00:09:52 +01:00
listCmd = []
2007-08-07 17:50:34 +02:00
deffile = env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")
2006-02-01 00:09:52 +01:00
for src in source:
if src == deffile:
# Treat this source as a .def file.
listCmd.append("/def:%s" % src.get_string(for_signature))
else:
# Just treat it as a generic source file.
listCmd.append(src)
return listCmd
2007-08-07 17:50:34 +02:00
def windowsLibEmitter(target, source, env):
2006-02-01 00:09:52 +01:00
SCons.Tool.msvc.validate_vars(env)
2007-08-07 17:50:34 +02:00
2006-02-01 00:09:52 +01:00
dll = env.FindIxes(target, "SHLIBPREFIX", "SHLIBSUFFIX")
no_import_lib = env.get('no_import_lib', 0)
2007-08-07 17:50:34 +02:00
2006-02-01 00:09:52 +01:00
if not dll:
raise SCons.Errors.UserError, "A shared library should have exactly one target with the suffix: %s" % env.subst("$SHLIBSUFFIX")
2007-08-07 17:50:34 +02:00
insert_def = env.subst("$WINDOWS_INSERT_DEF")
if not insert_def in ['', '0', 0] and \
not env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"):
2006-02-01 00:09:52 +01:00
# append a def file to the list of sources
2007-08-07 17:50:34 +02:00
source.append(env.ReplaceIxes(dll,
2006-02-01 00:09:52 +01:00
"SHLIBPREFIX", "SHLIBSUFFIX",
2007-08-07 17:50:34 +02:00
"WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX"))
version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0'))
if version_num >= 8.0 and env.get('WINDOWS_INSERT_MANIFEST', 0):
# MSVC 8 automatically generates .manifest files that must be installed
target.append(env.ReplaceIxes(dll,
"SHLIBPREFIX", "SHLIBSUFFIX",
"WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTSUFFIX"))
2006-02-01 00:09:52 +01:00
if env.has_key('PDB') and env['PDB']:
2008-02-07 10:59:49 +01:00
pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
target.append(pdb)
target[0].attributes.pdb = pdb
2006-02-01 00:09:52 +01:00
if not no_import_lib and \
not env.FindIxes(target, "LIBPREFIX", "LIBSUFFIX"):
# Append an import library to the list of targets.
2007-08-07 17:50:34 +02:00
target.append(env.ReplaceIxes(dll,
2006-02-01 00:09:52 +01:00
"SHLIBPREFIX", "SHLIBSUFFIX",
"LIBPREFIX", "LIBSUFFIX"))
# and .exp file is created if there are exports from a DLL
2007-08-07 17:50:34 +02:00
target.append(env.ReplaceIxes(dll,
2006-02-01 00:09:52 +01:00
"SHLIBPREFIX", "SHLIBSUFFIX",
2007-08-07 17:50:34 +02:00
"WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX"))
2006-02-01 00:09:52 +01:00
return (target, source)
def prog_emitter(target, source, env):
SCons.Tool.msvc.validate_vars(env)
2007-08-07 17:50:34 +02:00
exe = env.FindIxes(target, "PROGPREFIX", "PROGSUFFIX")
if not exe:
raise SCons.Errors.UserError, "An executable should have exactly one target with the suffix: %s" % env.subst("$PROGSUFFIX")
version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0'))
if version_num >= 8.0 and env.get('WINDOWS_INSERT_MANIFEST', 0):
# MSVC 8 automatically generates .manifest files that have to be installed
target.append(env.ReplaceIxes(exe,
"PROGPREFIX", "PROGSUFFIX",
"WINDOWSPROGMANIFESTPREFIX", "WINDOWSPROGMANIFESTSUFFIX"))
2006-02-01 00:09:52 +01:00
if env.has_key('PDB') and env['PDB']:
2008-02-07 10:59:49 +01:00
pdb = env.arg2nodes('$PDB', target=target, source=source)[0]
target.append(pdb)
target[0].attributes.pdb = pdb
2007-08-07 17:50:34 +02:00
2006-02-01 00:09:52 +01:00
return (target,source)
def RegServerFunc(target, source, env):
if env.has_key('register') and env['register']:
ret = regServerAction([target[0]], [source[0]], env)
if ret:
raise SCons.Errors.UserError, "Unable to register %s" % target[0]
else:
print "Registered %s sucessfully" % target[0]
return ret
return 0
2007-08-07 17:50:34 +02:00
regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
2006-02-01 00:09:52 +01:00
regServerCheck = SCons.Action.Action(RegServerFunc, None)
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}')
compositeLinkAction = shlibLinkAction + regServerCheck
def generate(env):
"""Add Builders and construction variables for ar to an Environment."""
SCons.Tool.createSharedLibBuilder(env)
SCons.Tool.createProgBuilder(env)
2007-08-07 17:50:34 +02:00
2006-02-01 00:09:52 +01:00
env['SHLINK'] = '$LINK'
env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll')
2007-08-07 17:50:34 +02:00
env['_SHLINK_TARGETS'] = windowsShlinkTargets
env['_SHLINK_SOURCES'] = windowsShlinkSources
2006-02-01 00:09:52 +01:00
env['SHLINKCOM'] = compositeLinkAction
2007-08-07 17:50:34 +02:00
env.Append(SHLIBEMITTER = [windowsLibEmitter])
2006-02-01 00:09:52 +01:00
env['LINK'] = 'link'
env['LINKFLAGS'] = SCons.Util.CLVar('/nologo')
env['_PDB'] = pdbGenerator
2007-08-07 17:50:34 +02:00
env['LINKCOM'] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $SOURCES.windows")}'
2006-02-01 00:09:52 +01:00
env.Append(PROGEMITTER = [prog_emitter])
env['LIBDIRPREFIX']='/LIBPATH:'
env['LIBDIRSUFFIX']=''
env['LIBLINKPREFIX']=''
env['LIBLINKSUFFIX']='$LIBSUFFIX'
env['WIN32DEFPREFIX'] = ''
env['WIN32DEFSUFFIX'] = '.def'
env['WIN32_INSERT_DEF'] = 0
2007-08-07 17:50:34 +02:00
env['WINDOWSDEFPREFIX'] = '${WIN32DEFPREFIX}'
env['WINDOWSDEFSUFFIX'] = '${WIN32DEFSUFFIX}'
env['WINDOWS_INSERT_DEF'] = '${WIN32_INSERT_DEF}'
2006-02-01 00:09:52 +01:00
env['WIN32EXPPREFIX'] = ''
env['WIN32EXPSUFFIX'] = '.exp'
2007-08-07 17:50:34 +02:00
env['WINDOWSEXPPREFIX'] = '${WIN32EXPPREFIX}'
env['WINDOWSEXPSUFFIX'] = '${WIN32EXPSUFFIX}'
env['WINDOWSSHLIBMANIFESTPREFIX'] = ''
2008-02-07 10:59:49 +01:00
env['WINDOWSSHLIBMANIFESTSUFFIX'] = '${SHLIBSUFFIX}.manifest'
2007-08-07 17:50:34 +02:00
env['WINDOWSPROGMANIFESTPREFIX'] = ''
2008-02-07 10:59:49 +01:00
env['WINDOWSPROGMANIFESTSUFFIX'] = '${PROGSUFFIX}.manifest'
2006-02-01 00:09:52 +01:00
env['REGSVRACTION'] = regServerCheck
env['REGSVR'] = os.path.join(SCons.Platform.win32.get_system_root(),'System32','regsvr32')
env['REGSVRFLAGS'] = '/s '
2007-08-07 17:50:34 +02:00
env['REGSVRCOM'] = '$REGSVR $REGSVRFLAGS ${TARGET.windows}'
2006-02-01 00:09:52 +01:00
try:
version = SCons.Tool.msvs.get_default_visualstudio_version(env)
if env.has_key('MSVS_IGNORE_IDE_PATHS') and env['MSVS_IGNORE_IDE_PATHS']:
2007-08-07 17:50:34 +02:00
include_path, lib_path, exe_path = SCons.Tool.msvc.get_msvc_default_paths(env,version)
2006-02-01 00:09:52 +01:00
else:
2007-08-07 17:50:34 +02:00
include_path, lib_path, exe_path = SCons.Tool.msvc.get_msvc_paths(env,version)
2006-02-01 00:09:52 +01:00
# since other tools can set these, we just make sure that the
# relevant stuff from MSVS is in there somewhere.
env.PrependENVPath('INCLUDE', include_path)
env.PrependENVPath('LIB', lib_path)
env.PrependENVPath('PATH', exe_path)
except (SCons.Util.RegError, SCons.Errors.InternalError):
pass
2007-08-07 17:50:34 +02:00
# For most platforms, a loadable module is the same as a shared
# library. Platforms which are different can override these, but
# setting them the same means that LoadableModule works everywhere.
SCons.Tool.createLoadableModuleBuilder(env)
env['LDMODULE'] = '$SHLINK'
env['LDMODULEPREFIX'] = '$SHLIBPREFIX'
env['LDMODULESUFFIX'] = '$SHLIBSUFFIX'
env['LDMODULEFLAGS'] = '$SHLINKFLAGS'
# We can't use '$SHLINKCOM' here because that will stringify the
# action list on expansion, and will then try to execute expanded
# strings, with the upshot that it would try to execute RegServerFunc
# as a command.
env['LDMODULECOM'] = compositeLinkAction
2006-02-01 00:09:52 +01:00
def exists(env):
2007-08-07 17:50:34 +02:00
platform = env.get('PLATFORM', '')
2006-02-01 00:09:52 +01:00
if SCons.Tool.msvs.is_msvs_installed():
# there's at least one version of MSVS installed.
return 1
2007-08-07 17:50:34 +02:00
elif platform in ('win32', 'cygwin'):
# Only explicitly search for a 'link' executable on Windows
# systems. Some other systems (e.g. Ubuntu Linux) have an
# executable named 'link' and we don't want that to make SCons
# think Visual Studio is installed.
2006-02-01 00:09:52 +01:00
return env.Detect('link')
2007-08-07 17:50:34 +02:00
return None