fix capitalization of appname in osx build
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 # script for pulling together a MacOSX app bundle.
4
5 GTKQUARTZ_ROOT=$HOME/gtk/inst
6
7 SAE=
8 MIXBUS=
9 INTERNAL_JACK=1
10 WITH_LADSPA=1
11 STRIP=1
12 PRINT_SYSDEPS=
13 WITH_NLS=
14 EXTRA_PACKAGING_DIR==
15 EXTERNAL_JACK=
16
17 while [ $# -gt 0 ] ; do
18     echo "arg = $1"
19     case $1 in
20
21         #
22         # top level build targets
23         #
24
25         --sae) WITH_NLS= ; SAE=1 ; INTERNAL_JACK=1; WITH_LADSPA=1; STRIP= ; EXTRA_PACKAGING_DIR=1 ; shift ;;
26         --mixbus) MIXBUS=1; WITH_NLS= ; SAE= ; INTERNAL_JACK=; WITH_LADSPA=; STRIP= ; EXTRA_PACKAGING_DIR=1; EXTERNAL_JACK=/usr/local/Jack.dmg; shift ;;
27         --public) WITH_NLS= ; SAE= ; INTERNAL_JACK=; WITH_LADSPA=1; STRIP= ; shift ;;
28         --allinone) SAE= ; WITH_NLS= ; INTERNAL_JACK=1; WITH_LADSPA=1; STRIP= ; shift ;;
29         --test) SAE= ; INTERNAL_JACK=; WITH_LADSPA=; STRIP= ; shift ;;
30
31         #
32         # specific build flags
33         #
34
35         --nojack) INTERNAL_JACK= ; shift ;;
36         --noladspa) WITH_LADSPA= ; shift ;;
37         --nostrip) STRIP= ; shift ;;
38         --sysdeps) PRINT_SYSDEPS=1; shift ;;
39         --nls) WITH_NLS=1 ; shift ;;
40         --pdir) EXTRA_PACKAGING_DIR=1; shift ;;
41         --external_jack) EXTERNAL_JACK=$2; shift ; shift ;;
42     esac
43 done
44
45 if [ x$EXTERNAL_JACK != x -a x$INTERNAL_JACK != x ] ; then
46     echo "It makes no sense to package JACK internally and externally. Please pick one."
47 fi
48
49 release_version=`grep -m 1 '^ardour_version' ../../SConstruct | cut -d' ' -f 3 | sed "s/'//g"`
50 svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d' ' -f 6 | sed 's/[";]//g'`
51 echo "Version is $release_version / $svn_version"
52 info_string="$release_version/$svn_version built on `hostname` by `whoami` on `date`"
53 echo "Info string is $info_string"
54
55 # setup directory structure
56
57 if [ x$MIXBUS != x ] ; then
58     APPNAME=Mixbus
59 else
60     APPNAME=Ardour2
61 fi
62
63 APPDIR=${APPNAME}.app
64 APPROOT=$APPDIR/Contents
65 Frameworks=$APPROOT/Frameworks
66 Resources=$APPROOT/Resources
67 Plugins=$APPROOT/Plugins
68 Surfaces=$APPROOT/Surfaces
69 Shared=$Resources/share
70 Etc=$Resources/etc
71 Locale=$Resources/locale
72
73 SAE_PKG_DIR=ArdourSAE
74 MIXBUS_PKG_DIR=Mixbus
75
76 if [ x$PRINT_SYSDEPS != x ] ; then
77 #
78 # print system dependencies
79 #
80
81     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
82         if ! file $file | grep -qs Mach-O ; then
83             continue
84         fi
85         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
86     done | sort | uniq
87     exit 0
88 fi
89
90 echo "Removing old $APPDIR tree ..."
91
92 rm -rf $APPDIR
93
94 echo "Building new app directory structure ..."
95
96 # only bother to make the longest paths
97
98 mkdir -p $APPROOT/MacOS
99 mkdir -p $APPROOT/Resources
100 mkdir -p $APPROOT/Plugins
101 mkdir -p $APPROOT/Surfaces
102 mkdir -p $Frameworks/modules
103 mkdir -p $Shared/templates
104 mkdir -p $Etc
105
106 # maybe set variables
107 env=""
108 if test x$SAE != x ; then
109     appname="Ardour2/SAE"
110     env="$env<key>ARDOUR_SAE</key><string>true</string>"
111     #
112     # current default for SAE version is German keyboard layout without a keypad
113     #
114     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de-nokeypad</string>"
115     env="$env<key>ARDOUR_UI_CONF</key><string>ardour2_ui_sae.conf</string>"
116     env="$env<key>ARDOUR2_UI_RC</key><string>ardour2_ui_dark_sae.rc</string>"
117 elif test x$MIXBUS != x ; then
118     appname="Ardour2/Mixbus"
119     env="$env<key>ARDOUR_MIXBUS</key><string>true</string>"
120     #
121     # current default for MIXBUS version is US keyboard layout without a keypad
122     #
123     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>us-nokeypad</string>"
124     env="$env<key>ARDOUR_UI_CONF</key><string>ardour2_ui.conf</string>"
125     env="$env<key>ARDOUR2_UI_RC</key><string>ardour2_ui_dark.rc</string>"
126 else
127     appname="Ardour2"
128 fi
129
130 #
131 # if we're not going to bundle JACK, make sure we can find
132 # jack in the places where it might be
133 #
134
135 if test x$INTERNAL_JACK != x ; then
136     env="$env<key>ARDOUR_INTERNAL_JACK</key><string>true</string>"
137 else
138     env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin</string>"
139     env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
140 fi
141
142 env="<key>LSEnvironment</key><dict><key>ARDOUR_BUNDLED</key><string>true</string>$env</dict>"
143
144 # edit plist
145 sed -e "s?@ENV@?$env?g" \
146     -e "s?@VERSION@?$release_version/$svn_version?g" \
147     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
148 # and plist strings
149 sed -e "s?@APPNAME@?$appname?" \
150     -e "s?@ENV@?$env?g" \
151     -e "s?@VERSION@?$release_version/$svn_version?g" \
152     -e "s?@INFOSTRING@?$info_string?g" < InfoPlist.strings.in > Resources/InfoPlist.strings
153
154 # copy static files
155
156 cp Info.plist $APPROOT
157 cp -R Resources $APPROOT
158
159 #
160 # if we build a bundle without jack, then
161 # make the Ardour2 executable a helper
162 # script that checks to see if JACK is
163 # installed.
164 #
165
166 if test x$INTERNAL_JACK != x ; then
167     MAIN_EXECUTABLE=Ardour2
168 else
169     cp startup_script $APPROOT/MacOS/Ardour2
170     chmod 775 $APPROOT/MacOS/Ardour2
171     MAIN_EXECUTABLE=Ardour2.bin
172 fi
173
174 echo "Copying ardour executable ...."
175 cp ../../gtk2_ardour/ardour-$release_version $APPROOT/MacOS/$MAIN_EXECUTABLE
176 if test x$SAE != x ; then
177     # cp ../../gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
178     cp  Ardour2-SAE.icns $Resources/appIcon.icns
179 elif test x$MIXBUS != x ; then
180     cp  Mixbus.icns $Resources/appIcon.icns
181 else
182     cp  Ardour2.icns $Resources/appIcon.icns
183 fi
184 if test x$STRIP != x ; then
185     strip $APPROOT/MacOS/Ardour2
186 fi
187 if test x$INTERNAL_JACK != x ; then
188     if [ -f /usr/local/lib/jack/jack_coreaudio.so ] ; then 
189         cp /usr/local/lib/jack/jack_coreaudio.so $Frameworks
190         cp /usr/local/bin/jackd $APPROOT/MacOS
191         JACK_SHARED_OBJECTS="$Frameworks/*.so"
192     fi
193 fi
194
195 # copy locale files
196 if test x$WITH_NLS != x ; then
197     echo "NLS support ..."
198     for file in ../../gtk2_ardour/*.mo
199     do
200         lang=`basename $file | sed 's/\.mo//'`
201         mkdir -p $Locale/$lang/LC_MESSAGES
202         cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
203     done
204 else
205     echo "Skipping NLS support"
206 fi
207
208 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
209 echo "Copying all Pango modules ..."
210 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
211 echo "Copying all GDK Pixbuf loaders ..."
212 cp -R $GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/*.so $Frameworks/modules
213 # charset alias file
214 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
215
216 pwd=`pwd`
217
218 if test x$WITH_LADSPA != x ; then
219     if test x$SAE != x ; then
220         plugdir=sae_ladspa
221     elif test x$MIXBUS != x ; then
222         plugdir=mixbus_ladspa
223     else
224         plugdir=ladspa
225     fi
226     echo "Copying `ls $plugdir | wc -l` plugins ..."
227     cp -r $plugdir/* $Plugins
228 fi
229
230 # generate new Pango module file
231 cat > pangorc <<EOF 
232 [Pango]
233 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
234 EOF
235 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
236 rm pangorc
237
238 # generate a new GDK pixbufs loaders file
239 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
240
241 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
242 cp ../../libs/clearlooks-newer/libclearlooks.dylib $Frameworks
243 mkdir -p $Frameworks/clearlooks/engines
244 (cd $Frameworks/clearlooks/engines && ln -s ../../libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
245
246 # XXX STILL NEED TO DO PANNERS FOR TRUNK
247 cp ../../libs/surfaces/*/libardour_*.dylib $Surfaces
248 # hack ... move libardour_cp back into Frameworks
249 mv $Surfaces/libardour_cp.dylib $Frameworks
250
251 # VAMP plugins that we use
252 cp ../../libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
253
254 while [ true ] ; do 
255     missing=false
256     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
257         if ! file $file | grep -qs Mach-O ; then
258             continue
259         fi
260         if test x$INTERNAL_JACK != x ; then
261             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)"`
262         else
263             # do not include libjack
264             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | grep -v 'libjack\.'`
265         fi
266         echo -n "."
267         for dep in $deps ; do
268             base=`basename $dep`
269             if ! test -f $Frameworks/$base; then
270                 if echo $dep | grep -sq '^libs' ; then
271                     cp ../../$dep $Frameworks
272                 else
273                     cp $dep $Frameworks
274                 fi
275                 missing=true
276             fi
277         done
278     done
279     if test x$missing = xfalse ; then
280         # everything has been found
281         break
282     fi
283 done
284 echo
285
286 echo "Copying other stuff to $APPDIR  ..."
287
288 cp ../../gtk2_ardour/ergonomic-us.bindings  $Resources
289 cp ../../gtk2_ardour/mnemonic-us.bindings  $Resources
290 cp ../../gtk2_ardour/SAE-de-keypad.bindings  $Resources
291 cp ../../gtk2_ardour/SAE-de-nokeypad.bindings  $Resources
292 cp ../../gtk2_ardour/SAE-us-keypad.bindings  $Resources
293 cp ../../gtk2_ardour/SAE-us-nokeypad.bindings  $Resources
294 cp ../../gtk2_ardour/ardour.menus $Resources
295 cp ../../gtk2_ardour/ardour-sae.menus $Resources
296 if test x$SAE != x ; then
297     cp ../../ardour_system_sae.rc $Resources/ardour_system.rc
298     echo cp ../../ardour_system_sae.rc $Resources/ardour_system.rc
299     cp ../../instant.xml.sae $Resources/instant.xml
300     echo cp ../../instant.xml.sae $Resources/instant.xml
301 else
302 #    cp ../../ardour_system.rc $Resources/ardour_system.rc
303 #    echo FOO cp ../../ardour_system.rc $Resources/ardour_system.rc
304     cp ../../instant.xml $Resources/instant.xml
305     echo cp ../../instant.xml $Resources/instant.xml
306 fi
307 cp ../../gtk2_ardour/ardour2_ui_sae.conf $Resources
308 cp ../../gtk2_ardour/ardour2_ui_default.conf $Resources
309 cp ../../gtk2_ardour/ardour2_ui_light.rc $Resources
310 cp ../../gtk2_ardour/ardour2_ui_dark.rc $Resources
311 cp ../../gtk2_ardour/ardour2_ui_light_sae.rc $Resources
312 cp ../../gtk2_ardour/ardour2_ui_dark_sae.rc $Resources
313
314 cp -r ../../gtk2_ardour/icons $Resources
315 cp -r ../../gtk2_ardour/pixmaps $Resources
316
317 #
318 # put sooper sekrit ingredients here and they will be copied
319 #
320
321 if [ -d specialSauce ] ; then
322     cp -r specialSauce $Resources
323 fi
324
325 # share stuff
326
327 cp -R ../../gtk2_ardour/splash.png $Shared
328 cp ../../templates/*.template $Shared/templates/
329
330 # go through and recursively remove any .svn dirs in the bundle
331 for svndir in `find $APPDIR -name .svn -type dir`; do
332     rm -rf $svndir
333 done
334
335 # now fix up the executables
336 echo "Fixing up executable dependency names ..."
337 executables=$MAIN_EXECUTABLE
338 if test x$INTERNAL_JACK != x ; then
339     executables="$executables jackd"
340 fi
341 if test x$SAE != x ; then
342     executables="$executables"
343 fi
344
345 for exe in $executables; do
346     EXE=$APPROOT/MacOS/$exe
347     changes=""
348     if test x$INTERNAL_JACK != x ; then
349         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}'` ; do
350             base=`basename $lib`
351             changes="$changes -change $lib @executable_path/../Frameworks/$base"
352         done
353     else
354         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
355             base=`basename $lib`
356             changes="$changes -change $lib @executable_path/../Frameworks/$base"
357         done
358     fi
359     if test "x$changes" != "x" ; then
360         install_name_tool $changes $EXE
361     fi
362 done
363
364 echo "Fixing up library names ..."
365 # now do the same for all the libraries we include
366 for dylib in $JACK_SHARED_OBJECTS $Frameworks/*.dylib $Frameworks/modules/*.so $Surfaces/*.dylib ; do
367     # skip symlinks
368     if test ! -L $dylib ; then
369         
370         # change all the dependencies
371
372         changes=""
373         if test x$INTERNAL_JACK != x ; then
374             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}'` ; do
375                 base=`basename $lib`
376                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
377             done
378         else
379             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
380                 base=`basename $lib`
381                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
382             done
383         fi
384
385         if test "x$changes" != x ; then
386             if  install_name_tool $changes $dylib ; then
387                 :
388             else
389                 exit 1
390             fi
391         fi
392
393         # now the change what the library thinks its own name is
394
395         base=`basename $dylib`
396         install_name_tool -id @executable_path/../Frameworks/$base $dylib
397     fi
398 done
399
400 if [ x$EXTRA_PACKAGING_DIR != x ] ; then
401
402     if [ x$SAE != x ] ; then
403         
404         # SAE packaging
405
406         echo "Creating SAE packaging directory"
407         rm -rf $SAE_PKG_DIR
408         mkdir $SAE_PKG_DIR
409         mv $APPDIR $SAE_PKG_DIR/Ardour2-SAE.app
410         cp HowToInstallArdourSAE.pdf "$SAE_PKG_DIR/How To Install Ardour SAE.pdf"
411         cp SAE-de-keypad.pdf "$SAE_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
412         cp SAE-de-nokeypad.pdf "$SAE_PKG_DIR/Ardour SAE Shortcuts.pdf"
413
414     elif [ x$MIXBUS != x ] ; then
415
416         # Mixbus packaging
417
418         echo "Creating Mixbus packaging directory"
419         rm -rf $MIXBUS_PKG_DIR
420         mkdir $MIXBUS_PKG_DIR
421         mv $APPDIR $MIXBUS_PKG_DIR/
422         # cp HowToInstallArdourMIXBUS.pdf "$MIXBUS_PKG_DIR/How To Install Ardour MIXBUS.pdf"
423         
424         if [ -x$EXTERNAL_JACK != x ] ; then
425             cp $EXTERNAL_JACK $MIXBUS_PKG_DIR
426         fi
427
428     else 
429
430         echo "public packaging in an extra folder is not implemented yet"
431
432     fi
433 fi
434
435 echo "Done."
436