* [SCons] Fix for the cyglink tool
@ 2013-08-07 16:46 Zouzou
2013-08-07 19:05 ` David Rothenberger
0 siblings, 1 reply; 2+ messages in thread
From: Zouzou @ 2013-08-07 16:46 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 569 bytes --]
Hi,
The cyglink tool in Cygwin's distrib of SCons has a typo that prevents
it from generating .a import files when building shared libraries with
the SharedLibrary method.
In cyglink.py, shlib_emitter creates a target file named with
IMPLIBPREFIX and IMPLIBSUFFIX but shlib_generator checks for LIBPREFIX
and LIBSUFFIX, which fails. The fix is to have shlib_generator check for
IMPLIBPREFIX and IMPLIBSUFFIX.
I am attaching a modified cyglink.patch with the correction; and a
"patch of the patch" that shows which line of cyglink.patch I have changed.
Zouzou
[-- Attachment #2: cyglink.patch --]
[-- Type: text/plain, Size: 4848 bytes --]
Add a cyglink Tool to handle linking of shared libraries under
From: David Rothenberger <daveroth@acm.org>
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:
[-- Attachment #3: cyglinkimplib.patch --]
[-- Type: text/plain, Size: 419 bytes --]
--- cyglink.patch 2013-07-05 10:28:40.000000000 +0200
+++ cyglink2.patch 2013-08-07 18:34:42.785377200 +0200
@@ -71,7 +71,7 @@
+
+ cmd.extend(['$SHLINKFLAGS', '$__RPATH'])
+
-+ implib = env.FindIxes(target, 'LIBPREFIX', 'LIBSUFFIX')
++ implib = env.FindIxes(target, 'IMPLIBPREFIX', 'IMPLIBSUFFIX')
+ if implib:
+ cmd.extend([
+ '-Wl,--out-implib='+implib.get_string(for_signature),
[-- Attachment #4: Type: text/plain, Size: 218 bytes --]
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [SCons] Fix for the cyglink tool
2013-08-07 16:46 [SCons] Fix for the cyglink tool Zouzou
@ 2013-08-07 19:05 ` David Rothenberger
0 siblings, 0 replies; 2+ messages in thread
From: David Rothenberger @ 2013-08-07 19:05 UTC (permalink / raw)
To: cygwin
Zouzou wrote:
> The cyglink tool in Cygwin's distrib of SCons has a typo that prevents
> it from generating .a import files when building shared libraries with
> the SharedLibrary method.
>
> In cyglink.py, shlib_emitter creates a target file named with
> IMPLIBPREFIX and IMPLIBSUFFIX but shlib_generator checks for LIBPREFIX
> and LIBSUFFIX, which fails. The fix is to have shlib_generator check for
> IMPLIBPREFIX and IMPLIBSUFFIX.
>
> I am attaching a modified cyglink.patch with the correction; and a
> "patch of the patch" that shows which line of cyglink.patch I have changed.
Thanks for the patch.
I originally did the cyglink.py tool to build serf and it worked
correctly for serf's build script. At least I'm pretty sure it did. I'll
take a look at your patch and apply it if serf still builds as well.
--
David Rothenberger ---- daveroth@acm.org
QOTD:
"It's been Monday all week today."
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-08-07 19:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-07 16:46 [SCons] Fix for the cyglink tool Zouzou
2013-08-07 19:05 ` David Rothenberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).