tools/mklibs: update to 0.1.44 and convert to Python 3
[oweals/openwrt.git] / tools / mklibs / patches / 100-apply-2to3.patch
1 --- a/src/mklibs
2 +++ b/src/mklibs
3 @@ -57,18 +57,18 @@ 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 -       print "With output:", output
21 +        print("Command failed with status", os.WEXITSTATUS(status),  ":", \
22 +               command, ' '.join(args))
23 +        print("With output:", output)
24          sys.exit(1)
25      return [i for i in output.split('\n') if i]
26  
27 @@ -204,7 +204,7 @@ class ProvidedSymbol(Symbol):
28  # Return a set of symbols provided by a library
29  def provided_symbols(obj):
30      if not os.access(obj, os.F_OK):
31 -        raise Exception("Cannot find lib" + obj)
32 +        raise Exception("Cannot find lib " + obj)
33      library = extract_soname(obj)
34  
35      output = command("mklibs-readelf", "--print-symbols-provided", obj)
36 @@ -297,27 +297,27 @@ def usage(was_err):
37          outfd = sys.stderr
38      else:
39          outfd = sys.stdout
40 -    print >> outfd, "Usage: mklibs [OPTION]... -d DEST FILE ..."
41 -    print >> outfd, "Make a set of minimal libraries for FILE(s) in DEST."
42 -    print >> outfd, "" 
43 -    print >> outfd, "  -d, --dest-dir DIRECTORY     create libraries in DIRECTORY"
44 -    print >> outfd, "  -D, --no-default-lib         omit default libpath (", ':'.join(default_lib_path), ")"
45 -    print >> outfd, "  -L DIRECTORY[:DIRECTORY]...  add DIRECTORY(s) to the library search path"
46 -    print >> outfd, "  -l LIBRARY                   add LIBRARY always"
47 -    print >> outfd, "      --ldlib LDLIB            use LDLIB for the dynamic linker"
48 -    print >> outfd, "      --libc-extras-dir DIRECTORY  look for libc extra files in DIRECTORY"
49 -    print >> outfd, "      --target TARGET          prepend TARGET- to the gcc and binutils calls"
50 -    print >> outfd, "      --root ROOT              search in ROOT for library rpaths"
51 -    print >> outfd, "      --sysroot ROOT           prepend ROOT to all paths for libraries"
52 -    print >> outfd, "      --gcc-options OPTIONS    pass OPTIONS to gcc"
53 -    print >> outfd, "      --libdir DIR             use DIR (e.g. lib64) in place of lib in default paths"
54 -    print >> outfd, "  -v, --verbose                explain what is being done"
55 -    print >> outfd, "  -h, --help                   display this help and exit"
56 +    print("Usage: mklibs [OPTION]... -d DEST FILE ...", file=outfd)
57 +    print("Make a set of minimal libraries for FILE(s) in DEST.", file=outfd)
58 +    print("", file=outfd) 
59 +    print("  -d, --dest-dir DIRECTORY     create libraries in DIRECTORY", file=outfd)
60 +    print("  -D, --no-default-lib         omit default libpath (", ':'.join(default_lib_path), ")", file=outfd)
61 +    print("  -L DIRECTORY[:DIRECTORY]...  add DIRECTORY(s) to the library search path", file=outfd)
62 +    print("  -l LIBRARY                   add LIBRARY always", file=outfd)
63 +    print("      --ldlib LDLIB            use LDLIB for the dynamic linker", file=outfd)
64 +    print("      --libc-extras-dir DIRECTORY  look for libc extra files in DIRECTORY", file=outfd)
65 +    print("      --target TARGET          prepend TARGET- to the gcc and binutils calls", file=outfd)
66 +    print("      --root ROOT              search in ROOT for library rpaths", file=outfd)
67 +    print("      --sysroot ROOT           prepend ROOT to all paths for libraries", file=outfd)
68 +    print("      --gcc-options OPTIONS    pass OPTIONS to gcc", file=outfd)
69 +    print("      --libdir DIR             use DIR (e.g. lib64) in place of lib in default paths", file=outfd)
70 +    print("  -v, --verbose                explain what is being done", file=outfd)
71 +    print("  -h, --help                   display this help and exit", file=outfd)
72      sys.exit(was_err)
73  
74  def version(vers):
75 -    print "mklibs: version ",vers
76 -    print ""
77 +    print("mklibs: version ",vers)
78 +    print("")
79  
80  #################### main ####################
81  ## Usage: ./mklibs.py [OPTION]... -d DEST FILE ...
82 @@ -368,8 +368,8 @@ script_pattern = re.compile("^#!\s*/")
83  
84  try:
85      optlist, proglist = getopt.getopt(sys.argv[1:], opts, longopts)
86 -except getopt.GetoptError, msg:
87 -    print >> sys.stderr, msg
88 +except getopt.GetoptError as msg:
89 +    print(msg, file=sys.stderr)
90      usage(1)
91  
92  for opt, arg in optlist:
93 @@ -377,7 +377,7 @@ for opt, arg in optlist:
94          if debuglevel < DEBUG_SPAM:
95              debuglevel = debuglevel + 1
96      elif opt == "-L":
97 -        lib_path.extend(string.split(arg, ":"))
98 +        lib_path.extend(arg.split(":"))
99      elif opt in ("-d", "--dest-dir"):
100          dest_path = arg
101      elif opt in ("-D", "--no-default-lib"):
102 @@ -396,17 +396,17 @@ for opt, arg in optlist:
103      elif opt in ("-l",):
104          force_libs.append(arg)
105      elif opt == "--gcc-options":
106 -        gcc_options.extend(string.split(arg, " "))
107 +        gcc_options.extend(arg.split(" "))
108      elif opt == "--libdir":
109          libdir = arg
110      elif opt in ("--help", "-h"):
111 -       usage(0)
112 +        usage(0)
113          sys.exit(0)
114      elif opt in ("--version", "-V"):
115          version(vers)
116          sys.exit(0)
117      else:
118 -        print "WARNING: unknown option: " + opt + "\targ: " + arg
119 +        print("WARNING: unknown option: " + opt + "\targ: " + arg)
120  
121  if include_default_lib_path == "yes":
122      lib_path.extend([a.replace("/lib/", "/" + libdir + "/") for a in default_lib_path])
123 @@ -424,22 +424,22 @@ if ldlib == "LDLIB":
124  objects = {}  # map from inode to filename
125  for prog in proglist:
126      inode = os.stat(prog)[ST_INO]
127 -    if objects.has_key(inode):
128 +    if inode in objects:
129          debug(DEBUG_SPAM, prog, "is a hardlink to", objects[inode])
130      elif so_pattern.match(prog):
131          debug(DEBUG_SPAM, prog, "is a library")
132 -    elif script_pattern.match(open(prog).read(256)):
133 +    elif script_pattern.match(open(prog, 'r', encoding='iso-8859-1').read(256)):
134          debug(DEBUG_SPAM, prog, "is a script")
135      else:
136          objects[inode] = prog
137  
138  if not ldlib:
139 -    for obj in objects.values():
140 +    for obj in list(objects.values()):
141          output = command("mklibs-readelf", "--print-interp", obj)
142          if output:
143              ldlib = output.pop()
144 -       if ldlib:
145 -           break
146 +        if ldlib:
147 +            break
148  
149  if not ldlib:
150      sys.exit("E: Dynamic linker not found, aborting.")
151 @@ -454,10 +454,10 @@ for obj in sorted(objects.values()):
152              for rpath_elem in rpath_val:
153                  if not rpath_elem in lib_rpath:
154                      if debuglevel >= DEBUG_VERBOSE:
155 -                        print "Adding rpath " + rpath_elem + " for " + obj
156 +                        print("Adding rpath " + rpath_elem + " for " + obj)
157                      lib_rpath.append(rpath_elem)
158          else:
159 -            print "warning: " + obj + " may need rpath, but --root not specified"
160 +            print("warning: " + obj + " may need rpath, but --root not specified")
161  
162  lib_path.extend(lib_rpath)
163  
164 @@ -465,12 +465,12 @@ passnr = 1
165  available_libs = []
166  previous_pass_unresolved = set()
167  while 1:
168 -    debug(DEBUG_NORMAL, "I: library reduction pass", `passnr`)
169 +    debug(DEBUG_NORMAL, "I: library reduction pass", repr(passnr))
170      if debuglevel >= DEBUG_VERBOSE:
171 -        print "Objects:",
172 -        for obj in sorted([x[string.rfind(x, '/') + 1:] for x in objects.values()]):
173 -            print obj,
174 -        print
175 +        print("Objects:", end=' ')
176 +        for obj in sorted([x[x.rfind('/') + 1:] for x in list(objects.values())]):
177 +            print(obj, end=' ')
178 +        print()
179  
180      passnr = passnr + 1
181      # Gather all already reduced libraries and treat them as objects as well
182 @@ -479,7 +479,7 @@ while 1:
183          obj = dest_path + "/" + lib
184          small_libs.append(obj)
185          inode = os.stat(obj)[ST_INO]
186 -        if objects.has_key(inode):
187 +        if inode in objects:
188              debug(DEBUG_SPAM, obj, "is hardlink to", objects[inode])
189          else:
190              objects[inode] = obj
191 @@ -509,7 +509,7 @@ while 1:
192      present_symbols = {}
193      checked_libs = small_libs
194      checked_libs.extend(available_libs)
195 -    checked_libs.append(ldlib)
196 +    checked_libs.append(sysroot + "/" + ldlib)
197      for lib in checked_libs:
198          for symbol in provided_symbols(lib):
199              debug(DEBUG_SPAM, "present_symbols adding %s" % symbol)
200 @@ -529,8 +529,8 @@ while 1:
201              unresolved.add(name)
202              num_unresolved = num_unresolved + 1
203  
204 -    debug (DEBUG_NORMAL, `len(needed_symbols)`, "symbols,",
205 -           `num_unresolved`, "unresolved")
206 +    debug (DEBUG_NORMAL, repr(len(needed_symbols)), "symbols,",
207 +           repr(num_unresolved), "unresolved")
208  
209      if num_unresolved == 0:
210          break
211 @@ -539,7 +539,7 @@ while 1:
212          # No progress in last pass. Verify all remaining symbols are weak.
213          for name in unresolved:
214              if not needed_symbols[name].weak:
215 -                print "WARNING: Unresolvable symbol %s" % name
216 +                print("WARNING: Unresolvable symbol %s" % name)
217          break
218  
219      previous_pass_unresolved = unresolved
220 @@ -641,9 +641,9 @@ while 1:
221              command(target + "gcc", *cmd)
222  
223              ## DEBUG
224 -            debug(DEBUG_VERBOSE, so_file, "\t", `os.stat(so_file)[ST_SIZE]`)
225 +            debug(DEBUG_VERBOSE, so_file, "\t", repr(os.stat(so_file)[ST_SIZE]))
226              debug(DEBUG_VERBOSE, dest_path + "/" + so_file_name + "-so", "\t",
227 -                  `os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]`)
228 +                  repr(os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]))
229  
230  # Finalising libs and cleaning up
231  for lib in regexpfilter(os.listdir(dest_path), "(.*)-so$"):
232 @@ -680,4 +680,4 @@ if not os.access(dest_path + "/" + ld_fu
233      command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
234              ld_file, dest_path + "/" + ld_full_path)
235  
236 -os.chmod(dest_path + "/" + ld_full_path, 0755)
237 +os.chmod(dest_path + "/" + ld_full_path, 0o755)
238 --- a/src/mklibs-copy
239 +++ b/src/mklibs-copy
240 @@ -51,9 +51,9 @@ def command(command, *args):
241      output = pipe.read().strip()
242      status = pipe.close()
243      if status is not None and os.WEXITSTATUS(status) != 0:
244 -        print "Command failed with status", os.WEXITSTATUS(status),  ":", \
245 -               command, ' '.join(args)
246 -       print "With output:", output
247 +        print("Command failed with status", os.WEXITSTATUS(status),  ":", \
248 +               command, ' '.join(args))
249 +        print("With output:", output)
250          sys.exit(1)
251      return output.split('\n')
252  
253 @@ -134,8 +134,8 @@ def multiarch(paths):
254          return paths
255  
256  def version(vers):
257 -    print "mklibs: version ",vers
258 -    print ""
259 +    print("mklibs: version ",vers)
260 +    print("")
261  
262  # Clean the environment
263  vers="0.12"
264 @@ -159,7 +159,7 @@ if include_default_lib_path:
265  objects = {}  # map from inode to filename
266  for prog in proglist:
267      inode = os.stat(prog)[ST_INO]
268 -    if objects.has_key(inode):
269 +    if inode in objects:
270          logger.debug("%s is a hardlink to %s", prog, objects[inode])
271      elif so_pattern.match(prog):
272          logger.debug("%s is a library", prog)
273 @@ -169,12 +169,12 @@ for prog in proglist:
274          logger.debug("%s is no ELF", prog)
275  
276  if not ldlib:
277 -    for obj in objects.values():
278 +    for obj in list(objects.values()):
279          output = command("mklibs-readelf", "-i", obj)
280 -       for x in output:
281 +        for x in output:
282              ldlib = x
283 -       if ldlib:
284 -           break
285 +        if ldlib:
286 +            break
287  
288  if not ldlib:
289      sys.exit("E: Dynamic linker not found, aborting.")
290 @@ -182,7 +182,7 @@ if not ldlib:
291  logger.info('Using %s as dynamic linker', ldlib)
292  
293  # Check for rpaths
294 -for obj in objects.values():
295 +for obj in list(objects.values()):
296      rpath_val = rpath(obj)
297      if rpath_val:
298          if root:
299 @@ -208,18 +208,18 @@ while 1:
300          obj = dest_path + "/" + lib
301          small_libs.append(obj)
302          inode = os.stat(obj)[ST_INO]
303 -        if objects.has_key(inode):
304 +        if inode in objects:
305              logger.debug("%s is hardlink to %s", obj, objects[inode])
306          else:
307              objects[inode] = obj
308  
309 -    for obj in objects.values():
310 +    for obj in list(objects.values()):
311          small_libs.append(obj)
312  
313 -    logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.itervalues()]))
314 +    logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.values()]))
315  
316      libraries = set()
317 -    for obj in objects.values():
318 +    for obj in list(objects.values()):
319          libraries.update(library_depends(obj))
320  
321      if libraries == previous_pass_libraries:
322 @@ -272,4 +272,4 @@ if not os.access(dest_path + "/" + ld_fu
323      command(target + "objcopy", "--strip-unneeded -R .note -R .comment",
324              ld_file, dest_path + "/" + ld_full_path)
325  
326 -os.chmod(dest_path + "/" + ld_full_path, 0755)
327 +os.chmod(dest_path + "/" + ld_full_path, 0o755)