Add a cyglink Tool to handle linking of shared libraries under From: David Rothenberger Cygwin. The tool handles creating the DLL import library as well as replacing the initial "lib" with "cyg". --- MANIFEST | 1 engine/SCons/Tool/__init__.py | 8 +++ engine/SCons/Tool/cyglink.py | 96 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 engine/SCons/Tool/cyglink.py diff --git a/MANIFEST b/MANIFEST index e652610..8ed840c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -83,6 +83,7 @@ engine/SCons/Tool/as.py engine/SCons/Tool/bcc32.py engine/SCons/Tool/c++.py engine/SCons/Tool/cc.py +engine/SCons/Tool/cyglink.py engine/SCons/Tool/cvf.py engine/SCons/Tool/default.py engine/SCons/Tool/dmd.py diff --git a/engine/SCons/Tool/__init__.py b/engine/SCons/Tool/__init__.py index b12095f..a15526e 100644 --- a/engine/SCons/Tool/__init__.py +++ b/engine/SCons/Tool/__init__.py @@ -733,6 +733,14 @@ def tool_list(platform, env): assemblers = ['as'] fortran_compilers = ['gfortran', 'f95', 'f90', 'g77'] ars = ['ar'] + elif str(platform) == 'cygwin': + "prefer GNU tools on Cygwin, except for a platform-specific linker" + linkers = ['cyglink', 'mslink', 'ilink'] + c_compilers = ['gcc', 'msvc', 'intelc', 'icc', 'cc'] + cxx_compilers = ['g++', 'msvc', 'intelc', 'icc', 'c++'] + assemblers = ['gas', 'nasm', 'masm'] + fortran_compilers = ['gfortran', 'g77', 'ifort', 'ifl', 'f95', 'f90', 'f77'] + ars = ['ar', 'mslib'] else: "prefer GNU tools on all other platforms" linkers = ['gnulink', 'mslink', 'ilink'] diff --git a/engine/SCons/Tool/cyglink.py b/engine/SCons/Tool/cyglink.py new file mode 100644 index 0000000..768c1ac --- /dev/null +++ b/engine/SCons/Tool/cyglink.py @@ -0,0 +1,96 @@ +"""SCons.Tool.cyglink + +Customization of gnulink for Cygwin (http://www.cygwin.com/) + +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. + +""" + +import SCons.Action +import SCons.Util + +import gnulink + +def shlib_generator(target, source, env, for_signature): + cmd = SCons.Util.CLVar(['$SHLINK']) + + dll = env.FindIxes(target, 'CYGDLLPREFIX', 'CYGDLLSUFFIX') + if dll: cmd.extend(['-o', dll]) + + cmd.extend(['$SHLINKFLAGS', '$__RPATH']) + + implib = env.FindIxes(target, 'IMPLIBPREFIX', 'IMPLIBSUFFIX') + if implib: + cmd.extend([ + '-Wl,--out-implib='+implib.get_string(for_signature), + '-Wl,--export-all-symbols', + '-Wl,--enable-auto-import', + '-Wl,--whole-archive', '$SOURCES', + '-Wl,--no-whole-archive', '$_LIBDIRFLAGS', '$_LIBFLAGS' + ]) + + 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")) + + # Remove any "lib" after the prefix + pre = env.subst('$SHLIBPREFIX') + dllName = str(dll) + if dllName[len(pre):len(pre)+3] == 'lib': + dllName = dllName[len(pre)+3:] + dll = env.fs.File(dllName) + + dll = env.ReplaceIxes(dll, + 'SHLIBPREFIX', 'SHLIBSUFFIX', + 'CYGDLLPREFIX', 'CYGDLLSUFFIX') + + origTarget = target + target = [env.fs.File(dll)] + + # Append an import lib target + if not no_import_lib and \ + not env.FindIxes(origTarget, 'IMPLIBPREFIX', 'IMPLIBSUFFIX'): + + # Create list of target libraries as strings + targetStrings = env.ReplaceIxes(origTarget[0], + 'SHLIBPREFIX', 'SHLIBSUFFIX', + 'IMPLIBPREFIX', 'IMPLIBSUFFIX') + + # Now add file nodes to target list + target.append(env.fs.File(targetStrings)) + + return (target, source) + + +shlib_action = SCons.Action.Action(shlib_generator, generator=1) + +def generate(env): + """Add Builders and construction variables for cyglink to an Environment.""" + gnulink.generate(env) + + env['SHLINKCOM'] = shlib_action + env['LDMODULECOM'] = shlib_action + env.Append(SHLIBEMITTER = [shlib_emitter]) + + env['CYGDLLPREFIX'] = 'cyg' + env['CYGDLLSUFFIX'] = '.dll' + + env['IMPLIBPREFIX'] = '' + env['IMPLIBSUFFIX'] = '.dll.a' + +def exists(env): + return gnulink.exists(env) + + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: