#!/usr/bin/env python """mkliborder.py""" import sys import string dependencies = {} ordered_libs = [] stack = [] def main(): global ordered_libs global stack # check passed args #if len(sys.argv) <= 2: # sys.exit(1) # get the list of libraries to expand #lib_list = sys.argv[2:] # suck in the passed libdeps info read_libdeps() lib_list = dependencies.keys() lib_list.sort() # this list is for speed only lib_seen = {} lib_added = {} # expand the library list based on the libdeps info stack = lib_list[:] while (len(stack) > 0): lib = stack[0] #print len(stack), lib if lib_seen.has_key(lib): del stack[0] if not lib_added.has_key(lib): #print "Adding", lib ordered_libs.append(lib) lib_added[lib] = 1 else: lib_seen[lib] = 1 dep_list = dependencies.get(lib) if dep_list: #print "Stacking", dep_list stack[:0] = dep_list else: del stack[0] if not lib_added.has_key(lib): #print "Adding", lib ordered_libs.append(lib) lib_added[lib] = 1 # print our result ordered_libs.reverse() #print string.join(ordered_libs) for lib in ordered_libs: print lib #if len(lib_list) > 250: # sys.stderr.write("Warning: wow, that is a lot of libraries on the link line (%d)!\n" % len(lib_list)) # sys.stderr.flush() def read_libdeps(): global dependencies #libdepsfil = open(sys.argv[1]) for line in sys.stdin.readlines(): f = string.split(line) if len(f) > 0: lib = f[0] if (len(f) >= 2) and (f[1] == ":") and (lib != ".PHONY") and (lib != "pkgs") and (lib != r"%") and (lib != r"%.mk"): dependencies[lib] = f[2:] if __name__ == "__main__": # We are being run as a script. main() else: # We are being loaded as a module. pass