From 45e00fd7c7695adb9d69e8621ab76fdfa085900b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 5 Oct 2018 07:15:55 +0200 Subject: Fix for windows & mingw --- scripts/mingw_ldd.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/mingw_package.py | 31 +++++++++++++++++++++++++++ scripts/package.py | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100755 scripts/mingw_ldd.py create mode 100755 scripts/mingw_package.py (limited to 'scripts') diff --git a/scripts/mingw_ldd.py b/scripts/mingw_ldd.py new file mode 100755 index 0000000..f678176 --- /dev/null +++ b/scripts/mingw_ldd.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# WTFPL - Do What the Fuck You Want to Public License +from __future__ import print_function +import pefile +import os +import sys + + +def get_dependency(filename): + deps = [] + pe = pefile.PE(filename) + for imp in pe.DIRECTORY_ENTRY_IMPORT: + deps.append(imp.dll.decode()) + return deps + + +def dep_tree(root, prefix=None): + if not prefix: + arch = get_arch(root) + #print('Arch =', arch) + prefix = '/usr/'+arch+'-w64-mingw32/bin' + #print('Using default prefix', prefix) + dep_dlls = dict() + + def dep_tree_impl(root, prefix): + for dll in get_dependency(root): + if dll in dep_dlls: + continue + full_path = os.path.join(prefix, dll) + if os.path.exists(full_path): + dep_dlls[dll] = full_path + dep_tree_impl(full_path, prefix=prefix) + else: + dep_dlls[dll] = 'not found' + + dep_tree_impl(root, prefix) + return (dep_dlls) + + +def get_arch(filename): + type2arch= {pefile.OPTIONAL_HEADER_MAGIC_PE: 'i686', + pefile.OPTIONAL_HEADER_MAGIC_PE_PLUS: 'x86_64'} + pe = pefile.PE(filename) + try: + return type2arch[pe.PE_TYPE] + except KeyError: + sys.stderr.write('Error: unknown architecture') + sys.exit(1) + +if __name__ == '__main__': + filename = sys.argv[1] + for dll, full_path in dep_tree(filename).items(): + print(' ' * 7, dll, '=>', full_path) + diff --git a/scripts/mingw_package.py b/scripts/mingw_package.py new file mode 100755 index 0000000..b304128 --- /dev/null +++ b/scripts/mingw_package.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import sys +import os +import mingw_ldd +import shutil + +def usage(): + print("usage: mingw-package.py ") + exit(1) + +def main(): + if len(sys.argv) != 2: + usage() + + executable_path = sys.argv[1] + if not os.path.isfile(executable_path): + print("arg executable_path is not a file or it's a directory") + exit(2) + executable_path = os.path.realpath(executable_path) + executable_dir = os.path.dirname(executable_path) + + print("Checking dynamic library dependencies of %s..." % executable_path) + deps = mingw_ldd.dep_tree(executable_path) + for dll, full_path in deps.items(): + if full_path != "not found": + print("Copying %s to %s" % (dll, executable_dir)) + shutil.copyfile(full_path, os.path.join(executable_dir, dll)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/package.py b/scripts/package.py index e3a6c52..6e861d9 100755 --- a/scripts/package.py +++ b/scripts/package.py @@ -95,7 +95,7 @@ def remove_blacklisted_libs(libs): return new_libs def main(): - if len(sys.argv) <= 4: + if len(sys.argv) != 5: usage() script_dir = os.path.dirname(os.path.realpath(sys.argv[0])) -- cgit v1.2.3