2008-12-29 02:13:55 +01:00
|
|
|
#!/usr/bin/env python
|
2008-11-24 21:29:47 +01:00
|
|
|
|
2008-11-25 02:10:28 +01:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
is_bad_lib = re.compile(r'(/usr/local|/opt)').match
|
|
|
|
is_sys_lib = re.compile(r'(/usr|/System)').match
|
|
|
|
otool_libname_extract = re.compile(r'\s+(/.*?)[\(\s:]').search
|
2008-12-29 05:41:00 +01:00
|
|
|
goodlist = []
|
2008-11-25 02:10:28 +01:00
|
|
|
|
|
|
|
def otool(cmdline):
|
|
|
|
pipe = os.popen("otool " + cmdline, 'r')
|
|
|
|
output = pipe.readlines()
|
|
|
|
pipe.close()
|
|
|
|
return output
|
|
|
|
|
|
|
|
def collectlibs(lib, masterlist, targetdir):
|
2008-12-29 05:41:00 +01:00
|
|
|
global goodlist
|
2008-11-25 02:10:28 +01:00
|
|
|
liblist = otool("-L " + lib)
|
|
|
|
locallist = []
|
|
|
|
for l in liblist:
|
|
|
|
lr = otool_libname_extract(l)
|
|
|
|
if not lr: continue
|
|
|
|
l = lr.group(1)
|
|
|
|
if is_bad_lib(l):
|
|
|
|
sys.exit("Linking with library in blacklisted location: " + l)
|
|
|
|
if not is_sys_lib(l) and not l in masterlist:
|
|
|
|
locallist.append(l)
|
2008-12-29 05:41:00 +01:00
|
|
|
print "found ", l,
|
2008-11-25 02:10:28 +01:00
|
|
|
shutil.copy(l, targetdir)
|
|
|
|
print " ...copied to target"
|
2008-12-29 05:41:00 +01:00
|
|
|
elif not l in goodlist and not l in masterlist:
|
|
|
|
goodlist.append(l)
|
2008-11-25 02:10:28 +01:00
|
|
|
masterlist.extend(locallist)
|
|
|
|
for l in locallist:
|
|
|
|
collectlibs(l, masterlist, targetdir)
|
|
|
|
|
|
|
|
binname = sys.argv[1]
|
|
|
|
targetdir = os.path.dirname(binname)
|
|
|
|
print "Searching for libraries in ", binname, "..."
|
|
|
|
libs = [binname]
|
|
|
|
collectlibs(sys.argv[1], libs, targetdir)
|
|
|
|
|
2008-12-29 05:41:00 +01:00
|
|
|
print
|
|
|
|
print "System libraries used..."
|
|
|
|
goodlist.sort()
|
|
|
|
for l in goodlist:
|
|
|
|
print l
|
|
|
|
|
|
|
|
|
|
|
|
print
|
|
|
|
print "Fixing library install names..."
|
2008-11-25 02:10:28 +01:00
|
|
|
in_tool_cmdline = "install_name_tool "
|
|
|
|
for lib in libs:
|
|
|
|
libbase = os.path.basename(lib)
|
|
|
|
in_tool_cmdline = in_tool_cmdline + ("-change %s @executable_path/%s " % (lib, libbase))
|
|
|
|
for lib in libs:
|
|
|
|
libbase = os.path.basename(lib)
|
|
|
|
os.system("%s -id @executable_path/%s '%s/%s'" % (in_tool_cmdline, libbase, targetdir, libbase))
|
2008-12-29 05:41:00 +01:00
|
|
|
print lib, "-> @executable_path/" + libbase
|
2008-11-25 02:10:28 +01:00
|
|
|
sys.stdout.flush()
|
2008-12-29 05:41:00 +01:00
|
|
|
|
2008-11-25 02:10:28 +01:00
|
|
|
print
|
|
|
|
print "All done!"
|