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