b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | --- a/src/mklibs |
| 2 | +++ b/src/mklibs |
| 3 | @@ -57,17 +57,17 @@ debuglevel = DEBUG_NORMAL |
| 4 | |
| 5 | def debug(level, *msg): |
| 6 | if debuglevel >= level: |
| 7 | - print(string.join(msg)) |
| 8 | + print(' '.join(msg)) |
| 9 | |
| 10 | # return a list of lines of output of the command |
| 11 | def command(command, *args): |
| 12 | - debug(DEBUG_SPAM, "calling", command, string.join(args)) |
| 13 | + debug(DEBUG_SPAM, "calling", command, ' '.join(args)) |
| 14 | pipe = os.popen(command + ' ' + ' '.join(args), 'r') |
| 15 | output = pipe.read().strip() |
| 16 | status = pipe.close() |
| 17 | if status is not None and os.WEXITSTATUS(status) != 0: |
| 18 | print("Command failed with status", os.WEXITSTATUS(status), ":", \ |
| 19 | - command, string.join(args)) |
| 20 | + command, ' '.join(args)) |
| 21 | print("With output:", output) |
| 22 | sys.exit(1) |
| 23 | return [i for i in output.split('\n') if i] |
| 24 | @@ -296,7 +296,7 @@ def usage(was_err): |
| 25 | print("Make a set of minimal libraries for FILE(s, file=outfd) in DEST.", file=outfd) |
| 26 | print("" , file=outfd) |
| 27 | print(" -d, --dest-dir DIRECTORY create libraries in DIRECTORY", file=outfd) |
| 28 | - print(" -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path, file=outfd), ", file=outfd)", file=outfd) |
| 29 | + print(" -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")", file=outfd) |
| 30 | print(" -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s, file=outfd) to the library search path", file=outfd) |
| 31 | print(" -l LIBRARY add LIBRARY always", file=outfd) |
| 32 | print(" --ldlib LDLIB use LDLIB for the dynamic linker", file=outfd) |
| 33 | @@ -372,7 +372,7 @@ for opt, arg in optlist: |
| 34 | if debuglevel < DEBUG_SPAM: |
| 35 | debuglevel = debuglevel + 1 |
| 36 | elif opt == "-L": |
| 37 | - lib_path.extend(string.split(arg, ":")) |
| 38 | + lib_path.extend(arg.split(":")) |
| 39 | elif opt in ("-d", "--dest-dir"): |
| 40 | dest_path = arg |
| 41 | elif opt in ("-D", "--no-default-lib"): |
| 42 | @@ -391,7 +391,7 @@ for opt, arg in optlist: |
| 43 | elif opt in ("-l",): |
| 44 | force_libs.append(arg) |
| 45 | elif opt == "--gcc-options": |
| 46 | - gcc_options.extend(string.split(arg, " ")) |
| 47 | + gcc_options.extend(arg.split(" ")) |
| 48 | elif opt == "--libdir": |
| 49 | libdir = arg |
| 50 | elif opt in ("--help", "-h"): |
| 51 | @@ -419,17 +419,17 @@ if ldlib == "LDLIB": |
| 52 | objects = {} # map from inode to filename |
| 53 | for prog in proglist: |
| 54 | inode = os.stat(prog)[ST_INO] |
| 55 | - if objects.has_key(inode): |
| 56 | + if inode in objects: |
| 57 | debug(DEBUG_SPAM, prog, "is a hardlink to", objects[inode]) |
| 58 | elif so_pattern.match(prog): |
| 59 | debug(DEBUG_SPAM, prog, "is a library") |
| 60 | - elif script_pattern.match(open(prog).read(256)): |
| 61 | + elif script_pattern.match(open(prog, 'r', encoding='iso-8859-1').read(256)): |
| 62 | debug(DEBUG_SPAM, prog, "is a script") |
| 63 | else: |
| 64 | objects[inode] = prog |
| 65 | |
| 66 | if not ldlib: |
| 67 | - for obj in objects.values(): |
| 68 | + for obj in list(objects.values()): |
| 69 | output = command("mklibs-readelf", "--print-interp", obj) |
| 70 | if output: |
| 71 | ldlib = output.pop() |
| 72 | @@ -462,9 +462,9 @@ previous_pass_unresolved = set() |
| 73 | while 1: |
| 74 | debug(DEBUG_NORMAL, "I: library reduction pass", str(passnr)) |
| 75 | if debuglevel >= DEBUG_VERBOSE: |
| 76 | - print("Objects:",) |
| 77 | - for obj in sorted([x[string.rfind(x, '/') + 1:] for x in objects.values()]): |
| 78 | - print(obj,) |
| 79 | + print("Objects:", end=' ') |
| 80 | + for obj in sorted([x[x.rfind('/') + 1:] for x in list(objects.values())]): |
| 81 | + print(obj, end=' ') |
| 82 | print() |
| 83 | |
| 84 | passnr = passnr + 1 |
| 85 | @@ -474,7 +474,7 @@ while 1: |
| 86 | obj = dest_path + "/" + lib |
| 87 | small_libs.append(obj) |
| 88 | inode = os.stat(obj)[ST_INO] |
| 89 | - if objects.has_key(inode): |
| 90 | + if inode in objects: |
| 91 | debug(DEBUG_SPAM, obj, "is hardlink to", objects[inode]) |
| 92 | else: |
| 93 | objects[inode] = obj |
| 94 | @@ -504,7 +504,7 @@ while 1: |
| 95 | present_symbols = {} |
| 96 | checked_libs = small_libs |
| 97 | checked_libs.extend(available_libs) |
| 98 | - checked_libs.append(ldlib) |
| 99 | + checked_libs.append(sysroot + "/" + ldlib) |
| 100 | for lib in checked_libs: |
| 101 | for symbol in provided_symbols(lib): |
| 102 | debug(DEBUG_SPAM, "present_symbols adding %s" % symbol) |
| 103 | --- a/src/mklibs-copy |
| 104 | +++ b/src/mklibs-copy |
| 105 | @@ -159,7 +159,7 @@ if include_default_lib_path: |
| 106 | objects = {} # map from inode to filename |
| 107 | for prog in proglist: |
| 108 | inode = os.stat(prog)[ST_INO] |
| 109 | - if objects.has_key(inode): |
| 110 | + if inode in objects: |
| 111 | logger.debug("%s is a hardlink to %s", prog, objects[inode]) |
| 112 | elif so_pattern.match(prog): |
| 113 | logger.debug("%s is a library", prog) |
| 114 | @@ -169,7 +169,7 @@ for prog in proglist: |
| 115 | logger.debug("%s is no ELF", prog) |
| 116 | |
| 117 | if not ldlib: |
| 118 | - for obj in objects.values(): |
| 119 | + for obj in list(objects.values()): |
| 120 | output = command("mklibs-readelf", "-i", obj) |
| 121 | for x in output: |
| 122 | ldlib = x |
| 123 | @@ -182,7 +182,7 @@ if not ldlib: |
| 124 | logger.info('Using %s as dynamic linker', ldlib) |
| 125 | |
| 126 | # Check for rpaths |
| 127 | -for obj in objects.values(): |
| 128 | +for obj in list(objects.values()): |
| 129 | rpath_val = rpath(obj) |
| 130 | if rpath_val: |
| 131 | if root: |
| 132 | @@ -208,18 +208,18 @@ while 1: |
| 133 | obj = dest_path + "/" + lib |
| 134 | small_libs.append(obj) |
| 135 | inode = os.stat(obj)[ST_INO] |
| 136 | - if objects.has_key(inode): |
| 137 | + if inode in objects: |
| 138 | logger.debug("%s is hardlink to %s", obj, objects[inode]) |
| 139 | else: |
| 140 | objects[inode] = obj |
| 141 | |
| 142 | - for obj in objects.values(): |
| 143 | + for obj in list(objects.values()): |
| 144 | small_libs.append(obj) |
| 145 | |
| 146 | - logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.itervalues()])) |
| 147 | + logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.values()])) |
| 148 | |
| 149 | libraries = set() |
| 150 | - for obj in objects.values(): |
| 151 | + for obj in list(objects.values()): |
| 152 | libraries.update(library_depends(obj)) |
| 153 | |
| 154 | if libraries == previous_pass_libraries: |