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