500cdd5b729b0f3616d5103e7746e2cea7d48aa3
[mussa.git] / makelib / osxdist.py
1 #!/usr/bin/env python
2
3 import os
4 import sys
5 from shutil import copy, copytree
6
7 def system(cmdline):
8   #print >>sys.stderr, cmdline
9   return os.system(cmdline)
10
11 def mkdir(path):
12   path_list = []
13   head, tail = os.path.split(path)
14   path_list.insert(0, tail)
15   while len(head) > 0:
16     head, tail = os.path.split(head)
17     path_list.insert(0, tail)
18   created_path = ""
19   for path_element in path_list:
20     created_path = os.path.join(created_path, path_element)
21     if not os.path.exists(created_path):
22       os.mkdir(created_path)
23     
24 # useful information about building dmgs
25 # http://developer.apple.com/documentation/Porting/Conceptual/PortingUnix
26 # http://developer.apple.com/documentation/developertools/Conceptual/SoftwareDistribution/Concepts/sd_disk_images.html
27
28 def makedmg(dirlist, volname):
29   # need to detect what the real volume name is
30   mussa_mount = '/Volumes/%s' %(volname)
31   mussarw_dmg = '%sw.dmg' %(volname)
32   mussa_dmg = '%s.dmg' %(volname)
33   system('hdiutil detach '+mussa_mount)
34   if os.path.exists(mussa_mount):
35     print >>sys.stderr, "Something is in", mussa_mount
36     return 
37   if os.path.exists(mussarw_dmg):
38     os.unlink(mussarw_dmg)
39   if os.path.exists(mussa_dmg):
40     os.unlink(mussa_dmg)
41   system('hdiutil create -size 64m -fs HFS+ -volname "%s" %s'%(volname, mussarw_dmg))
42   system('hdiutil attach '+mussarw_dmg)
43   # copy files
44   for d in dirlist:
45     copytree(d, os.path.join(mussa_mount, d))
46
47   system('hdiutil detach '+mussa_mount)
48   system('hdiutil convert '+mussarw_dmg +' -format UDZO -o '+mussa_dmg)
49   #system('hdiutil internet-enable -yes '+mussa_dmg)
50
51 def main(args):
52   framework_subpath = os.path.join("%(framework)s.framework", "Versions", "4.0", "%(framework)s")
53   frameworks = ['QtCore', 'QtGui', 'QtOpenGL']
54
55   qt_lib_dir="/usr/local/qt-4.1.1/lib"
56   qt_framework=os.path.join(qt_lib_dir, framework_subpath)
57
58   app_name="mussagl"
59   app_dir=app_name+".app"
60   app_binary=app_dir+"/Contents/MacOS/"+app_name
61   app_framework=os.path.join(app_dir, "Contents", "Frameworks", framework_subpath)
62   if not os.path.exists(app_dir):
63     print >>sys.stderr, "please build mussagl first"
64     return 1
65
66   # install frameworks and update binary
67   for frame in frameworks:
68     qtframe = qt_framework % ({'framework': frame})
69     appframe = app_framework % ({'framework': frame})
70     exe_path = "@executable_path/../Frameworks/" + framework_subpath
71     exe_path %= ({'framework': frame})
72     mkdir(os.path.split(appframe)[0])
73     # update binary
74     copy(qtframe, appframe)
75     system("install_name_tool -id "+exe_path+" "+appframe)
76     system("install_name_tool -change "+qtframe+" "+exe_path+" "+app_binary)
77     # now that everything is in place change the frameworks 
78     # references
79     for frame2 in frameworks:
80       qtframe2 = qt_framework % ({'framework': frame2})
81       contents_exe_path = "@executable_path/../Frameworks/" + framework_subpath
82       contents_exe_path %= ({'framework': frame2})
83       system("install_name_tool -change "+qtframe2+" "+contents_exe_path+" "+
84              appframe)
85   makedmg([app_dir], 'mussa')
86
87 if __name__ == "__main__":
88   main(sys.argv[1:])