+#!/usr/bin/env python
+
+import os
+import sys
+from shutil import copy, copytree
+
+def system(cmdline):
+ #print >>sys.stderr, cmdline
+ return os.system(cmdline)
+
+def mkdir(path):
+ path_list = []
+ head, tail = os.path.split(path)
+ path_list.insert(0, tail)
+ while len(head) > 0:
+ head, tail = os.path.split(head)
+ path_list.insert(0, tail)
+ created_path = ""
+ for path_element in path_list:
+ created_path = os.path.join(created_path, path_element)
+ if not os.path.exists(created_path):
+ os.mkdir(created_path)
+
+# useful information about building dmgs
+# http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix
+# http://developer.apple.com/documentation/developertools/Conceptual/SoftwareDistribution/Concepts/sd_disk_images.html
+
+def makedmg(dirlist, volname):
+ # need to detect what the real volume name is
+ mussa_mount = '/Volumes/%s' %(volname)
+ mussarw_dmg = '%sw.dmg' %(volname)
+ mussa_dmg = '%s.dmg' %(volname)
+ system('hdiutil detach '+mussa_mount)
+ if os.path.exists(mussa_mount):
+ print >>sys.stderr, "Something is in", mussa_mount
+ return
+ if os.path.exists(mussarw_dmg):
+ os.unlink(mussarw_dmg)
+ if os.path.exists(mussa_dmg):
+ os.unlink(mussa_dmg)
+ system('hdiutil create -size 64m -fs HFS+ -volname "%s" %s'%(volname, mussarw_dmg))
+ system('hdiutil attach '+mussarw_dmg)
+ # copy files
+ for d in dirlist:
+ copytree(d, os.path.join(mussa_mount, d))
+
+ system('hdiutil detach '+mussa_mount)
+ system('hdiutil convert '+mussarw_dmg +' -format UDZO -o '+mussa_dmg)
+ #system('hdiutil internet-enable -yes '+mussa_dmg)
+
+def main(args):
+ framework_subpath = os.path.join("%(framework)s.framework", "Versions", "4.0", "%(framework)s")
+ frameworks = ['QtCore', 'QtGui', 'QtOpenGL']
+
+ qt_lib_dir="/usr/local/qt-4.1.1/lib"
+ qt_framework=os.path.join(qt_lib_dir, framework_subpath)
+
+ app_name="mussagl"
+ app_dir=app_name+".app"
+ app_binary=app_dir+"/Contents/MacOS/"+app_name
+ app_framework=os.path.join(app_dir, "Contents", "Frameworks", framework_subpath)
+ if not os.path.exists(app_dir):
+ print >>sys.stderr, "please build mussagl first"
+ return 1
+
+ # install frameworks and update binary
+ for frame in frameworks:
+ qtframe = qt_framework % ({'framework': frame})
+ appframe = app_framework % ({'framework': frame})
+ exe_path = "@executable_path/../Frameworks/" + framework_subpath
+ exe_path %= ({'framework': frame})
+ mkdir(os.path.split(appframe)[0])
+ # update binary
+ copy(qtframe, appframe)
+ system("install_name_tool -id "+exe_path+" "+appframe)
+ system("install_name_tool -change "+qtframe+" "+exe_path+" "+app_binary)
+ # now that everything is in place change the frameworks
+ # references
+ for frame2 in frameworks:
+ qtframe2 = qt_framework % ({'framework': frame2})
+ contents_exe_path = "@executable_path/../Frameworks/" + framework_subpath
+ contents_exe_path %= ({'framework': frame2})
+ system("install_name_tool -change "+qtframe2+" "+contents_exe_path+" "+
+ appframe)
+ makedmg([app_dir], 'mussa')
+
+if __name__ == "__main__":
+ main(sys.argv[1:])