OSX packaging tweaks
[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 if pkg-config --modversion gtk+-2.0 | grep -s 2.22 ; then
8     # older GTK
9     GDKPIXBUF_LOADERS=$GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders
10     echo 
11     echo
12     echo "*****************************************************"
13     echo "You are building with the OLD GTK stack. I hope that is ok"
14     echo "*****************************************************"
15     echo
16     echo
17 else
18     # newer GTK
19     GDKPIXBUF_LOADERS=$GTKQUARTZ_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders
20     echo 
21     echo
22     echo "*****************************************************"
23     echo "You are building with the NEW GTK stack. I hope that is ok"
24     echo "*****************************************************"
25     echo
26     echo
27 fi
28
29 SAE=
30 MIXBUS=
31 INTERNAL_JACK=1
32 WITH_LADSPA=1
33 STRIP=1
34 PRINT_SYSDEPS=
35 WITH_NLS=
36 EXTERNAL_JACK=
37
38 while [ $# -gt 0 ] ; do
39     echo "arg = $1"
40     case $1 in
41
42         #
43         # top level build targets
44         #
45
46         --sae) WITH_NLS= ; 
47                SAE=1 ; 
48                INTERNAL_JACK=1; 
49                WITH_LADSPA=1; 
50                STRIP= ; 
51                PRODUCT_PKG_DIR=ArdourSAE ; 
52                APPNAME=Ardour ;
53                shift ;;
54         --mixbus) MIXBUS=1; 
55                   WITH_NLS=1 ; 
56                   SAE= ; 
57                   INTERNAL_JACK=; 
58                   WITH_LADSPA=; 
59                   STRIP= ; 
60                   PRODUCT_PKG_DIR=MixBus;
61                   APPNAME=Mixbus ;
62                   shift ;;
63         --public) WITH_NLS= ; 
64                   SAE= ; 
65                   INTERNAL_JACK=; 
66                   WITH_LADSPA=1; 
67                   STRIP= ; 
68                   PRODUCT_PKG_DIR=Ardour;
69                   APPNAME=Ardour ;
70                   shift ;;
71         --allinone) SAE= ; 
72                     WITH_NLS= ; 
73                     INTERNAL_JACK=1; 
74                     WITH_LADSPA=1; 
75                     STRIP= ; 
76                     PRODUCT_PKG_DIR=Ardour ;
77                     shift ;;
78         --test) SAE= ; INTERNAL_JACK=; WITH_LADSPA=; STRIP= ; shift ;;
79
80         #
81         # specific build flags
82         #
83
84         --nojack) INTERNAL_JACK= ; shift ;;
85         --noladspa) WITH_LADSPA= ; shift ;;
86         --nostrip) STRIP= ; shift ;;
87         --sysdeps) PRINT_SYSDEPS=1; shift ;;
88         --nls) WITH_NLS=1 ; shift ;;
89         --external_jack) EXTERNAL_JACK=$2; shift ; shift ;;
90     esac
91 done
92
93 if [ x$EXTERNAL_JACK != x -a x$INTERNAL_JACK != x ] ; then
94     echo "It makes no sense to package JACK internally and externally. Please pick one."
95 fi
96
97 BUILD_ROOT=../../build
98
99 #release_version=`grep -m 1 '^VERSION' ../../wscript | cut -d' ' -f 3 | sed "s/'//g"`
100 release_version=3.0
101 svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d' ' -f 8 | sed 's/[^0-9]//g'`
102 echo "Version is $release_version / $svn_version"
103 info_string="$release_version/$svn_version built on `hostname` by `whoami` on `date`"
104 echo "Info string is $info_string"
105
106 # setup directory structure
107
108 APPDIR=${APPNAME}.app
109 APPROOT=$APPDIR/Contents
110 Frameworks=$APPROOT/Frameworks
111 Resources=$APPROOT/Resources
112 Plugins=$APPROOT/Plugins
113 Surfaces=$APPROOT/Surfaces
114 Panners=$APPROOT/Panners
115 MidiMaps=$APPROOT/MidiMaps
116 ExportFormats=$APPROOT/ExportFormats
117 Templates=$APPROOT/Templates
118 Shared=$Resources/share
119 Etc=$Resources/etc
120 Locale=$Resources/locale
121
122 if [ x$PRINT_SYSDEPS != x ] ; then
123 #
124 # print system dependencies
125 #
126
127     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
128         if ! file $file | grep -qs Mach-O ; then
129             continue
130         fi
131         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
132     done | sort | uniq
133     exit 0
134 fi
135
136 echo "Removing old $APPDIR tree ..."
137
138 rm -rf $APPDIR
139
140 echo "Building new app directory structure ..."
141
142 # only bother to make the longest paths
143
144 mkdir -p $APPROOT/MacOS
145 mkdir -p $APPROOT/Resources
146 mkdir -p $Plugins
147 mkdir -p $Surfaces
148 mkdir -p $Panners
149 mkdir -p $MidiMaps
150 mkdir -p $ExportFormats
151 mkdir -p $Templates
152 mkdir -p $Frameworks/modules
153 mkdir -p $Shared/templates
154 mkdir -p $Etc
155
156 # maybe set variables
157 env=""
158 if test x$SAE != x ; then
159     appname="Ardour3/SAE"
160     env="$env<key>ARDOUR_SAE</key><string>true</string>"
161     #
162     # current default for SAE version is German keyboard layout without a keypad
163     #
164     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de-nokeypad</string>"
165     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui_sae.conf</string>"
166     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark_sae.rc</string>"
167 elif test x$MIXBUS != x ; then
168     appname="Ardour3/Mixbus"
169     env="$env<key>ARDOUR_MIXBUS</key><string>true</string>"
170     #
171     # current default for MIXBUS version is US keyboard layout without a keypad
172     #
173     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>us-nokeypad</string>"
174     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui.conf</string>"
175     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark.rc</string>"
176 else
177     appname="Ardour3"
178 fi
179
180 #
181 # if we're not going to bundle JACK, make sure we can find
182 # jack in the places where it might be
183 #
184
185 if test x$INTERNAL_JACK != x ; then
186     env="$env<key>ARDOUR_INTERNAL_JACK</key><string>true</string>"
187 else
188     env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>"
189     env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
190 fi
191
192 env="<key>LSEnvironment</key><dict>$env<key>ARDOUR_BUNDLED</key><string>true</string></dict>"
193
194 # edit plist
195 sed -e "s?@ENV@?$env?g" \
196     -e "s?@VERSION@?$release_version/$svn_version?g" \
197     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
198 # and plist strings
199 sed -e "s?@APPNAME@?$appname?" \
200     -e "s?@ENV@?$env?g" \
201     -e "s?@VERSION@?$release_version/$svn_version?g" \
202     -e "s?@INFOSTRING@?$info_string?g" < InfoPlist.strings.in > Resources/InfoPlist.strings || exit 1
203
204 # copy static files
205
206 cp Info.plist $APPROOT
207 cp -R Resources $APPROOT
208
209 #
210 # if we build a bundle without jack, then
211 # make the Ardour3 executable a helper
212 # script that checks to see if JACK is
213 # installed.
214 #
215
216 if test x$INTERNAL_JACK != x ; then
217     MAIN_EXECUTABLE=Ardour3
218 else
219     cp startup_script $APPROOT/MacOS/Ardour3
220     chmod 775 $APPROOT/MacOS/Ardour3
221     MAIN_EXECUTABLE=Ardour3.bin
222 fi
223
224 echo "Copying ardour executable ...."
225 cp $BUILD_ROOT/gtk2_ardour/ardour-$release_version $APPROOT/MacOS/$MAIN_EXECUTABLE
226 if test x$SAE != x ; then
227     # cp $BUILD_ROOT/gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
228     cp  Ardour3-SAE.icns $Resources/appIcon.icns
229 elif test x$MIXBUS != x ; then
230     cp  Mixbus.icns $Resources/appIcon.icns
231 else
232     cp  Ardour3.icns $Resources/appIcon.icns
233 fi
234 cp  typeArdour.icns $Resources/
235 if test x$STRIP != x ; then
236     strip $APPROOT/MacOS/Ardour3
237 fi
238 if test x$INTERNAL_JACK != x ; then
239     if [ -f /usr/local/lib/jack/jack_coreaudio.so ] ; then 
240         cp /usr/local/lib/jack/jack_coreaudio.so $Frameworks
241         cp /usr/local/bin/jackd $APPROOT/MacOS
242         JACK_SHARED_OBJECTS="$Frameworks/*.so"
243     fi
244 fi
245
246 # copy locale files
247 if test x$WITH_NLS != x ; then
248     echo "NLS support ..."
249     echo "I hope you remembered to run scons msgupdate!"
250     LINGUAS=
251     for file in $BUILD_ROOT/gtk2_ardour/*.mo 
252     do
253         lang=`basename $file | sed 's/\.mo//'`
254         mkdir -p $Locale/$lang/LC_MESSAGES
255         cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
256         LINGUAS="$LINGUAS $lang"
257     done
258     for file in $BUILD_ROOT/libs/ardour/*.mo 
259     do
260         lang=`basename $file | sed 's/\.mo//'`
261         mkdir -p $Locale/$lang/LC_MESSAGES
262         cp $file $Locale/$lang/LC_MESSAGES/libardour.mo
263     done
264     for l in $LINGUAS
265     do
266       if [ -d $GTKQUARTZ_ROOT/share/locale/$l ] ; then
267           echo "Copying GTK i18n files for $l..."
268           cp -r $GTKQUARTZ_ROOT/share/locale/$l $Locale
269       else
270           # try with just the language spec
271           just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
272           if [ -d $GTKQUARTZ_ROOT/share/locale/$just_lang ] ; then
273               echo "Copying GTK i18n files for $l..."
274               cp -r $GTKQUARTZ_ROOT/share/locale/$just_lang $Locale
275           fi
276       fi
277     done
278 else
279     echo "Skipping NLS support"
280 fi
281
282 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
283 echo "Copying all Pango modules ..."
284 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
285 echo "Copying all GDK Pixbuf loaders ..."
286 cp -R $GDKPIXBUF_LOADERS/*.so $Frameworks/modules
287 # charset alias file
288 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
289
290 pwd=`pwd`
291
292 if test x$WITH_LADSPA != x ; then
293     if test x$SAE != x ; then
294         plugdir=sae_ladspa
295     elif test x$MIXBUS != x ; then
296         plugdir=mixbus_ladspa
297     else
298         plugdir=ladspa
299     fi
300     echo "Copying `ls $plugdir | wc -l` plugins ..."
301     cp -r $plugdir/* $Plugins
302 fi
303
304 # generate new Pango module file
305 cat > pangorc <<EOF 
306 [Pango]
307 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
308 EOF
309 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
310 rm pangorc
311
312 # generate a new GDK pixbufs loaders file
313 gdk-pixbuf-query-loaders | sed "s?$GDKPIXBUF_LOADERS/?@executable_path/../Frameworks/modules/?" > $Resources/gdk-pixbuf.loaders
314
315 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
316 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.dylib $Frameworks
317 mkdir -p $Frameworks/clearlooks/engines
318 (cd $Frameworks/clearlooks/engines && ln -s $BUILD_ROOT/libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
319
320 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.dylib $Surfaces
321 cp $BUILD_ROOT/libs/panners/*/lib*.dylib $Panners
322 (cd ../../export && 
323     for f in *.preset ; do 
324         echo ExportFormat: $f; cp "$f" ../tools/osx_packaging/$ExportFormats ; 
325 done)
326 (cd $BUILD_ROOT/templates && \
327     for f in *.template ; do 
328         echo Template: $f ; cp "$f" ../../tools/osx_packaging/$Templates ; 
329 done)
330
331 # MIDI maps
332 cp ../../midi_maps/*.map $MidiMaps
333
334 # VAMP plugins that we use
335 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
336
337 while [ true ] ; do 
338     missing=false
339     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
340         if ! file $file | grep -qs Mach-O ; then
341             continue
342         fi
343         if test x$INTERNAL_JACK != x ; then
344             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)"`
345         else
346             # do not include libjack
347             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | grep -v 'libjack\.'`
348         fi
349         echo -n "."
350         for dep in $deps ; do
351             base=`basename $dep`
352             if ! test -f $Frameworks/$base; then
353                 if echo $dep | grep -sq '^libs' ; then
354                     cp $BUILD_ROOT/$dep $Frameworks
355                 else
356                     cp $dep $Frameworks
357                 fi
358                 missing=true
359             fi
360         done
361     done
362     if test x$missing = xfalse ; then
363         # everything has been found
364         break
365     fi
366 done
367 echo
368
369 echo "Copying other stuff to $APPDIR  ..."
370
371 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings  $Resources
372
373 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Resources
374 cp ../../gtk2_ardour/mixer.bindings $Resources
375 cp ../../gtk2_ardour/step_editing.bindings $Resources
376 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
377
378 if test x$SAE != x ; then
379     cp $BUILD_ROOT/gtk2_ardour/SAE-de-keypad.bindings  $Resources
380     cp $BUILD_ROOT/gtk2_ardour/SAE-de-nokeypad.bindings  $Resources
381     cp $BUILD_ROOT/gtk2_ardour/SAE-us-keypad.bindings  $Resources
382     cp $BUILD_ROOT/gtk2_ardour/SAE-us-nokeypad.bindings  $Resources
383     cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
384     echo cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
385     cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
386     echo cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
387 else
388 #    cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
389 #    echo FOO cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
390     cp ../../instant.xml $Resources/instant.xml
391     echo cp ../../instant.xml $Resources/instant.xml
392 fi
393 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources
394 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources/ardour3_ui.conf
395 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Resources
396 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Resources
397
398 cp -r ../../gtk2_ardour/icons $Resources
399 cp -r ../../gtk2_ardour/pixmaps $Resources
400
401 # go through and recursively remove any .svn dirs in the bundle
402 for svndir in `find $APPDIR -name .svn -type dir`; do
403     rm -rf $svndir
404 done
405
406 # now fix up the executables
407 echo "Fixing up executable dependency names ..."
408 executables=$MAIN_EXECUTABLE
409 if test x$INTERNAL_JACK != x ; then
410     executables="$executables jackd"
411 fi
412 if test x$SAE != x ; then
413     executables="$executables"
414 fi
415
416 for exe in $executables; do
417     EXE=$APPROOT/MacOS/$exe
418     changes=""
419     if test x$INTERNAL_JACK != x ; then
420         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}'` ; do
421             base=`basename $lib`
422             changes="$changes -change $lib @executable_path/../Frameworks/$base"
423         done
424     else
425         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
426             base=`basename $lib`
427             changes="$changes -change $lib @executable_path/../Frameworks/$base"
428         done
429     fi
430     if test "x$changes" != "x" ; then
431         install_name_tool $changes $EXE
432     fi
433 done
434
435 echo "Fixing up library names ..."
436 # now do the same for all the libraries we include
437 for dylib in $JACK_SHARED_OBJECTS $Frameworks/*.dylib $Frameworks/modules/*.so $Surfaces/*.dylib ; do
438     # skip symlinks
439     if test ! -L $dylib ; then
440         
441         # change all the dependencies
442
443         changes=""
444         if test x$INTERNAL_JACK != x ; then
445             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}'` ; do
446                 base=`basename $lib`
447                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
448             done
449         else
450             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
451                 base=`basename $lib`
452                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
453             done
454         fi
455
456         if test "x$changes" != x ; then
457             if  install_name_tool $changes $dylib ; then
458                 :
459             else
460                 exit 1
461             fi
462         fi
463
464         # now the change what the library thinks its own name is
465
466         base=`basename $dylib`
467         install_name_tool -id @executable_path/../Frameworks/$base $dylib
468     fi
469 done
470
471 #
472 # and now ... the DMG
473
474
475 rm -rf $PRODUCT_PKG_DIR
476 mkdir $PRODUCT_PKG_DIR
477
478 if [ x$SAE != x ] ; then
479         
480     # SAE packaging
481     
482     echo "Creating SAE packaging directory"
483     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
484     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
485     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
486     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
487     
488 elif [ x$MIXBUS != x ] ; then
489
490      # Mixbus packaging
491
492     echo "Creating Mixbus packaging directory"
493     mv $APPDIR $PRODUCT_PKG_DIR/
494     cp MixBus_Install_QuickStart.pdf "$PRODUCT_PKG_DIR/Mixbus Install & Quick Start Guide.pdf"
495     
496     if [ -x $EXTERNAL_JACK != x ] ; then
497         cp $EXTERNAL_JACK $PRODUCT_PKG_DIR
498     fi
499     
500         # create dmg
501 else 
502
503     echo "Creating $APPNAME packaging directory"
504     mv $APPDIR $PRODUCT_PKG_DIR/
505
506 fi
507
508 echo "Building DMG ..."
509
510 # UC_DMG=$APPNAME-${release_version}-${svn_version}-UC.dmg
511 # FINAL_DMG=$APPNAME-${release_version}-${svn_version}.dmg
512 UC_DMG=$APPNAME-${release_version}-${svn_version}.dmg
513
514 rm -f $UC_DMG
515 echo hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
516 hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
517
518 # compress it
519 # echo "Compressing DMG ..."
520 # rm -f $FINAL_DMG
521 # hdiutil convert $UC_DMG -format UDBZ -o $FINAL_DMG
522
523 echo "Done."
524