updated osx icon. use ARDOUR_MODULE_PATH in osx exporter script. fixed control proto...
[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 '^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
57 odir = Dir.getwd
58 Dir.chdir("../..")
59
60 result = `otool -L gtk2_ardour/ardour.bin`
61 results = result.split("\n")
62 results.delete_at(0)
63
64 result =  `otool -L libs/ardour/libardour.dylib`
65 results = results + result.split("\n").slice(1,result.size-1)
66
67 result =  `otool -L libs/surfaces/*/*.dylib`
68 results = results + result.split("\n").slice(1,result.size-1)
69
70 results.uniq!
71
72 $stdout.print("Copying libs to #{libdir} ...\n");
73
74 results.each do |s|
75     s = s.split[0]
76     # exclude frameworks, system libraries, X11 libraries, and libjack.
77     unless s =~ /System|\/usr\/lib|\/usr\/X11R6|libjack|:$/ then
78         #$stdout.print("Copying #{s}\n")
79         `cp #{s} #{odir}/#{libdir}/`
80     end
81 end
82
83 # now do it again
84 result =  `otool -L #{odir}/#{libdir}/*.dylib`
85 results = result.split("\n")
86 results.uniq!
87 results.each do |s|
88     s = s.split[0]
89     # exclude frameworks, system libraries, X11 libraries, and libjack.
90     unless s =~ /System|\/usr\/lib|\/usr\/X11R6|libjack|:$/ then
91       sbase = File.basename(s)
92       targfile = "#{odir}/#{libdir}/#{sbase}"
93       #$stdout.print("Targ is : " + targfile + "\n")
94       if not File.exist?(targfile) then
95         #$stdout.print("2nd stage Copying #{s}\n")
96         `cp #{s} #{odir}/#{libdir}/`
97       end
98     end
99 end
100
101
102 Dir.chdir(odir)
103
104 # copy ardour.bin to bindir/ardour
105 $stdout.print("Copying bin to #{bindir} ...\n");
106
107 if File.exist?("../../gtk2_ardour/ardour.bin") then
108    `cp ../../gtk2_ardour/ardour.bin #{bindir}/ardour`
109 end
110
111 `cp ../../libs/surfaces/*/*.dylib #{libdir}/surfaces`
112 # remove the basenames from libdir that are in surfaces (copied earlier)
113 begin
114   Dir.foreach(libdir+"/surfaces") {|x| unless ( x[0] == 46 or x.include?("libardour_cp")) then File.delete(libdir + "/" +x) end}
115 rescue
116 end
117
118
119 # copy gtk and pango lib stuff
120 `cp -R /opt/local/lib/pango #{libdir}/`
121 `cp -R /opt/local/lib/gtk-2.0 #{libdir}/`
122
123 # use our clearlooks
124 `rm -f #{libdir}/gtk-2.0/2.*/engines/libclearlooks.*`
125 # must use .so for it to be found :/
126 `cp ../../libs/clearlooks/libclearlooks.dylib #{libdir}/gtk-2.0/2.10.0/engines/libclearlooks.so`
127
128
129 def lipo_platforms_recurse(src1, src2, target)
130
131   if not File.stat(src1).directory? then
132     # normal file, lets lipo them if it doesn't already exist there
133     isbin = `file #{src1}`.include?("Mach-O")
134     if (! File.exist?(target)) and isbin then
135       if File.exist?(src2) then
136         $stdout.print("Lipo'ing " + target + "\n")
137         `lipo -create -output #{target} #{src1} #{src2}`
138       else
139         # just copy it
140         $stdout.print("Copying " + src1 + "\n")
141         `cp #{src1} #{target}`
142       end
143     else
144       #$stdout.print("Skipping " + target + "\n")
145     end
146   else
147     # directory, recurse if necessary
148     if File.exist?(src2) then
149       # other dir exists, recurse
150       
151       # make targetdir if necessary
152       if not File.exist?(target) then
153         Dir.mkdir(target)
154       end
155       
156       Dir.foreach(src1) do |file| 
157         if file[0] != 46 then
158           src1file = src1 + '/' + file
159           src2file = src2 + '/' + file
160           targfile = target + '/' + file
161           lipo_platforms_recurse(src1file, src2file, targfile)
162         end
163       end
164     else
165       # just copy it recursively to target
166       $stdout.print("Copying dir " + src1 + "\n")
167       `cp -R #{src1} #{target}`
168     end
169   end
170 end
171
172 # lipo stuff together if both platforms libs and bins are here
173
174 if File.exist?(ppc_libdir) and File.exist?(i386_libdir) then
175   $stdout.print("\nBoth platforms in place, lipo'ing...\n");
176   `rm -rf lib/*`
177   lipo_platforms_recurse(ppc_libdir, i386_libdir, "lib")
178   lipo_platforms_recurse(i386_libdir, ppc_libdir, "lib")
179   lipo_platforms_recurse(i386_bindir+'/ardour', ppc_bindir+'/ardour', "bin/ardour")
180
181   # remove existing Ardour2.app
182   `rm -rf Ardour2.app`
183
184   $stdout.print("\nRunning Playtpus to create Ardour2.app  ...\n");
185
186   `/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'`
187
188   $stdout.print("\nCopying other stuff to Ardour2.app  ...\n");
189
190   if not File.exist?("Ardour2.app/Contents/Resources/etc") then
191     Dir.mkdir "Ardour2.app/Contents/Resources/etc" 
192   end
193
194   if not File.exist?("Ardour2.app/Contents/Resources/etc/ardour2") then
195     Dir.mkdir "Ardour2.app/Contents/Resources/etc/ardour2" 
196   end
197   `cp ../../gtk2_ardour/ardour.bindings ../../gtk2_ardour/ardour.colors ../../gtk2_ardour/ardour.menus Ardour2.app/Contents/Resources/etc/ardour2/`
198   `cp ../../ardour.rc ../../ardour_system.rc Ardour2.app/Contents/Resources/etc/ardour2/`
199   `cp ardour2_mac_ui.rc Ardour2.app/Contents/Resources/etc/ardour2/ardour2_ui.rc`
200
201   # copy other etc stuff
202   if not File.exist?("Ardour2.app/Contents/Resources/etc/gtk-2.0") then
203     `cp -R etc/gtk-2.0 Ardour2.app/Contents/Resources/etc/`
204   end
205   if not File.exist?("Ardour2.app/Contents/Resources/etc/pango") then
206     `cp -R etc/pango Ardour2.app/Contents/Resources/etc/`
207   end
208   if not File.exist?("Ardour2.app/Contents/Resources/etc/fonts") then
209     `cp -R /opt/local/etc/fonts Ardour2.app/Contents/Resources/etc/`
210   end
211
212   if not File.exist?("Ardour2.app/Contents/Resources/etc/profile.d") then
213     `cp -R etc/profile.d Ardour2.app/Contents/Resources/etc/`
214   end
215
216   # share stuff
217
218   if not File.exist?("Ardour2.app/Contents/Resources/share") then
219     Dir.mkdir "Ardour2.app/Contents/Resources/share"
220   end
221
222   if not File.exist?("Ardour2.app/Contents/Resources/share/ardour2") then
223     Dir.mkdir "Ardour2.app/Contents/Resources/share/ardour2"
224     Dir.mkdir "Ardour2.app/Contents/Resources/share/ardour2/templates"
225     `cp -R  ../../gtk2_ardour/icons ../../gtk2_ardour/pixmaps ../../gtk2_ardour/splash.png Ardour2.app/Contents/Resources/share/ardour2/`
226     `cp ../../templates/*.template Ardour2.app/Contents/Resources/share/ardour2/templates/` 
227   end
228
229   # go through and recursively remove any .svn dirs in the bundle
230   svndirs = `find Ardour2.app -name .svn -type dir`.split("\n")
231   svndirs.each do |svndir|
232     `rm -rf #{svndir}`
233   end
234
235   # make DMG
236   `rm -rf macdist`
237   Dir.mkdir("macdist")
238   `cp -r README.rtf COPYING Ardour2.app macdist/`
239   dmgname = "Ardour-#{version}"
240   `rm -f #{dmgname}.dmg`
241   $stdout.print("\nCreating DMG\n")
242   `hdiutil create -fs HFS+ -volname #{dmgname} -srcfolder macdist #{dmgname}.dmg`
243
244
245   $stdout.print("\nDone\n")
246
247 else
248   # zip up libdir and bindir
249   zipfile = "binlib_"+`uname -p`.strip() + ".zip" 
250   $stdout.print("Zipping up #{libdir} and #{bindir} into #{zipfile}...\n")
251   `zip -rq #{zipfile} #{libdir} #{bindir}`
252   $stdout.print("Copy #{zipfile} to other platform's osx_packaging dir and run app_build.rb\nthere to complete universal build.\n")
253
254
255 end
256
257