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