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