2 # -*- coding: iso-8859-1 -*-
4 ################################################################################
6 # 2008 June 27th by Marcus 'EgS' Eggenberger <egs@quassel-irc.org> #
8 # The author disclaims copyright to this source code. #
9 # This Python Script is in the PUBLIC DOMAIN. #
11 ################################################################################
13 # ==============================
15 # ==============================
19 class InstallQt(object):
20 def __init__(self, appdir, bundle = True):
23 self.executableDir = self.appDir
25 self.executableDir += "/MacOS"
28 self.frameworkDir = self.appDir + "/Frameworks"
30 self.frameworkDir = self.executableDir + "/Frameworks"
32 self.needFrameworks = []
34 executables = [self.executableDir + "/" + executable for executable in os.listdir(self.executableDir)]
36 for executable in executables:
37 for framework,lib in self.determineDependancies(executable):
38 if framework not in self.needFrameworks:
39 self.needFrameworks.append(framework)
40 self.installFramework(framework)
41 self.changeDylPath(executable)
43 def installFramework(self, framework):
45 os.mkdir(self.frameworkDir)
50 os.system('cp -R "%s" "%s"' % (framework, self.frameworkDir))
52 frameworkname = framework.split('/')[-1]
53 localframework = self.frameworkDir + "/" + frameworkname
56 os.system('find "%s" -name *debug* -exec rm -f {} \;' % localframework)
57 os.system('find "%s" -name Headers -exec rm -rf {} \; 2>/dev/null' % localframework)
59 # Install new Lib ID and Change Path to Frameworks for the Dynamic linker
60 for lib in os.listdir(localframework + "/Versions/Current"):
61 lib = "%s/Versions/Current/%s" % (localframework, lib)
62 otoolpipe = os.popen('otool -D "%s"' % lib)
63 libname = [line for line in otoolpipe][1].strip()
65 frameworkpath, libpath = libname.split(frameworkname)
67 newlibname = "@executable_path/../%s%s" % (frameworkname, libpath)
69 newlibname = "@executable_path/%s%s" % (frameworkname, libpath)
70 #print 'install_name_tool -id "%s" "%s"' % (newlibname, lib)
71 os.system('install_name_tool -id "%s" "%s"' % (newlibname, lib))
72 self.changeDylPath(lib)
74 def determineDependancies(self, app):
75 otoolPipe = os.popen('otool -L "%s"' % app)
76 otoolOutput = [line for line in otoolPipe]
78 libs = [line.split()[0] for line in otoolOutput[1:] if "Qt" in line and not "@executable_path" in line]
79 frameworks = [lib[:lib.find(".framework")+len(".framework")] for lib in libs]
80 return zip(frameworks, libs)
82 def changeDylPath(self, obj):
83 for framework, lib in self.determineDependancies(obj):
84 frameworkname = framework.split('/')[-1]
85 frameworkpath, libpath = lib.split(frameworkname)
87 newlibname = "@executable_path/../Frameworks/%s%s" % (frameworkname, libpath)
89 newlibname = "@executable_path/Frameworks/%s%s" % (frameworkname, libpath)
91 #print 'install_name_tool -change "%s" "%s" "%s"' % (lib, newlibname, obj)
92 os.system('install_name_tool -change "%s" "%s" "%s"' % (lib, newlibname, obj))
94 if __name__ == "__main__":
96 print "Wrong Argument Count (Syntax: %s [--nobundle] $TARGET_APP)" % sys.argv[0]
102 if sys.argv[1].startswith("--"):
104 if sys.argv[1] == "--nobundle":
107 targetDir = sys.argv[offset]
109 targetDir += "/Contents"
111 InstallQt(targetDir, bundle)