3 #/**************************************************************************
4 # * This file is property of and copyright by the ALICE HLT Project *
5 # * All rights reserved. *
8 # * Seforo Mohlalisi <seforomohlalisi@yahoo.co.uk> *
10 # * Permission to use, copy, modify and distribute this software and its *
11 # * documentation strictly for non-commercial purposes is hereby granted *
12 # * without fee, provided that the above copyright notice appears in all *
13 # * copies and that both the copyright notice and this permission notice *
14 # * appear in the supporting documentation. The authors make no claims *
15 # * about the suitability of this software for any purpose. It is *
16 # * provided "as is" without express or implied warranty. *
17 # **************************************************************************/
19 # This script tries to find all dependencies of a library on other libraries.
21 # The first argument to the script should be the directory where your library
22 # of interest resides in. i.e. for
23 # > find_libs directory1 directory2 ... directoryN libXX.so
24 # The library for which we want to find dependencies, libXX.so, must reside
25 # in directory1. All other directories are optional, but the last argument must
26 # be the library name of the library for which we want to find dependencies.
36 sys.argv = sys.argv[1: ]
39 if libname.endswith('.so') == True:
40 command = """nm -C """ + libname + """ | awk '/ U /{print ;}/ T /{print ; }' """
41 for line in os.popen(command).readlines():
42 if '::' in line and not 'for' in line and not 'operator' in line and not 'std::' in line and not 'gnu_cxx::' in line and not 'non-virtual' in line: #To avoid looking for what we cannot find
44 if line.startswith('U'):
46 line = (line.lstrip('U')).strip()
48 line = line[:U] #Take only the class name in the symbol
49 if line not in undefinedSymbols:
50 undefinedSymbols.append(line)
54 line = (line[k+1 : ]).strip()
56 line = line[:T] #Take only the class name in the symbol
57 if definedSymbols.has_key(line) == False:
58 definedSymbols[line] = libname
59 libraries[libname] = undefinedSymbols
61 def findLibs(libname,directory):
62 Usymbols = libraries[libname]
63 foundLibs.append(libname)
65 while i < len(Usymbols):
69 files=[filename for filename in files if filename[0] != '.']
72 if libraries.has_key(f) == False:
74 if definedSymbols.has_key(symbol) and definedSymbols[symbol] in foundLibs:
77 elif definedSymbols.has_key(symbol) and definedSymbols[symbol] not in foundLibs:
78 print definedSymbols[symbol] #Print found library name
80 findLibs(definedSymbols[symbol], directory)
83 if directory < len(sys.argv) - 1:
84 os.chdir(sys.argv[directory])
85 directory = directory + 1
86 continue # Avoid incrementing the index we are searching
88 notFound.append("'"+symbol+"'" + " in " + libname)
91 starttime = time.time()
93 print "Libraries " + sys.argv[-1] + " depends on; Printed in the order which they are called"
95 findLibs(sys.argv[-1],1)
96 stoptime = time.time()
97 elapsed = stoptime - starttime
98 print "Running findLibDeps.py took %.3f seconds" % (elapsed)
100 if len(notFound) > 0:
101 print "Symbols not found"