/usr/share/clam/sconstools/addDependentLibsToBundle.py is in libclam-dev 1.4.0-6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env python
import os, glob
import sys
def run(command) :
print "\033[32m:: ", command, "\033[0m"
return os.system(command)
def norun(command) :
print "\033[31mXX ", command, "\033[0m"
def needsChange(binary, blacklist) :
#with python2.5 we could just return all([not binary.startswith(blacksheep) for blacksheep in blacklist])
for blacksheep in blacklist :
if binary.startswith( blacksheep ) :
# print "found blackseep", binary
return False
return True
def libDependencies(binary, visited, blacklist) :
# print "examining", binary
for line in os.popen("otool -L "+binary).readlines()[1:] :
entry = line.split()[0]
if entry in visited : continue
if not needsChange( entry, blacklist ) : continue
visited.append( entry )
libDependencies( entry, visited, blacklist )
def addDependentLibsToBundle( bundle ) :
binaries = glob.glob(bundle+"/Contents/MacOS/*")
binaries += glob.glob(bundle+"/Contents/plugins/*")
doNotChange = [
"/System/",
"/usr/lib/",
"@executable_path/",
]
libsPath = []
for binary in binaries :
libDependencies(binary, libsPath, doNotChange)
# print libsPath
libs = [ (os.path.basename(path), path) for path in libsPath ]
run("mkdir -p %(bundle)s/Contents/Frameworks/" % locals() )
vars = {}
# copy all dependent libs to the bundle and change its id (relative path to the bundle)
for lib, path in libs :
run("cp %(path)s %(bundle)s/Contents/Frameworks/%(lib)s" % locals() )
run("install_name_tool -id @executable_path/../Frameworks/%(lib)s %(bundle)s/Contents/Frameworks/%(lib)s" % locals() )
# fix binary dependencies
for current in binaries :
for lib, libpath in libs :
run("install_name_tool -change %(libpath)s @executable_path/../Frameworks/%(lib)s %(current)s" % locals() )
# fix libs dependencies
for current, _ in libs :
for lib, libpath in libs :
run("install_name_tool -change %(libpath)s @executable_path/../Frameworks/%(lib)s %(bundle)s/Contents/Frameworks/%(current)s" % locals() )
if __name__ == "__main__":
addDependentLibsToBundle( "Annotator.app" )
|