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