443b287c28c884ba62fdd7c079b1b0c5c058cd0b
[ardour.git] / tools / osx_packaging / app_build.rb
1 #!/usr/bin/env ruby
2
3 # Ruby script for pulling together a MacOSX app bundle.
4
5 # it will be either powerpc or i386
6 version = "beta9"
7 arch = `uname -p`.strip()
8 libdir = "lib_" + arch
9 bindir = "bin_" + arch
10
11 ppc_libdir = "lib_powerpc"
12 i386_libdir = "lib_i386"
13 ppc_bindir = "bin_powerpc"
14 i386_bindir = "bin_i386"
15 ppc_binlib = "binlib_powerpc.zip"
16 i386_binlib = "binlib_i386.zip"
17
18 #$stdout.print("libdir is '" + libdir + "'\n")
19
20 # check for the other arch's libbin.zip
21 if arch == "i386" then
22   zipfile = ppc_binlib
23   `rm -rf #{ppc_libdir} #{ppc_bindir}`
24 else
25   zipfile = i386_binlib
26   `rm -rf #{i386_libdir} #{i386_bindir}`
27 end
28
29 if File.exist?(zipfile) then
30   $stdout.print("Found #{zipfile} : unpacking...\n")
31   `unzip -aq #{zipfile}`
32 end
33
34
35 if File.exist?(libdir) then
36   # remove it
37   `rm -rf #{libdir}/*`
38   #Dir.foreach(libdir) {|x| unless ( x[0] == 46 or File.stat(libdir+"/"+x).directory?) then File.delete(libdir + "/" +x) end}
39 else
40     Dir.mkdir libdir
41 end
42
43 if File.exist?(bindir) then
44     Dir.foreach(bindir) {|x| unless x[0] == 46 then File.delete(bindir + "/" +x) end}
45 else
46     Dir.mkdir bindir
47 end
48
49 if not File.exist?(libdir+"/surfaces") then
50    Dir.mkdir(libdir + "/surfaces")
51 end
52
53
54 odir = Dir.getwd
55 Dir.chdir("../..")
56
57 result = `otool -L gtk2_ardour/ardour.bin`
58 results = result.split("\n")
59 results.delete_at(0)
60
61 result =  `otool -L libs/ardour/libardour.dylib`
62 results = results + result.split("\n").slice(1,result.size-1)
63
64 result =  `otool -L libs/surfaces/*/*.dylib`
65 results = results + result.split("\n").slice(1,result.size-1)
66
67 results.uniq!
68
69 $stdout.print("Copying libs to #{libdir} ...\n");
70
71 results.each do |s|
72     s = s.split[0]
73     # exclude frameworks, system libraries, X11 libraries, and libjack.
74     unless s =~ /System|\/usr\/lib|\/usr\/X11R6|libjack|:$/ then
75         #$stdout.print("Copying #{s}\n")
76         `cp #{s} #{odir}/#{libdir}/`
77     end
78 end
79
80 # now do it again
81 result =  `otool -L #{odir}/#{libdir}/*.dylib`
82 results = result.split("\n")
83 results.uniq!
84 results.each do |s|
85     s = s.split[0]
86     # exclude frameworks, system libraries, X11 libraries, and libjack.
87     unless s =~ /System|\/usr\/lib|\/usr\/X11R6|libjack|:$/ then
88       sbase = File.basename(s)
89       targfile = "#{odir}/#{libdir}/#{sbase}"
90       #$stdout.print("Targ is : " + targfile + "\n")
91       if not File.exist?(targfile) then
92         #$stdout.print("2nd stage Copying #{s}\n")
93         `cp #{s} #{odir}/#{libdir}/`
94       end
95     end
96 end
97
98
99 Dir.chdir(odir)
100
101 # copy ardour.bin to bindir/ardour
102 $stdout.print("Copying bin to #{bindir} ...\n");
103
104 if File.exist?("../../gtk2_ardour/ardour.bin") then
105    `cp ../../gtk2_ardour/ardour.bin #{bindir}/ardour`
106 end
107
108 `cp ../../libs/surfaces/*/*.dylib #{libdir}/surfaces`
109 # remove the basenames from libdir that are in surfaces (copied earlier)
110 begin
111   Dir.foreach(libdir+"/surfaces") {|x| unless ( x[0] == 46 or x.include?("libardour_cp")) then File.delete(libdir + "/" +x) end}
112 rescue
113 end
114
115
116 # copy gtk and pango lib stuff
117 `cp -R /opt/local/lib/pango #{libdir}/`
118 `cp -R /opt/local/lib/gtk-2.0 #{libdir}/`
119
120 # use our clearlooks
121 `rm -f #{libdir}/gtk-2.0/2.*/engines/libclearlooks.*`
122 # must use .so for it to be found :/
123 `cp ../../libs/clearlooks/libclearlooks.dylib #{libdir}/gtk-2.0/2.10.0/engines/libclearlooks.so`
124
125
126 def lipo_platforms_recurse(src1, src2, target)
127
128   if not File.stat(src1).directory? then
129     # normal file, lets lipo them if it doesn't already exist there
130     isbin = `file #{src1}`.include?("Mach-O")
131     if (! File.exist?(target)) and isbin then
132       if File.exist?(src2) then
133         $stdout.print("Lipo'ing " + target + "\n")
134         `lipo -create -output #{target} #{src1} #{src2}`
135       else
136         # just copy it
137         $stdout.print("Copying " + src1 + "\n")
138         `cp #{src1} #{target}`
139       end
140     else
141       #$stdout.print("Skipping " + target + "\n")
142     end
143   else
144     # directory, recurse if necessary
145     if File.exist?(src2) then
146       # other dir exists, recurse
147       
148       # make targetdir if necessary
149       if not File.exist?(target) then
150         Dir.mkdir(target)
151       end
152       
153       Dir.foreach(src1) do |file| 
154         if file[0] != 46 then
155           src1file = src1 + '/' + file
156           src2file = src2 + '/' + file
157           targfile = target + '/' + file
158           lipo_platforms_recurse(src1file, src2file, targfile)
159         end
160       end
161     else
162       # just copy it recursively to target
163       $stdout.print("Copying dir " + src1 + "\n")
164       `cp -R #{src1} #{target}`
165     end
166   end
167 end
168
169 # lipo stuff together if both platforms libs and bins are here
170
171 if File.exist?(ppc_libdir) and File.exist?(i386_libdir) then
172   $stdout.print("\nBoth platforms in place, lipo'ing...\n");
173   `rm -rf lib/*`
174   lipo_platforms_recurse(ppc_libdir, i386_libdir, "lib")
175   lipo_platforms_recurse(i386_libdir, ppc_libdir, "lib")
176   lipo_platforms_recurse(i386_bindir+'/ardour', ppc_bindir+'/ardour', "bin/ardour")
177
178   # remove existing Ardour2.app
179   `rm -rf Ardour2.app`
180
181   $stdout.print("\nRunning Playtpus to create Ardour2.app  ...\n");
182
183   `/usr/local/bin/platypus -D -X 'ardour' -a 'Ardour2' -t 'shell' -o 'None' -u 'Paul Davis' -i '/bin/sh' -V '2.0' -s 'ArDr' -I 'org.ardour.Ardour2' -f 'bin' -f 'lib' -i 'Ardour2.icns' -f 'MenuBar.nib' -f 'ProgressWindow.nib' -f 'init' -f 'openDoc' 'script' 'Ardour2.app'`
184
185   $stdout.print("\nCopying other stuff to Ardour2.app  ...\n");
186
187   if not File.exist?("Ardour2.app/Contents/Resources/etc") then
188     Dir.mkdir "Ardour2.app/Contents/Resources/etc" 
189   end
190
191   if not File.exist?("Ardour2.app/Contents/Resources/etc/ardour2") then
192     Dir.mkdir "Ardour2.app/Contents/Resources/etc/ardour2" 
193   end
194   `cp ../../gtk2_ardour/ardour.bindings ../../gtk2_ardour/ardour.colors ../../gtk2_ardour/ardour.menus Ardour2.app/Contents/Resources/etc/ardour2/`
195   `cp ../../ardour.rc ../../ardour_system.rc Ardour2.app/Contents/Resources/etc/ardour2/`
196   `cp ardour2_mac_ui.rc Ardour2.app/Contents/Resources/etc/ardour2/ardour2_ui.rc`
197
198   # copy other etc stuff
199   if not File.exist?("Ardour2.app/Contents/Resources/etc/gtk-2.0") then
200     `cp -R etc/gtk-2.0 Ardour2.app/Contents/Resources/etc/`
201   end
202   if not File.exist?("Ardour2.app/Contents/Resources/etc/pango") then
203     `cp -R etc/pango Ardour2.app/Contents/Resources/etc/`
204   end
205   if not File.exist?("Ardour2.app/Contents/Resources/etc/fonts") then
206     `cp -R /opt/local/etc/fonts Ardour2.app/Contents/Resources/etc/`
207   end
208
209   if not File.exist?("Ardour2.app/Contents/Resources/etc/profile.d") then
210     `cp -R etc/profile.d Ardour2.app/Contents/Resources/etc/`
211   end
212
213   # share stuff
214
215   if not File.exist?("Ardour2.app/Contents/Resources/share") then
216     Dir.mkdir "Ardour2.app/Contents/Resources/share"
217   end
218
219   if not File.exist?("Ardour2.app/Contents/Resources/share/ardour2") then
220     Dir.mkdir "Ardour2.app/Contents/Resources/share/ardour2"
221     Dir.mkdir "Ardour2.app/Contents/Resources/share/ardour2/templates"
222     `cp -R  ../../gtk2_ardour/icons ../../gtk2_ardour/pixmaps ../../gtk2_ardour/splash.png Ardour2.app/Contents/Resources/share/ardour2/`
223     `cp ../../templates/*.template Ardour2.app/Contents/Resources/share/ardour2/templates/` 
224   end
225
226   # go through and recursively remove any .svn dirs in the bundle
227   svndirs = `find Ardour2.app -name .svn -type dir`.split("\n")
228   svndirs.each do |svndir|
229     `rm -rf #{svndir}`
230   end
231
232   # make DMG
233   `rm -rf macdist`
234   Dir.mkdir("macdist")
235   `cp -r README.rtf COPYING Ardour2.app macdist/`
236   dmgname = "Ardour2-#{version}"
237   `rm -f #{dmgname}.dmg`
238   $stdout.print("\nCreating DMG\n")
239   `hdiutil create -fs HFS+ -volname #{dmgname} -srcfolder macdist #{dmgname}.dmg`
240
241
242   $stdout.print("\nDone\n")
243
244 else
245   # zip up libdir and bindir
246   zipfile = "binlib_"+`uname -p`.strip() + ".zip" 
247   $stdout.print("\nZipping up #{libdir} and #{bindir} into #{zipfile}\n")
248   $stdout.print("Copy #{zipfile} to other platform's osx_packaging dir and run app_build.rb\nthere to complete universal build.\n")
249   `zip -rq #{zipfile} #{libdir} #{bindir}`
250
251 end
252
253