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