enable icon-start-from-.ardour-file to work on OS X; properly install apple event...
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 # script for pulling together a MacOSX app bundle.
4
5 GTKQUARTZ_ROOT=/opt/gtk
6
7 SAE=
8 WITH_JACK=1
9 WITH_LADSPA=1
10 STRIP=1
11 PRINT_SYSDEPS=
12
13 while [ $# -gt 0 ] ; do
14     echo "arg = $1"
15     case $1 in
16
17         #
18         # top level build targets
19         #
20
21         --sae) SAE=1 ; WITH_JACK=1; WITH_LADSPA=1; STRIP= ; shift ;;
22         --public) SAE= ; WITH_JACK=; WITH_LADSPA=1; STRIP= ; shift ;;
23         --allinone) SAE= ; WITH_JACK=1; WITH_LADSPA=1; STRIP= ; shift ;;
24         --test) SAE= ; WITH_JACK=; WITH_LADSPA=; STRIP= ; shift ;;
25
26         #
27         # specific build flags
28         #
29
30         --nojack) WITH_JACK= ; shift ;;
31         --noladspa) WITH_LADSPA= ; shift ;;
32         --nostrip) STRIP= ; shift ;;
33         --sysdeps) PRINT_SYSDEPS=1; shift ;;
34     esac
35 done
36
37 version=`grep -m 1 '^ardour_version' ../../SConstruct | cut -d' ' -f 3 | sed "s/'//g"`
38 echo "Version is $version"
39 info_string="$version built on `hostname` by `whoami` on `date`"
40 echo "Info string is $info_string"
41
42 # setup directory structure
43
44 APPROOT=Ardour2.app/Contents
45 Frameworks=$APPROOT/Frameworks
46 Resources=$APPROOT/Resources
47 Plugins=$APPROOT/Plugins
48 Surfaces=$APPROOT/Surfaces
49 Shared=$Resources/share
50 Etc=$Resources/etc
51
52 if [ x$PRINT_SYSDEPS != x ] ; then
53 #
54 # print system dependencies
55 #
56
57     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
58         if ! file $file | grep -qs Mach-O ; then
59             continue
60         fi
61         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
62     done | sort | uniq
63     exit 0
64 fi
65
66 echo "Removing old Ardour2.app tree ..."
67
68 rm -rf Ardour2.app
69
70 echo "Building new app directory structure ..."
71
72 # only bother to make the longest paths
73
74 mkdir -p $APPROOT/MacOS
75 mkdir -p $APPROOT/Resources
76 mkdir -p $APPROOT/Plugins
77 mkdir -p $APPROOT/Surfaces
78 mkdir -p $Frameworks/modules
79 mkdir -p $Shared/templates
80 mkdir -p $Etc
81
82 # maybe set variables
83 env=""
84 if test x$SAE != x ; then
85     env="$env<key>ARDOUR_SAE</key><string>true</string>"
86     #
87     # current default for SAE version is German keyboard layout
88     #
89     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de</string>"
90     env="$env<key>ARDOUR_UI_CONF</key><string>ardour2_ui_sae.conf</string>"
91 fi
92
93 #
94 # if we're not going to bundle JACK, make sure we can find
95 # jack in the places where it might be
96 #
97
98 if test x$WITH_JACK != x ; then
99     env="$env<key>ARDOUR_WITH_JACK</key><string>true</string>"
100 else
101     env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin</string>"
102     env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
103 fi
104
105 env="<key>LSEnvironment</key><dict><key>ARDOUR_BUNDLED</key><string>true</string>$env</dict>"
106
107 # edit plist
108 sed -e "s?@ENV@?$env?g" \
109     -e "s?@VERSION@?$version?g" \
110     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
111
112 # copy static files
113
114 cp Info.plist $APPROOT
115 cp -R Resources $APPROOT
116
117 echo "Copying ardour executable ...."
118 cp ../../gtk2_ardour/ardour-$version $APPROOT/MacOS/Ardour2
119 if test x$SAE != x ; then
120     cp ../../gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
121 fi
122 if test x$STRIP != x ; then
123     strip $APPROOT/MacOS/Ardour2
124 fi
125 if test x$WITH_JACK != x ; then
126     cp /usr/local/lib/jack/jack_coreaudio.so $Frameworks
127     cp /usr/local/bin/jackd $APPROOT/MacOS
128 fi
129
130 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
131 echo "Copying all Pango modules ..."
132 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
133 echo "Copying all GDK Pixbuf loaders ..."
134 cp -R $GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/*.so $Frameworks/modules
135 # charset alias file
136 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
137
138 pwd=`pwd`
139
140 if test x$WITH_LADSPA != x ; then
141     echo "Copying `ls ladspa | wc -l` plugins ..."
142     cp -r ladspa/* $Plugins
143 fi
144
145 # generate new Pango module file
146 cat > pangorc <<EOF 
147 [Pango]
148 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
149 EOF
150 env PANGO_RC_FILE=pangorc $GTKQUARTZ_ROOT/bin/pango-querymodules | sed "s?$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/?@executable_path/../Frameworks/modules/?" > $Resources/pango.modules
151 rm pangorc
152
153 # generate a new GDK pixbufs loaders file
154 sed "s?$GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/?@executable_path/../Frameworks/modules/?" < $GTKQUARTZ_ROOT/etc/gtk-2.0/gdk-pixbuf.loaders > $Resources/gdk-pixbuf.loaders
155
156 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
157 cp ../../libs/clearlooks/libclearlooks.dylib $Frameworks
158 mkdir -p $Frameworks/clearlooks/engines
159 (cd $Frameworks/clearlooks/engines && ln -s ../../libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
160
161 # XXX STILL NEED TO DO PANNERS FOR TRUNK
162 cp ../../libs/surfaces/*/libardour_*.dylib $Surfaces
163 # hack ... move libardour_cp back into Frameworks
164 mv $Surfaces/libardour_cp.dylib $Frameworks
165
166 # VAMP plugins that we use
167 cp ../../libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
168
169 while [ true ] ; do 
170     missing=false
171     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
172         if ! file $file | grep -qs Mach-O ; then
173             continue
174         fi
175         if test x$WITH_JACK != x ; then
176             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)"`
177         else
178             # do not include libjack
179             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | grep -v 'libjack\.'`
180         fi
181         echo -n "."
182         for dep in $deps ; do
183             base=`basename $dep`
184             if ! test -f $Frameworks/$base; then
185                 if echo $dep | grep -sq '^libs' ; then
186                     cp ../../$dep $Frameworks
187                 else
188                     cp $dep $Frameworks
189                 fi
190                 missing=true
191             fi
192         done
193     done
194     if test x$missing = xfalse ; then
195         # everything has been found
196         break
197     fi
198 done
199 echo
200
201 echo "Copying other stuff to Ardour2.app  ..."
202
203 cp ../../gtk2_ardour/ergonomic-us.bindings  $Resources
204 cp ../../gtk2_ardour/mnemonic-us.bindings  $Resources
205 cp ../../gtk2_ardour/SAE-de.bindings  $Resources
206 cp ../../gtk2_ardour/ardour.menus $Resources
207 cp ../../gtk2_ardour/ardour-sae.menus $Resources
208 if test x$SAE != x ; then
209     cp ../../ardour_system_sae.rc $Resources/ardour_system.rc
210     echo cp ../../ardour_system_sae.rc $Resources/ardour_system.rc
211 else
212     cp ../../ardour_system.rc $Resources/ardour_system.rc
213     echo FOO cp ../../ardour_system.rc $Resources/ardour_system.rc
214 fi
215 cp ../../gtk2_ardour/ardour2_ui_sae.conf $Resources
216 cp ../../gtk2_ardour/ardour2_ui_default.conf $Resources
217 cp ../../gtk2_ardour/ardour2_ui_light.rc $Resources
218 cp ../../gtk2_ardour/ardour2_ui_dark.rc $Resources
219
220 cp -r ../../gtk2_ardour/icons $Resources
221 cp -r ../../gtk2_ardour/pixmaps $Resources
222
223 # share stuff
224
225 cp -R ../../gtk2_ardour/splash.png $Shared
226 cp ../../templates/*.template $Shared/templates/
227
228 # go through and recursively remove any .svn dirs in the bundle
229 for svndir in `find Ardour2.app -name .svn -type dir`; do
230     rm -rf $svndir
231 done
232
233 # now fix up the executables
234 echo "Fixing up executable dependency names ..."
235 executables="Ardour2"
236 if test x$WITH_JACK != x ; then
237     executables="$executables jackd"
238 fi
239 if test x$SAE != x ; then
240     executables="$executables gtkevents"
241 fi
242
243 for exe in $executables; do
244     EXE=$APPROOT/MacOS/$exe
245     changes=""
246     if test x$WITH_JACK != x ; then
247         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
248             base=`basename $lib`
249             changes="$changes -change $lib @executable_path/../Frameworks/$base"
250         done
251     else
252         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
253             base=`basename $lib`
254             changes="$changes -change $lib @executable_path/../Frameworks/$base"
255         done
256     fi
257     if test "x$changes" != "x" ; then
258         install_name_tool $changes $EXE
259     fi
260 done
261
262 echo "Fixing up library names ..."
263 # now do the same for all the libraries we include
264 for dylib in $Frameworks/*.dylib $Frameworks/modules/*.so $Surfaces/*.dylib ; do
265     # skip symlinks
266     if test ! -L $dylib ; then
267         
268         # change all the dependencies
269
270         changes=""
271         if test x$WITH_JACK != x ; then
272             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
273                 base=`basename $lib`
274                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
275             done
276         else
277             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
278                 base=`basename $lib`
279                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
280             done
281         fi
282
283         if test "x$changes" != x ; then
284             if  install_name_tool $changes $dylib ; then
285                 :
286             else
287                 exit 1
288             fi
289         fi
290
291         # now the change what the library thinks its own name is
292
293         base=`basename $dylib`
294         install_name_tool -id @executable_path/../Frameworks/$base $dylib
295     fi
296 done
297
298 echo "Done."
299