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