add lv2core to bundles
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 set -e
4
5 # script for pulling together a MacOSX app bundle.
6
7 GTKSTACK_ROOT=$HOME/gtk/inst
8 ARDOURSTACK_ROOT=$HOME/a3/inst
9 BUILD_ROOT=../../build
10
11 # where harvid and xjadeo binaries are cached
12 if test -z "$CACHEDIR" -o ! -d "$CACHEDIR"; then
13         CACHEDIR=/var/tmp
14 fi
15 mkdir -p "$CACHEDIR"
16
17 SAE=
18 MIXBUS=
19 WITH_HARVID=1
20 WITH_LADSPA=1
21 STRIP=1
22 PRINT_SYSDEPS=
23 WITH_NLS=
24
25 while [ $# -gt 0 ] ; do
26     echo "arg = $1"
27     case $1 in
28
29         #
30         # top level build targets
31         #
32
33         --sae) WITH_NLS= ; 
34                SAE=1 ; 
35                WITH_LADSPA=1; 
36                STRIP= ; 
37                PRODUCT_PKG_DIR=ArdourSAE ; 
38                APPNAME=Ardour ;
39                shift ;;
40         --mixbus) MIXBUS=1; 
41                   WITH_NLS=1 ; 
42                   SAE= ; 
43                   WITH_LADSPA=; 
44                   STRIP= ; 
45                   PRODUCT_PKG_DIR=MixBus;
46                   APPNAME=Mixbus ;
47                   shift ;;
48         --public) WITH_NLS= ; 
49                   SAE= ; 
50                   WITH_LADSPA=1; 
51                   PRODUCT_PKG_DIR=Ardour;
52                   APPNAME=Ardour ;
53                   shift ;;
54         --allinone) SAE= ; 
55                     WITH_NLS= ; 
56                     WITH_LADSPA=1; 
57                     STRIP= ; 
58                     PRODUCT_PKG_DIR=Ardour ;
59                     shift ;;
60         --test) SAE= ; WITH_LADSPA=; STRIP= ; shift ;;
61
62         #
63         # specific build flags
64         #
65
66         --noharvid) WITH_HARVID= ; shift ;;
67         --noladspa) WITH_LADSPA= ; shift ;;
68         --nostrip) STRIP= ; shift ;;
69         --sysdeps) PRINT_SYSDEPS=1; shift ;;
70         --nls) WITH_NLS=1 ; shift ;;
71     esac
72 done
73
74 if test -z "$PRODUCT_PKG_DIR" -o -z "$APPNAME"; then
75         echo "application or product-name was not specified"
76         exit 1
77 fi
78
79 . ../define_versions.sh
80 echo "Version is $release_version"
81 if [ "x$commit" != "x" ] ; then
82     info_string="$release_version ($commit) built on `hostname` by `whoami` on `date`"
83 else
84     info_string="$release_version built on `hostname` by `whoami` on `date`"
85 fi
86 echo "Info string is $info_string"
87
88 if [ x$DEBUG = xT ]; then
89         STRIP=
90         echo "Debug build, strip disabled"
91 else
92         if test x$STRIP != x ; then
93                 echo "No debug build, strip enabled"
94         else
95                 echo "No debug build, but strip disabled."
96         fi
97 fi
98
99 # setup directory structure
100
101 APPDIR=${APPNAME}.app
102 APPROOT=$APPDIR/Contents
103 Frameworks=$APPROOT/lib
104 Resources=$APPROOT/Resources
105 #
106 # Since this is OS X, don't try to distinguish between etc and shared
107 # (machine dependent and independent data) - just put everything
108 # into Resources.
109
110 Shared=$Resources
111 Etc=$Resources
112 Locale=$Resources/locale
113 #
114 # Bundled Plugins live in a top level folder
115
116 Plugins=$APPROOT/Plugins
117 Surfaces=$Frameworks/surfaces
118 Panners=$Frameworks/panners
119 Backends=$Frameworks/backends
120 MidiMaps=$Shared/midi_maps
121 ExportFormats=$Shared/export
122 Templates=$Shared/templates
123 PatchFiles=$Shared/patchfiles
124 MackieControl=$Shared/mcp
125
126 if [ x$PRINT_SYSDEPS != x ] ; then
127 #
128 # print system dependencies
129 #
130
131 for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do
132         if ! file $file | grep -qs Mach-O ; then
133             continue
134         fi
135         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
136     done | sort | uniq
137     exit 0
138 fi
139
140 echo "Removing old $APPDIR tree ..."
141
142 rm -rf $APPDIR
143
144 echo "Building new app directory structure ..."
145
146 # only bother to make the longest paths
147
148 mkdir -p $APPROOT/MacOS
149 mkdir -p $APPROOT/Resources
150 mkdir -p $Plugins
151 mkdir -p $Surfaces
152 mkdir -p $Panners
153 mkdir -p $Backends
154 mkdir -p $MidiMaps
155 mkdir -p $ExportFormats
156 mkdir -p $Templates
157 mkdir -p $Frameworks/modules
158 mkdir -p $Etc
159 mkdir -p $MackieControl
160 mkdir -p $PatchFiles
161
162 # maybe set variables
163 env=""
164 if test x$SAE != x ; then
165     appname="Ardour3/SAE"
166     env="$env<key>ARDOUR_SAE</key><string>true</string>"
167     #
168     # current default for SAE version is German keyboard layout without a keypad
169     #
170     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de-nokeypad</string>"
171     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui_sae.conf</string>"
172 elif test x$MIXBUS != x ; then
173     appname="Ardour3/Mixbus"
174     env="$env<key>ARDOUR_MIXBUS</key><string>true</string>"
175     #
176     # current default for MIXBUS version is US keyboard layout without a keypad
177     #
178     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>us-nokeypad</string>"
179     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui.conf</string>"
180 else
181     appname="Ardour3"
182 fi
183
184 #
185 # if we're not going to bundle JACK, make sure we can find
186 # jack in the places where it might be
187 #
188
189 env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>"
190 env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
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?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?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 # ..and clean up
210 rm -f Info.plist
211 rm -f Resources/InfoPlist.strings
212
213 #
214 # if we build a bundle without jack, then
215 # make the Ardour3 executable a helper
216 # script that checks to see if JACK is
217 # installed.
218 #
219
220 cp startup_script $APPROOT/MacOS/Ardour3
221 chmod 775 $APPROOT/MacOS/Ardour3
222 MAIN_EXECUTABLE=Ardour3.bin
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
236 set +e # things below are not error-free (optional files etc) :(
237
238 # copy locale files
239 if test x$WITH_NLS != x ; then
240     echo "NLS support ..."
241     echo "I hope you remembered to run waf i18n"
242     LINGUAS=
243
244     for pkg in gtk2_ardour libs/ardour libs/gtkmm2ext ; do 
245         files=`find ../../$pkg -name "*.mo"`
246         
247             #
248             # the package name is appended with a number so that
249             # it can be parallel installed during a regular install
250             # with older (and newer) versions. it is just the major
251             # number of the release (i.e. leading digits)
252             #
253         
254         vsuffix=`echo $release_version | sed 's/^\([0-9][0-9]*\).*/\1/'`
255         
256         if [ -z "$files" ]; then
257             echo ""
258             echo "!!!! WARNING !!!! - Did not find any .mo files in ../../$pkg"
259             echo ""
260         fi
261         
262         for file in $files 
263         do
264             echo $file
265             lang=`basename $file | sed 's/\.mo//'`
266             mkdir -p $Locale/$lang/LC_MESSAGES
267             cp $file $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
268             echo copy $file to $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
269             if echo $LINGUAS | grep $lang >/dev/null 2>&1 ; then
270                 :
271             else 
272                 LINGUAS="$LINGUAS $lang"
273             fi
274         done
275     done
276
277     for l in $LINGUAS
278     do
279       if [ -d $GTKSTACK_ROOT/share/locale/$l ] ; then
280           echo "Copying GTK i18n files for $l..."
281           cp -r $GTKSTACK_ROOT/share/locale/$l $Locale
282       else
283           # try with just the language spec
284           just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
285           if [ -d $GTKSTACK_ROOT/share/locale/$just_lang ] ; then
286               echo "Copying GTK i18n files for $l..."
287               cp -r $GTKSTACK_ROOT/share/locale/$just_lang $Locale
288           fi
289       fi
290     done
291 else
292     echo "Skipping NLS support"
293 fi
294
295 #
296 # Copy stuff that may be dynamically loaded
297
298
299 cp -R $GTKSTACK_ROOT/etc/* $Etc
300 echo "Copying all Pango modules ..."
301 cp -R $GTKSTACK_ROOT/lib/pango/1.8.0/modules/*.so $Frameworks/modules
302 echo "Copying all GDK Pixbuf loaders ..."
303 cp -R $GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so $Frameworks/modules
304 # charset alias file
305 cp -R $GTKSTACK_ROOT/lib/charset.alias $Resources
306
307 # generate new Pango module file
308 cat > pangorc <<EOF 
309 [Pango]
310 ModulesPath=$GTKSTACK_ROOT/lib/pango/1.8.0/modules
311 EOF
312 env PANGO_RC_FILE=pangorc $GTKSTACK_ROOT/bin/pango-querymodules | sed "s?$GTKSTACK_ROOT/lib/pango/1.8.0/modules/?@executable_path/../lib/modules/?" > $Resources/pango.modules
313 rm pangorc
314
315 # generate a new GDK pixbufs loaders file
316 gdk-pixbuf-query-loaders | sed "s?$GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/?@executable_path/../lib/modules/?" > $Resources/gdk-pixbuf.loaders
317
318 # We rely on clearlooks, so include a version from our own build tree
319 # this one is special - we will set GTK_PATH to $Frameworks/gtkengines
320
321 GTK_ENGINE_DIR=$Frameworks/gtkengines/engines
322 mkdir -p $GTK_ENGINE_DIR
323
324 echo "Copying GTK engines ..."
325 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.dylib $Frameworks
326 (cd $GTK_ENGINE_DIR && ln -s ../../libclearlooks.dylib . && ln -s ../../libclearlooks.dylib libclearlooks.so)
327
328 cp $GTKSTACK_ROOT/lib/gtk-2.0/2.10.0/engines/libpixmap.so $Frameworks
329 (cd $GTK_ENGINE_DIR && ln -s ../../libpixmap.so)
330
331
332 if test x$WITH_LADSPA != x ; then
333     if test x$SAE != x ; then
334         plugdir=sae_ladspa
335     elif test x$MIXBUS != x ; then
336         plugdir=mixbus_ladspa
337     else
338         plugdir=ladspa
339     fi
340     if [ -d $plugdir -a "x$(ls $plugdir)" != x ] ; then 
341         echo "Copying `ls $plugdir | wc -l` plugins ..."
342         cp -r $plugdir/* $Plugins
343     fi
344 fi
345
346 # Control Surface shared libraries
347 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.dylib $Surfaces
348 cp $BUILD_ROOT/libs/surfaces/control_protocol/libardourcp*.dylib $Frameworks
349
350 # Panners
351 cp $BUILD_ROOT/libs/panners/*/lib*.dylib $Panners
352
353 # Backends
354 for backend in jack wavesaudio dummy; do
355     cp $BUILD_ROOT/libs/backends/$backend/lib*.dylib $Backends
356 done
357
358 # Export Formats/Presets
359 for f in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do 
360     cp "$f" $ExportFormats ; 
361 done
362
363 # Session and Route templates
364 #for f in $BUILD_ROOT/../templates/* ; do 
365 #    if [ -d "$f" ] ; then
366 #        cp -r "$f" $Templates ; 
367 #    fi
368 #done
369
370 # MidiMaps
371 # got to be careful with names here
372 for x in $BUILD_ROOT/../midi_maps/*.map ; do
373     cp "$x" $MidiMaps
374 done
375
376 # MIDNAM Patch Files
377 # got to be careful with names here
378 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
379     cp "$x" $PatchFiles
380 done
381
382 # MackieControl data
383 # got to be careful with names here
384 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
385     cp "$x" $MackieControl
386 done
387
388 # VAMP plugins that we use
389 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
390
391 # Suil modules (new dir 'build-stack')
392 if test -d $GTKSTACK_ROOT/lib/suil-0/ ; then
393     cp $GTKSTACK_ROOT/lib/suil-0/lib* $Frameworks
394 fi
395
396 # Suil modules (old dir 'build-ardour-stack')
397 if test -d $ARDOURSTACK_ROOT/lib/suil-0/ ; then
398     cp $ARDOURSTACK_ROOT/lib/suil-0/lib* $Frameworks
399 fi
400
401 # VST scanner app and wrapper script, if they exist
402 if test -d $BUILD_ROOT/libs/fst ; then
403     cp $BUILD_ROOT/libs/fst/ardour-vst-scanner* $Frameworks/
404 fi
405
406 # vfork wrapper
407 if test -f $BUILD_ROOT/libs/vfork/ardour-exec-wrapper ; then
408     mkdir -p $Frameworks/vfork
409     cp $BUILD_ROOT/libs/vfork/ardour-exec-wrapper $Frameworks/
410 fi
411
412
413 while [ true ] ; do 
414     missing=false
415     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Panners/*.dylib $Backends/*.dylib $Surfaces/*.dylib $Plugins/*.so ; do 
416         if ! file $file | grep -qs Mach-O ; then
417             continue
418         fi
419
420         if test x$STRIP != x ; then
421                 strip -u -r -arch all $file &>/dev/null
422         fi
423
424         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | grep -v 'libjack\.'`
425         # echo -n "."
426         for dep in $deps ; do
427             base=`basename $dep`
428             if ! test -f $Frameworks/$base; then
429                 if echo $dep | grep -sq '^libs' ; then
430                     cp $BUILD_ROOT/$dep $Frameworks
431                 else
432                     cp $dep $Frameworks
433                 fi
434                 missing=true
435             fi
436         done
437     done
438     if test x$missing = xfalse ; then
439         # everything has been found
440         break
441     fi
442 done
443 echo
444
445 echo "Copying other stuff to $APPDIR  ..."
446
447 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings  $Resources
448
449 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Resources
450 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
451 cp $BUILD_ROOT/gtk2_ardour/default_ui_config $Resources
452 cp $BUILD_ROOT/gtk2_ardour/clearlooks.rc $Resources
453
454 # Copied directly from source tree
455
456 cp ../../system_config $Resources/system_config
457 cp ../../instant.xml $Resources/instant.xml
458 cp ../../gtk2_ardour/step_editing.bindings $Resources
459 cp ../../gtk2_ardour/mixer.bindings $Resources
460 cp -r ../../gtk2_ardour/icons $Resources
461 cp -r ../../gtk2_ardour/pixmaps $Resources
462 cp ../../gtk2_ardour/dark.colors $Resources
463 cp -R ../../gtk2_ardour/splash.png $Shared
464 cp -R ../../gtk2_ardour/small-splash.png $Shared
465 cp -R ../../gtk2_ardour/ArdourMono.ttf $Shared
466
467 # go through and recursively remove any .svn dirs in the bundle
468 for svndir in `find $APPDIR -name .svn -type dir`; do
469     rm -rf $svndir
470 done
471
472 # install bundled LV2s to <app>/Contents/lib/LV2/
473 cp -R $BUILD_ROOT/libs/LV2 $Frameworks/
474
475 # lv2 core, classifications etc - TODO check if we need the complete LV2 ontology
476 if test -d $ARDOURSTACK_ROOT/lib/lv2/lv2core.lv2 ; then
477         cp -R $ARDOURSTACK_ROOT/lib/lv2/lv2core.lv2 $Frameworks/LV2/
478 elif test -d $GTKSTACK_ROOT/lib/lv2/lv2core.lv2 ; then
479         cp -R $GTKSTACK_ROOT/lib/lv2/lv2core.lv2 $Frameworks/LV2/
480 fi
481
482
483 # now fix up the executables
484 echo "Fixing up executable dependency names ..."
485 executables=$MAIN_EXECUTABLE
486 if test x$SAE != x ; then
487     executables="$executables"
488 fi
489
490 for exe in $executables; do
491     EXE=$APPROOT/MacOS/$exe
492     changes=""
493     for lib in `otool -L $EXE | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
494       base=`basename $lib`
495       changes="$changes -change $lib @executable_path/../lib/$base"
496     done
497     if test "x$changes" != "x" ; then
498         install_name_tool $changes $EXE
499     fi
500 done
501
502 echo "Fixing up library names ..."
503 # now do the same for all the libraries we include
504 for libdir in $Frameworks $Frameworks/modules $Surfaces $Panners $Backends ; do
505
506     libbase=`basename $libdir`
507     
508     for dylib in $libdir/*.dylib $libdir/*.so ; do
509         
510        # skip symlinks
511         
512         if test -L $dylib ; then
513             continue
514         fi
515         
516         # change all the dependencies
517         
518         changes=""
519         for lib in `otool -L $dylib | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
520             base=`basename $lib`
521             if echo $lib | grep -s libbase; then
522                 changes="$changes -change $lib @executable_path/../$libbase/$base"
523             else
524                 changes="$changes -change $lib @executable_path/../lib/$base"
525             fi
526         done
527         
528         if test "x$changes" != x ; then
529             if  install_name_tool $changes $dylib ; then
530                 :
531             else
532                 exit 1
533             fi
534         fi
535         
536         # now the change what the library thinks its own name is
537         
538         base=`basename $dylib`
539         install_name_tool -id @executable_path/../$libbase/$base $dylib
540     done
541 done
542
543 #
544 # and now ... the DMG
545
546
547 rm -rf $PRODUCT_PKG_DIR
548 mkdir $PRODUCT_PKG_DIR
549
550 DMGWINBOTTOM=440
551 DMGBACKGROUND=dmgbg
552
553 if [ x$SAE != x ] ; then
554         
555     # SAE packaging
556     
557     echo "Creating SAE packaging directory"
558     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
559     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
560     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
561     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
562     
563 elif [ x$MIXBUS != x ] ; then
564
565      # Mixbus packaging
566
567     echo "Creating Mixbus packaging directory"
568     mv $APPDIR $PRODUCT_PKG_DIR/
569     DMGBACKGROUND=dmgbgMB
570 else 
571
572     echo "Creating $APPNAME packaging directory"
573     mv $APPDIR $PRODUCT_PKG_DIR/
574
575 fi
576
577 if test x$WITH_HARVID != x ; then
578         echo "installing video tools.."
579         HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
580         XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
581         MULTIARCH=osx
582         echo "copying harvid and xjadeo ..."
583
584         rsync -Pa \
585                 rsync://ardour.org/video-tools/harvid-osx-${HARVID_VERSION}.tgz \
586                 "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz"
587
588         rsync -Pa \
589                 rsync://ardour.org/video-tools/jadeo-${XJADEO_VERSION:1}.dmg \
590                 "$CACHEDIR/jadeo-${XJADEO_VERSION:1}.dmg"
591
592         tar -x -z \
593                 -C $PRODUCT_PKG_DIR/$APPROOT \
594                 -f "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz" || exit 1
595
596         JADEO=$(hdiutil attach "$CACHEDIR/jadeo-${XJADEO_VERSION:1}.dmg" | grep Apple_HFS | grep dev/ | cut -f 3)
597         cp -r "${JADEO}/Jadeo.app" "$PRODUCT_PKG_DIR/"
598         hdiutil detach "${JADEO}"
599
600         DMGWINBOTTOM=580
601         YPOS=$[ $DMGWINBOTTOM - 300 ]
602         XJADEOPOS="set position of item \"Jadeo.app\" of container window to {310, ${YPOS}}"
603
604         DMGBACKGROUND=${DMGBACKGROUND}xj
605 fi
606
607 echo "Building DMG ..."
608
609 # UC_DMG=$APPNAME-${release_version}-UC.dmg
610 # FINAL_DMG=$APPNAME-${release_version}.dmg
611
612 if [ x$DEBUG = xT ]; then
613         UC_DMG=$APPNAME-$release_version-dbg.dmg
614 else
615         UC_DMG=$APPNAME-$release_version.dmg
616 fi
617 VOLNAME=$APPNAME-$release_version
618
619 MNTPATH=`mktemp -d -t ardourimg`
620 TMPDMG=`mktemp -t ardour`
621 ICNSTMP=`mktemp -t ardouricon`
622 EXTRA_SPACE_MB=30
623 DMGMEGABYTES=$[ `du -sk "$PRODUCT_PKG_DIR" | cut -f 1` * 1024 / 1048576 + $EXTRA_SPACE_MB ]
624
625 echo "DMG MB = " $DMGMEGABYTES
626
627 rm -f $UC_DMG "$TMPDMG" "${TMPDMG}.dmg" "$ICNSTMP"
628 rm -rf "$MNTPATH"
629 mkdir -p "$MNTPATH"
630
631 TMPDMG="${TMPDMG}.dmg"
632
633 trap "rm -rf $MNTPATH $TMPDMG ${TMPDMG}.dmg $ICNSTMP" EXIT
634
635 hdiutil create -megabytes $DMGMEGABYTES "$TMPDMG"
636 DiskDevice=$(hdid -nomount "$TMPDMG" | grep Apple_HFS | cut -f 1 -d ' ')
637 newfs_hfs -v "${VOLNAME}" "${DiskDevice}"
638 mount -t hfs "${DiskDevice}" "${MNTPATH}"
639
640 cp -r ${PRODUCT_PKG_DIR}/* "${MNTPATH}" || exit
641 mkdir "${MNTPATH}/.background"
642 cp -vi ${DMGBACKGROUND}.png "${MNTPATH}/.background/dmgbg.png"
643
644 echo "setting DMG background ..."
645
646 if test $(sw_vers -productVersion | cut -d '.' -f 2) -lt 9; then
647         # OSX ..10.8.X
648         DISKNAME=${VOLNAME}
649 else
650         # OSX 10.9.X and later
651         DISKNAME=`basename "${MNTPATH}"`
652 fi
653
654 osascript << EOF
655   tell application "Finder"
656     activate
657     tell disk "${DISKNAME}"
658       open
659       set current view of container window to icon view
660       set toolbar visible of container window to false
661       set statusbar visible of container window to false
662       set the bounds of container window to {400, 200, 800, ${DMGWINBOTTOM}}
663       set theViewOptions to the icon view options of container window
664       set arrangement of theViewOptions to not arranged
665       set icon size of theViewOptions to 64
666       set background picture of theViewOptions to file ".background:dmgbg.png"
667       make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
668       set position of item "${APPDIR}" of container window to {90, 100}
669       set position of item "Applications" of container window to {310, 100}
670       ${MIXBUSPOS}
671       ${HARVIDPOS}
672       ${XJADEOPOS}
673       close
674       open
675       update without registering applications
676       delay 5
677       eject
678     end tell
679   end tell
680 EOF
681
682 chmod -Rf go-w "${MNTPATH}"
683 sync
684
685 set -e
686 echo "compressing Image ..."
687
688 # Umount the image
689 umount "${DiskDevice}"
690 hdiutil eject "${DiskDevice}"
691 # Create a read-only version, use zlib compression
692 hdiutil convert -format UDZO "${TMPDMG}" -imagekey zlib-level=9 -o "${UC_DMG}"
693
694 echo "setting file icon ..."
695
696 cp ${PRODUCT_PKG_DIR}/$Resources/appIcon.icns ${ICNSTMP}.icns
697 sips -i ${ICNSTMP}.icns
698 DeRez -only icns ${ICNSTMP}.icns > ${ICNSTMP}.rsrc
699 Rez -append ${ICNSTMP}.rsrc -o "$UC_DMG"
700 SetFile -a C "$UC_DMG"
701
702 rm ${ICNSTMP}.icns ${ICNSTMP}.rsrc
703
704 echo
705 echo "packaging suceeded."
706 ls -l "$UC_DMG"
707
708 echo "Done."
709 exit