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