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