From ae31d2eb3c83b5e50659da2c7a92aaca49a691e2 Mon Sep 17 00:00:00 2001 From: garyo Date: Tue, 6 Jan 2009 23:04:47 +0000 Subject: [PATCH] Fix issue 2274 (LDMODULE* ignored except on Mac): integrated patch from Arve Knudsen. git-svn-id: http://scons.tigris.org/svn/scons/trunk@3875 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 3 ++ src/engine/SCons/Tool/__init__.py | 2 +- src/engine/SCons/Tool/link.py | 5 ++- src/engine/SCons/Tool/mslink.py | 68 ++++++++++++++++++++++--------- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index c525a843..e793527b 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -23,6 +23,9 @@ RELEASE 1.X - XXX From Arve Knudsen: + - Make linker tools differentiate properly between SharedLibrary + and LoadableModule. + - Document TestCommon.shobj_prefix variable. From Gary Oberbrunner: diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 8fa97cdc..7309a356 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -272,7 +272,7 @@ def createLoadableModuleBuilder(env): action_list = [ SCons.Defaults.SharedCheck, SCons.Defaults.LdModuleLinkAction ] ld_module = SCons.Builder.Builder(action = action_list, - emitter = "$SHLIBEMITTER", + emitter = "$LDMODULEEMITTER", prefix = '$LDMODULEPREFIX', suffix = '$LDMODULESUFFIX', target_scanner = ProgramScanner, diff --git a/src/engine/SCons/Tool/link.py b/src/engine/SCons/Tool/link.py index 4522ba17..b11be764 100644 --- a/src/engine/SCons/Tool/link.py +++ b/src/engine/SCons/Tool/link.py @@ -99,10 +99,13 @@ def generate(env): # setting them the same means that LoadableModule works everywhere. SCons.Tool.createLoadableModuleBuilder(env) env['LDMODULE'] = '$SHLINK' + # don't set up the emitter, cause AppendUnique will generate a list + # starting with None :-( + env.Append(LDMODULEEMITTER='$SHLIBEMITTER') env['LDMODULEPREFIX'] = '$SHLIBPREFIX' env['LDMODULESUFFIX'] = '$SHLIBSUFFIX' env['LDMODULEFLAGS'] = '$SHLINKFLAGS' - env['LDMODULECOM'] = '$SHLINKCOM' + env['LDMODULECOM'] = '$LDMODULE -o $TARGET $LDMODULEFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS' diff --git a/src/engine/SCons/Tool/mslink.py b/src/engine/SCons/Tool/mslink.py index 42eabafb..4268b58f 100644 --- a/src/engine/SCons/Tool/mslink.py +++ b/src/engine/SCons/Tool/mslink.py @@ -50,9 +50,9 @@ def pdbGenerator(env, target, source, for_signature): except (AttributeError, IndexError): return None -def windowsShlinkTargets(target, source, env, for_signature): +def _dllTargets(target, source, env, for_signature, paramtp): listCmd = [] - dll = env.FindIxes(target, 'SHLIBPREFIX', 'SHLIBSUFFIX') + dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp) if dll: listCmd.append("/out:%s"%dll.get_string(for_signature)) implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX') @@ -60,7 +60,7 @@ def windowsShlinkTargets(target, source, env, for_signature): return listCmd -def windowsShlinkSources(target, source, env, for_signature): +def _dllSources(target, source, env, for_signature, paramtp): listCmd = [] deffile = env.FindIxes(source, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX") @@ -73,17 +73,32 @@ def windowsShlinkSources(target, source, env, for_signature): listCmd.append(src) return listCmd -def windowsLibEmitter(target, source, env): +def windowsShlinkTargets(target, source, env, for_signature): + return _dllTargets(target, source, env, for_signature, 'SHLIB') + +def windowsShlinkSources(target, source, env, for_signature): + return _dllSources(target, source, env, for_signature, 'SHLIB') + +def _windowsLdmodTargets(target, source, env, for_signature): + """Get targets for loadable modules.""" + return _dllTargets(target, source, env, for_signature, 'LDMODULE') + +def _windowsLdmodSources(target, source, env, for_signature): + """Get sources for loadable modules.""" + return _dllSources(target, source, env, for_signature, 'LDMODULE') + +def _dllEmitter(target, source, env, paramtp): + """Common implementation of dll emitter.""" SCons.Tool.msvc.validate_vars(env) extratargets = [] extrasources = [] - dll = env.FindIxes(target, "SHLIBPREFIX", "SHLIBSUFFIX") + dll = env.FindIxes(target, '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp) 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") + raise SCons.Errors.UserError, 'A shared library should have exactly one target with the suffix: %s' % env.subst('$%sSUFFIX' % paramtp) insert_def = env.subst("$WINDOWS_INSERT_DEF") if not insert_def in ['', '0', 0] and \ @@ -92,7 +107,7 @@ def windowsLibEmitter(target, source, env): # append a def file to the list of sources extrasources.append( env.ReplaceIxes(dll, - "SHLIBPREFIX", "SHLIBSUFFIX", + '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSDEFPREFIX", "WINDOWSDEFSUFFIX")) version_num, suite = SCons.Tool.msvs.msvs_parse_version(env.get('MSVS_VERSION', '6.0')) @@ -100,7 +115,7 @@ def windowsLibEmitter(target, source, env): # MSVC 8 automatically generates .manifest files that must be installed extratargets.append( env.ReplaceIxes(dll, - "SHLIBPREFIX", "SHLIBSUFFIX", + '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTSUFFIX")) if env.has_key('PDB') and env['PDB']: @@ -113,16 +128,27 @@ def windowsLibEmitter(target, source, env): # Append an import library to the list of targets. extratargets.append( env.ReplaceIxes(dll, - "SHLIBPREFIX", "SHLIBSUFFIX", + '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "LIBPREFIX", "LIBSUFFIX")) # and .exp file is created if there are exports from a DLL extratargets.append( env.ReplaceIxes(dll, - "SHLIBPREFIX", "SHLIBSUFFIX", + '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSEXPPREFIX", "WINDOWSEXPSUFFIX")) return (target+extratargets, source+extrasources) +def windowsLibEmitter(target, source, env): + return _dllEmitter(target, source, env, 'SHLIB') + +def ldmodEmitter(target, source, env): + """Emitter for loadable modules. + + Loadable modules are identical to shared libraries on Windows, but building + them is subject to different parameters (LDMODULE*). + """ + return _dllEmitter(target, source, env, 'LDMODULE') + def prog_emitter(target, source, env): SCons.Tool.msvc.validate_vars(env) @@ -160,7 +186,9 @@ def RegServerFunc(target, source, env): regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR") regServerCheck = SCons.Action.Action(RegServerFunc, None) shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $_SHLINK_SOURCES")}') -compositeLinkAction = shlibLinkAction + regServerCheck +compositeShLinkAction = shlibLinkAction + regServerCheck +ldmodLinkAction = SCons.Action.Action('${TEMPFILE("$LDMODULE $LDMODULEFLAGS $_LDMODULE_TARGETS $( $_LIBDIRFLAGS $) $_LIBFLAGS $_PDB $_LDMODULE_SOURCES")}') +compositeLdmodAction = ldmodLinkAction + regServerCheck def generate(env): """Add Builders and construction variables for ar to an Environment.""" @@ -171,7 +199,7 @@ def generate(env): env['SHLINKFLAGS'] = SCons.Util.CLVar('$LINKFLAGS /dll') env['_SHLINK_TARGETS'] = windowsShlinkTargets env['_SHLINK_SOURCES'] = windowsShlinkSources - env['SHLINKCOM'] = compositeLinkAction + env['SHLINKCOM'] = compositeShLinkAction env.Append(SHLIBEMITTER = [windowsLibEmitter]) env['LINK'] = 'link' env['LINKFLAGS'] = SCons.Util.CLVar('/nologo') @@ -221,19 +249,19 @@ def generate(env): except (SCons.Util.RegError, SCons.Errors.InternalError): pass - # 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. + # Loadable modules are on Windows the same as shared libraries, but they + # are subject to different build parameters (LDMODULE* variables). + # Therefore LDMODULE* variables correspond as much as possible to + # SHLINK*/SHLIB* ones. 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 + env['_LDMODULE_TARGETS'] = _windowsLdmodTargets + env['_LDMODULE_SOURCES'] = _windowsLdmodSources + env['LDMODULEEMITTER'] = [ldmodEmitter] + env['LDMODULECOM'] = compositeLdmodAction def exists(env): platform = env.get('PLATFORM', '') -- 2.26.2