summaryrefslogtreecommitdiff
path: root/giscanner/shlibs.py
diff options
context:
space:
mode:
authorРуслан Ижбулатов <lrn1986@gmail.com>2014-02-21 11:24:27 +0000
committerColin Walters <walters@verbum.org>2014-02-22 18:54:11 -0500
commitf3fcdf9701fb6e70684479c73f7f3ab5492e3d1a (patch)
treeafbe97a696ba67e82f6f84b63b00cb1aef35b9d8 /giscanner/shlibs.py
parent2a3f311d26c5a5fff813872ea3a3e4d1e30c1beb (diff)
downloadgobject-introspection-f3fcdf9701fb6e70684479c73f7f3ab5492e3d1a.tar.gz
scanner: Fix shlib resolution on W32
GI just adds '.dll' to library name and calls it a day. There's a comment about how this function might work, i've used it to implement something better. This requires a compiler that supports -print-search-dirs argument (i.e. gcc) and a dlltool. https://bugzilla.gnome.org/show_bug.cgi?id=724890
Diffstat (limited to 'giscanner/shlibs.py')
-rw-r--r--giscanner/shlibs.py55
1 files changed, 52 insertions, 3 deletions
diff --git a/giscanner/shlibs.py b/giscanner/shlibs.py
index 21fcafd0..27cd5ce0 100644
--- a/giscanner/shlibs.py
+++ b/giscanner/shlibs.py
@@ -24,7 +24,7 @@ import platform
import re
import subprocess
-from .utils import get_libtool_command, extract_libtool_shlib
+from .utils import get_libtool_command, extract_libtool_shlib, which
# For .la files, the situation is easy.
@@ -89,10 +89,59 @@ def _resolve_non_libtool(options, binary, libraries):
binary.args[0] = old_argdir
if os.name == 'nt':
+ args = []
+ libtool = get_libtool_command(options)
+ if libtool:
+ args.append(which(os.environ.get('SHELL', 'sh.exe')))
+ args.extend(libtool)
+ args.append('--mode=execute')
+ # FIXME: it could have prefix (i686-w64-mingw32-dlltool.exe)
+ args.extend(['dlltool.exe', '--identify'])
+ compiler_cmd = os.environ.get('CC', 'cc')
+ # FIXME: what if it's not gcc?
+ proc = subprocess.Popen([compiler_cmd, '-print-search-dirs'],
+ stdout=subprocess.PIPE)
+ o, e = proc.communicate()
+ libsearch = []
+ for line in o.splitlines():
+ if line.startswith('libraries: '):
+ libsearch = line[len('libraries: '):].split(';')
+
shlibs = []
+ not_resolved = []
+ for lib in libraries:
+ found = False
+ candidates = [
+ 'lib%s.dll.a' % lib,
+ 'lib%s.a' % lib,
+ '%s.dll.a' % lib,
+ '%s.a' % lib,
+ '%s.lib' % lib,
+ ]
+ for l in libsearch:
+ if found:
+ break
+ if l.startswith('='):
+ l = l[1:]
+ for c in candidates:
+ if found:
+ break
+ implib = os.path.join(l, c)
+ if os.path.exists(implib):
+ proc = subprocess.Popen(args + [implib],
+ stdout=subprocess.PIPE)
+ o, e = proc.communicate()
+ for dll in o.splitlines():
+ shlibs.append(dll)
+ found = True
+ break
+ if not found:
+ not_resolved.append(lib)
+ if len(not_resolved) > 0:
+ raise SystemExit(
+ "ERROR: can't resolve libraries to shared libraries: " +
+ ", ".join(not_resolved))
- for library in libraries:
- shlibs.append(library + '.dll')
else:
args = []
libtool = get_libtool_command(options)