summaryrefslogtreecommitdiff
path: root/engine/SCons/Tool/cyglink.py
diff options
context:
space:
mode:
authorLuca Falavigna <dktrkranz@debian.org>2014-04-26 11:52:25 +0200
committerLuca Falavigna <dktrkranz@debian.org>2014-04-26 11:52:25 +0200
commitc58ef47cac0ffa49ecabdb228991a89fcdb4f8ef (patch)
tree677bf40bab72549a4c2dd882328a9896d1a08a87 /engine/SCons/Tool/cyglink.py
parentd4746a568b9d1464742de0788d39b08309e28cb0 (diff)
parent599d55e3999ad29f72fdc3a61d7c4bafc3171452 (diff)
Merge tag 'upstream/2.3.1'
Upstream version 2.3.1
Diffstat (limited to 'engine/SCons/Tool/cyglink.py')
-rw-r--r--engine/SCons/Tool/cyglink.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/engine/SCons/Tool/cyglink.py b/engine/SCons/Tool/cyglink.py
new file mode 100644
index 0000000..87716cf
--- /dev/null
+++ b/engine/SCons/Tool/cyglink.py
@@ -0,0 +1,94 @@
+"""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, 'SHLIBPREFIX', 'SHLIBSUFFIX')
+ 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'
+ ])
+ else:
+ cmd.extend(['$SOURCES', '$_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 or len(target) > 1:
+ 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')
+ if dll.name[len(pre):len(pre)+3] == 'lib':
+ dll.name = pre + dll.name[len(pre)+3:]
+
+ orig_target = target
+ target = [env.fs.File(dll)]
+ target[0].attributes.shared = 1
+
+ # Append an import lib target
+ if not no_import_lib:
+ # Create list of target libraries as strings
+ target_strings = env.ReplaceIxes(orig_target[0],
+ 'SHLIBPREFIX', 'SHLIBSUFFIX',
+ 'IMPLIBPREFIX', 'IMPLIBSUFFIX')
+
+ implib_target = env.fs.File(target_strings)
+ implib_target.attributes.shared = 1
+ target.append(implib_target)
+
+ 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['LINKFLAGS'] = SCons.Util.CLVar('-Wl,-no-undefined')
+
+ env['SHLINKCOM'] = shlib_action
+ env['LDMODULECOM'] = shlib_action
+ env.Append(SHLIBEMITTER = [shlib_emitter])
+
+ env['SHLIBPREFIX'] = 'cyg'
+ env['SHLIBSUFFIX'] = '.dll'
+
+ env['IMPLIBPREFIX'] = 'lib'
+ 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: