bless osx Qt components and make a .dmg
authorDiane Trout <diane@caltech.edu>
Wed, 22 Mar 2006 00:42:24 +0000 (00:42 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 22 Mar 2006 00:42:24 +0000 (00:42 +0000)
OS X needs to have the location of any shared libraries prelinked
(at build time). This does that, and then makes a dmg.

osxdist.py [new file with mode: 0644]

diff --git a/osxdist.py b/osxdist.py
new file mode 100644 (file)
index 0000000..b1e820a
--- /dev/null
@@ -0,0 +1,87 @@
+#!/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(app_dir):
+  # need to detect what the real volume name is
+  mussa_mount = '/Volumes/Mussa'
+  mussarw_dmg = 'mussarw.dmg'
+  mussa_dmg = 'mussa.dmg'
+  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 "Mussa" '+mussarw_dmg)
+  system('hdiutil attach '+mussarw_dmg)
+  # copy files
+  copytree(app_dir, os.path.join(mussa_mount, app_dir))
+
+  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.0-shared/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)
+
+if __name__ == "__main__":
+  main(sys.argv[1:])