aboutsummaryrefslogtreecommitdiff
path: root/scripts/mingw_package.py
blob: b30412812c0c25e6ea82a8fec8e1259ff494f146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

import sys
import os
import mingw_ldd
import shutil

def usage():
    print("usage: mingw-package.py <executable_path>")
    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()