summaryrefslogtreecommitdiff
path: root/giscanner/ccompiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'giscanner/ccompiler.py')
-rw-r--r--giscanner/ccompiler.py48
1 files changed, 38 insertions, 10 deletions
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index 7a1e9393..2912fe0e 100644
--- a/giscanner/ccompiler.py
+++ b/giscanner/ccompiler.py
@@ -95,6 +95,41 @@ def customize_compiler(compiler):
compiler.shared_lib_extension = shlib_suffix
+def resolve_mingw_lib(implib, libtool=None):
+ """Returns a DLL name given a path to an import lib
+
+ /full/path/to/libgtk-3.dll.a -> libgtk-3-0.dll
+ """
+
+ args = []
+ if libtool:
+ args.extend(libtool)
+ args.append('--mode=execute')
+
+ # Figure out if we have a gcc toolchain or llvm one
+ dlltool = os.environ.get('DLLTOOL', 'dlltool.exe')
+ dlltool_output = subprocess.run(
+ [dlltool], stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ universal_newlines=True).stdout
+ is_llvm = 'llvm-dlltool' in dlltool_output
+
+ if not is_llvm:
+ # gcc dlltool provides this via --identify
+ dlltool_args = args + [dlltool, '--identify']
+ output = subprocess.check_output(dlltool_args + [implib], universal_newlines=True)
+ for line in output.splitlines():
+ return line
+ else:
+ # for llvm we need to parse the output of nm
+ # https://github.com/msys2/MINGW-packages/issues/11994#issuecomment-1176691216
+ output = subprocess.check_output(args + ['nm', implib], universal_newlines=True)
+ for line in output.splitlines():
+ if line.endswith(':'):
+ return line[:-1]
+ return None
+
+
# Flags that retain macros in preprocessed output.
FLAGS_RETAINING_MACROS = ['-g3', '-ggdb3', '-gstabs3', '-gcoff3', '-gxcoff3', '-gvms3']
@@ -341,10 +376,6 @@ class CCompiler(object):
# When we are not using Visual C++ nor clang-cl (i.e. we are using GCC)...
else:
libtool = utils.get_libtool_command(options)
- if libtool:
- args.extend(libtool)
- args.append('--mode=execute')
- args.extend([os.environ.get('DLLTOOL', 'dlltool.exe'), '--identify'])
proc = subprocess.Popen([self.compiler_cmd, '-print-search-dirs'],
stdout=subprocess.PIPE)
o, e = proc.communicate()
@@ -400,13 +431,10 @@ class CCompiler(object):
tmp_fileobj.close()
os.unlink(tmp_filename)
else:
- proc = subprocess.Popen(args + [implib],
- stdout=subprocess.PIPE)
- o, e = proc.communicate()
- for line in o.decode('ascii').splitlines():
- shlibs.append(line)
+ shlib = resolve_mingw_lib(implib, libtool)
+ if shlib is not None:
+ shlibs.append(shlib)
found = True
- break
if not found:
not_resolved.append(lib)
if len(not_resolved) > 0: