another hack to accommodate different project names
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 set -e
4
5 # script for pulling together a MacOSX app bundle.
6
7 GTKSTACK_ROOT=$HOME/gtk/inst
8 ARDOURSTACK_ROOT=$HOME/a3/inst
9 BUILD_ROOT=../../build
10
11 # where harvid and xjadeo binaries are cached
12 if test -z "$CACHEDIR" -o ! -d "$CACHEDIR"; then
13         CACHEDIR=/var/tmp
14 fi
15 mkdir -p "$CACHEDIR"
16
17 SAE=
18 MIXBUS=
19 MIXBUS32C=
20 WITH_HARVID=1
21 WITH_HARRISON_LV2=
22 WITH_X42_LV2=
23 STRIP=1
24 PRINT_SYSDEPS=
25 WITH_NLS=
26
27 : ${HARRISONCHANNELSTRIP=harrison_channelstrip}
28 : ${HARRISONLV2=harrison_lv2s-n}
29 : ${HARRISONDSPURL=http://www.harrisonconsoles.com/plugins/releases/public}
30
31 . ../define_versions.sh
32
33 while [ $# -gt 0 ] ; do
34     echo "arg = $1"
35     case $1 in
36
37         #
38         # top level build targets
39         #
40
41         --sae)
42                 SAE=1 ;
43                 STRIP= ;
44                 PRODUCT_PKG_DIR=ArdourSAE ;
45                 APPNAME=Ardour ;
46                 BUNDLENAME=Ardour${major_version} ;
47                 lower_case_appname=ardour;
48                 shift ;;
49         --mixbus) MIXBUS=1;
50                 WITH_HARRISON_LV2=1 ;
51                 WITH_X42_LV2=1 ;
52                 WITH_NLS=1 ;
53                 SAE= ;
54                 STRIP= ;
55                 PRODUCT_PKG_DIR=Mixbus;
56                 APPNAME=Mixbus ;
57                 BUNDLENAME=Mixbus${major_version} ;
58                 lower_case_appname=mixbus;
59                 shift ;;
60         --mixbus32c) MIXBUS=1;
61                 MIXBUS32C=1;
62                 WITH_HARRISON_LV2=1 ;
63                 WITH_X42_LV2=1 ;
64                 WITH_NLS=1 ;
65                 SAE= ;
66                 STRIP= ;
67                 PRODUCT_PKG_DIR=Mixbus32C;
68                 lower_case_appname=mixbus32c;
69                 APPNAME=Mixbus32C-${major_version} ;
70                 BUNDLENAME=Mixbus32C-${major_version} ;
71                 shift ;;
72         --public)
73                 SAE= ;
74                 WITH_HARRISON_LV2=1 ;
75                 WITH_X42_LV2=1 ;
76                 PRODUCT_PKG_DIR=Ardour;
77                 APPNAME=Ardour ;
78                 BUNDLENAME=Ardour${major_version} ;
79                 lower_case_appname=ardour;
80                 shift ;;
81         --allinone) SAE= ;
82                 STRIP= ;
83                 PRODUCT_PKG_DIR=Ardour ;
84                 shift ;;
85         --test) SAE= ; STRIP= ; shift ;;
86
87         #
88         # specific build flags
89         #
90
91         --noharvid) WITH_HARVID= ; shift ;;
92         --nostrip) STRIP= ; shift ;;
93         --sysdeps) PRINT_SYSDEPS=1; shift ;;
94         --nls) WITH_NLS=1 ; shift ;;
95         --chanstrip) HARRISONCHANNELSTRIP=$2 ; shift; shift ;;
96     esac
97 done
98
99 if test -z "$PRODUCT_PKG_DIR" -o -z "$APPNAME"; then
100         echo "application or product-name was not specified"
101         exit 1
102 fi
103
104 echo "Version is $release_version"
105 if [ "x$commit" != "x" ] ; then
106     info_string="$release_version ($commit) built on `hostname` by `whoami` on `date`"
107 else
108     info_string="$release_version built on `hostname` by `whoami` on `date`"
109 fi
110 echo "Info string is $info_string"
111
112 if [ x$DEBUG = xT ]; then
113         STRIP=
114         echo "Debug build, strip disabled"
115 else
116         if test x$STRIP != x ; then
117                 echo "No debug build, strip enabled"
118         else
119                 echo "No debug build, but strip disabled."
120         fi
121 fi
122
123 # setup directory structure
124
125 APPDIR=${BUNDLENAME}.app
126 APPROOT=$APPDIR/Contents
127 Frameworks=$APPROOT/lib
128 Resources=$APPROOT/Resources
129 #
130 # Since this is OS X, don't try to distinguish between etc and shared
131 # (machine dependent and independent data) - just put everything
132 # into Resources.
133
134 Shared=$Resources
135 Etc=$Resources
136 Locale=$Resources/locale
137 #
138 # Bundled Plugins live in a top level folder
139
140 Plugins=$APPROOT/Plugins
141 Surfaces=$Frameworks/surfaces
142 Panners=$Frameworks/panners
143 Backends=$Frameworks/backends
144 MidiMaps=$Shared/midi_maps
145 ExportFormats=$Shared/export
146 Templates=$Shared/templates
147 PatchFiles=$Shared/patchfiles
148 LuaScripts=$Shared/scripts
149 MackieControl=$Shared/mcp
150 Themes=$Shared/themes
151
152 if [ x$PRINT_SYSDEPS != x ] ; then
153 #
154 # print system dependencies
155 #
156
157 for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do
158         if ! file $file | grep -qs Mach-O ; then
159             continue
160         fi
161         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
162     done | sort | uniq
163     exit 0
164 fi
165
166 echo "Removing old $APPDIR tree ..."
167
168 rm -rf $APPDIR
169
170 echo "Building new app directory structure ..."
171
172 # only bother to make the longest paths
173
174 mkdir -p $APPROOT/MacOS
175 mkdir -p $APPROOT/Resources
176 mkdir -p $Plugins
177 mkdir -p $Surfaces
178 mkdir -p $Panners
179 mkdir -p $Backends
180 mkdir -p $MidiMaps
181 mkdir -p $ExportFormats
182 mkdir -p $Templates
183 mkdir -p $Frameworks/modules
184 mkdir -p $Etc
185 mkdir -p $MackieControl
186 mkdir -p $PatchFiles
187 mkdir -p $LuaScripts
188 mkdir -p $Themes
189
190
191
192 EXECUTABLE=${BUNDLENAME}
193
194 #
195 # if we're not going to bundle JACK, make sure we can find
196 # jack in the places where it might be
197 #
198
199 env=""
200 env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>"
201 env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
202
203 env="<key>LSEnvironment</key><dict>$env<key>ARDOUR_BUNDLED</key><string>true</string></dict>"
204
205
206 # edit plist
207 sed -e "s?@ENV@?$env?g" \
208     -e "s?@VERSION@?$release_version?g" \
209     -e "s?@INFOSTRING@?$info_string?g" \
210     -e "s?@IDSUFFIX@?$EXECUTABLE?g" \
211     -e "s?@BUNDLENAME@?$BUNDLENAME?g" \
212     -e "s?@EXECUTABLE@?$EXECUTABLE?g" < Info.plist.in > Info.plist
213 # and plist strings
214 sed -e "s?@APPNAME@?$appname?" \
215     -e "s?@ENV@?$env?g" \
216     -e "s?@VERSION@?$release_version?g" \
217     -e "s?@INFOSTRING@?$info_string?g" < InfoPlist.strings.in > Resources/InfoPlist.strings || exit 1
218
219 # copy static files
220
221 cp Info.plist $APPROOT
222 cp -R Resources $APPROOT
223
224 # ..and clean up
225 rm -f Info.plist
226 rm -f Resources/InfoPlist.strings
227
228 #
229 # if we build a bundle without jack, then
230 # make the Ardour executable a helper
231 # script that checks to see if JACK is
232 # installed.
233 #
234
235 cp startup_script $APPROOT/MacOS/$EXECUTABLE
236 chmod 775 $APPROOT/MacOS/$EXECUTABLE
237 MAIN_EXECUTABLE=Ardour.bin  ## used in startup_script
238
239 echo "Copying ardour executable ...."
240 cp $BUILD_ROOT/gtk2_ardour/ardour-$release_version $APPROOT/MacOS/$MAIN_EXECUTABLE
241 if test x$SAE != x ; then
242     # cp $BUILD_ROOT/gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
243     cp  Ardour3-SAE.icns $Resources/appIcon.icns
244 elif test x$MIXBUS32C != x ; then
245     cp  Mixbus32C.icns $Resources/appIcon.icns
246 elif test x$MIXBUS != x ; then
247     cp  Mixbus.icns $Resources/appIcon.icns
248 else
249     cp  Ardour.icns $Resources/appIcon.icns
250 fi
251 cp  typeArdour.icns $Resources/
252
253 set +e # things below are not error-free (optional files etc) :(
254
255 # copy locale files
256 if test x$WITH_NLS != x ; then
257     echo "NLS support ..."
258     echo "I hope you remembered to run waf i18n"
259     LINGUAS=
260
261     for pkg in gtk2_ardour libs/ardour libs/gtkmm2ext ; do 
262         files=`find ../../$pkg -name "*.mo"`
263         
264             #
265             # the package name is appended with a number so that
266             # it can be parallel installed during a regular install
267             # with older (and newer) versions. it is just the major
268             # number of the release (i.e. leading digits)
269             #
270         
271         vsuffix=`echo $release_version | sed 's/^\([0-9][0-9]*\).*/\1/'`
272         
273         if [ -z "$files" ]; then
274             echo ""
275             echo "!!!! WARNING !!!! - Did not find any .mo files in ../../$pkg"
276             echo ""
277         fi
278         
279         for file in $files 
280         do
281             echo $file
282             lang=`basename $file | sed 's/\.mo//'`
283             mkdir -p $Locale/$lang/LC_MESSAGES
284             cp $file $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
285             echo copy $file to $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
286             if echo $LINGUAS | grep $lang >/dev/null 2>&1 ; then
287                 :
288             else 
289                 LINGUAS="$LINGUAS $lang"
290             fi
291         done
292     done
293
294     for l in $LINGUAS
295     do
296       if [ -d $GTKSTACK_ROOT/share/locale/$l ] ; then
297           echo "Copying GTK i18n files for $l..."
298           cp -r $GTKSTACK_ROOT/share/locale/$l $Locale
299       else
300           # try with just the language spec
301           just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
302           if [ -d $GTKSTACK_ROOT/share/locale/$just_lang ] ; then
303               echo "Copying GTK i18n files for $l..."
304               cp -r $GTKSTACK_ROOT/share/locale/$just_lang $Locale
305           fi
306       fi
307     done
308 else
309     echo "Skipping NLS support"
310 fi
311
312 #
313 # Copy stuff that may be dynamically loaded
314
315
316 cp -R $GTKSTACK_ROOT/etc/* $Etc
317 cp -R $GTKSTACK_ROOT/lib/charset.alias $Resources
318
319 # We rely on clearlooks, so include a version from our own build tree
320 # this one is special - we will set GTK_PATH to $Frameworks/gtkengines
321
322 GTK_ENGINE_DIR=$Frameworks/gtkengines/engines
323 mkdir -p $GTK_ENGINE_DIR
324
325 echo "Copying GTK engines ..."
326 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.dylib $Frameworks
327 (cd $GTK_ENGINE_DIR && ln -s ../../libclearlooks.dylib . && ln -s ../../libclearlooks.dylib libclearlooks.so)
328
329 cp $GTKSTACK_ROOT/lib/gtk-2.0/2.10.0/engines/libpixmap.so $Frameworks
330 (cd $GTK_ENGINE_DIR && ln -s ../../libpixmap.so)
331
332
333 # Control Surface shared libraries
334 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.dylib $Surfaces
335 cp $BUILD_ROOT/libs/surfaces/control_protocol/libardourcp*.dylib $Frameworks
336
337 # Panners
338 cp $BUILD_ROOT/libs/panners/*/lib*.dylib $Panners
339
340 # Backends
341 for backend in jack wavesaudio dummy coreaudio; do
342     cp $BUILD_ROOT/libs/backends/$backend/lib*.dylib $Backends
343 done
344
345 # Export Formats/Presets
346 for f in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do 
347     cp "$f" $ExportFormats ; 
348 done
349
350 # Session and Route templates
351 #for f in $BUILD_ROOT/../templates/* ; do 
352 #    if [ -d "$f" ] ; then
353 #        cp -r "$f" $Templates ; 
354 #    fi
355 #done
356
357 # MidiMaps
358 # got to be careful with names here
359 for x in $BUILD_ROOT/../midi_maps/*.map ; do
360     cp "$x" $MidiMaps
361 done
362
363 # MIDNAM Patch Files
364 # got to be careful with names here
365 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
366     cp "$x" $PatchFiles
367 done
368
369 # Lua Script Files
370 # got to be careful with names here
371 for x in $BUILD_ROOT/../scripts/*.lua ; do
372                 BN=$(basename $x)
373           if test "${BN:0:1}" = "_"; then
374                         continue;
375                 fi
376     cp "$x" $LuaScripts
377 done
378
379 # MackieControl data
380 # got to be careful with names here
381 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
382     cp "$x" $MackieControl
383 done
384
385 # VAMP plugins that we use
386 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
387
388 # Suil modules (new dir 'build-stack')
389 if test -d $GTKSTACK_ROOT/lib/suil-0/ ; then
390     cp $GTKSTACK_ROOT/lib/suil-0/lib* $Frameworks
391 fi
392
393 # Suil modules (old dir 'build-ardour-stack')
394 if test -d $ARDOURSTACK_ROOT/lib/suil-0/ ; then
395     cp $ARDOURSTACK_ROOT/lib/suil-0/lib* $Frameworks
396 fi
397
398 # VST scanner app and wrapper script, if they exist
399 if test -d $BUILD_ROOT/libs/fst ; then
400     cp $BUILD_ROOT/libs/fst/ardour-vst-scanner* $Frameworks/
401 fi
402
403 # vfork wrapper
404 if test -f $BUILD_ROOT/libs/vfork/ardour-exec-wrapper ; then
405     mkdir -p $Frameworks/vfork
406     cp $BUILD_ROOT/libs/vfork/ardour-exec-wrapper $Frameworks/
407 fi
408
409 # session-utils
410 HAVE_SESSION_UTILS=false
411 for file in $BUILD_ROOT/session_utils/${lower_case_appname}${major_version}-*; do
412         BN=$(basename $file)
413         cp -v $file $Frameworks/
414         if test x$STRIP = xall ; then
415                 strip -s $Frameworks/${BN}
416         fi
417         ln -s ../lib/ardour-util.sh ${APPROOT}/MacOS/${BN}
418         HAVE_SESSION_UTILS=true
419 done
420
421 # TODO check if this is still needed, even when building on 10.5
422 if file $BUILD_ROOT/gtk2_ardour/ardour-$release_version | grep -q ppc; then
423 STDCPP='|libstdc\+\+'
424 else
425 STDCPP=
426 fi
427
428 while [ true ] ; do 
429     missing=false
430     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Panners/*.dylib $Backends/*.dylib $Surfaces/*.dylib $Plugins/*.so ; do 
431         if ! file $file | grep -qs Mach-O ; then
432             continue
433         fi
434         # libffi contains "S" (other section symbols) that should not be stripped.
435         if [[ $file == *"libffi"* ]] ; then
436             continue
437         fi
438
439         if test x$STRIP != x ; then
440                 strip -u -r -arch all $file &>/dev/null
441         fi
442
443         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/$STDCPP)" | grep -v 'libjack\.' | grep -v "$(basename $file)"`
444         # echo -n "."
445         for dep in $deps ; do
446             base=`basename $dep`
447             if ! test -f $Frameworks/$base; then
448                 if echo $dep | grep -sq '^libs' ; then
449                     cp $BUILD_ROOT/$dep $Frameworks
450                 else
451                     cp $dep $Frameworks
452                 fi
453                 missing=true
454             fi
455         done
456     done
457     if test x$missing = xfalse ; then
458         # everything has been found
459         break
460     fi
461 done
462 echo
463
464 echo "Copying other stuff to $APPDIR  ..."
465
466 cp $BUILD_ROOT/gtk2_ardour/ardour.keys  $Resources
467 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
468 cp $BUILD_ROOT/gtk2_ardour/default_ui_config $Resources
469 cp $BUILD_ROOT/gtk2_ardour/clearlooks.rc $Resources
470
471 # Copied directly from source tree
472
473 mkdir ${Resources}/icons
474 mkdir ${Resources}/resources
475 cp ../../system_config $Resources/system_config
476 cp ../../instant.xml $Resources/instant.xml
477 cp ../../gtk2_ardour/icons/*.png ${Resources}/icons/
478 cp -r ../../gtk2_ardour/icons/cursor_* ${Resources}/icons/
479 cp ../../gtk2_ardour/ArdourMono.ttf $Shared
480 cp ../../gtk2_ardour/resources/${PRODUCT_PKG_DIR}-* ${Resources}/resources/
481
482
483 # Themes: only install those named for this app
484 cp ../../gtk2_ardour/themes/*-${lower_case_appname}.colors $Themes
485
486 # go through and recursively remove any .svn dirs in the bundle
487 for svndir in `find $APPDIR -name .svn -type dir`; do
488     rm -rf $svndir
489 done
490
491 # session utils start script
492 if test "$HAVE_SESSION_UTILS" = true ; then
493         cat >> $Frameworks/ardour-util.sh << EOF
494 #!/bin/sh
495
496 BIN_DIR=\$(dirname "\$0")
497 BUNDLE_DIR=\$(dirname "\$BIN_DIR")
498
499 export ARDOUR_DATA_PATH="\$BUNDLE_DIR/share"
500 export ARDOUR_CONFIG_PATH="\$BUNDLE_DIR/etc"
501 export ARDOUR_DLL_PATH="\$BUNDLE_DIR/lib"
502 export VAMP_PATH="\$BUNDLE_DIR/lib"\${VAMP_PATH:+:\$VAMP_PATH}
503
504 SELF=\$(basename "\$0")
505 exec "\$BUNDLE_DIR/lib/\$SELF" "\$@"
506 EOF
507         chmod +x $Frameworks/ardour-util.sh
508 fi
509
510
511 # install bundled LV2s to <app>/Contents/lib/LV2/
512 cp -R $BUILD_ROOT/libs/LV2 $Frameworks/
513
514 # lv2 core, classifications etc - TODO check if we need the complete LV2 ontology
515 if test -d $ARDOURSTACK_ROOT/lib/lv2/lv2core.lv2 ; then
516         cp -R $ARDOURSTACK_ROOT/lib/lv2/lv2core.lv2 $Frameworks/LV2/
517 elif test -d $GTKSTACK_ROOT/lib/lv2/lv2core.lv2 ; then
518         cp -R $GTKSTACK_ROOT/lib/lv2/lv2core.lv2 $Frameworks/LV2/
519 fi
520
521
522 # now fix up the executables
523 echo "Fixing up executable dependency names ..."
524 executables=$MAIN_EXECUTABLE
525 if test x$SAE != x ; then
526     executables="$executables"
527 fi
528 if test "$HAVE_SESSION_UTILS" = true ; then
529         for file in  $Frameworks/${lower_case_appname}${major_version}-*; do
530                 BN=$(basename $file)
531                 executables="$executables ../lib/${BN}"
532         done
533 fi
534
535 if test -f "$Frameworks/ardour-vst-scanner"; then
536         executables="$executables ../lib/ardour-vst-scanner"
537 fi
538
539 for exe in $executables; do
540     echo "Processing Executable: $exe"
541     EXE=$APPROOT/MacOS/$exe
542     changes=""
543     for lib in `otool -L $EXE | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/$STDCPP)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
544       base=`basename $lib`
545       changes="$changes -change $lib @executable_path/../lib/$base"
546     done
547     if test "x$changes" != "x" ; then
548         install_name_tool $changes $EXE
549     fi
550 done
551
552 echo "Fixing up library names ..."
553 # now do the same for all the libraries we include
554 for libdir in $Frameworks $Frameworks/modules $Surfaces $Panners $Backends $Frameworks/LV2/* ; do
555
556     libbase=`basename $libdir`
557     
558     for dylib in $libdir/*.dylib $libdir/*.so ; do
559         
560        # skip symlinks
561         
562         if test -L $dylib ; then
563             continue
564         fi
565         
566         # change all the dependencies
567         
568         changes=""
569         for lib in `otool -L $dylib | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/$STDCPP)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
570             base=`basename $lib`
571             if echo $lib | grep -s libbase; then
572                 changes="$changes -change $lib @executable_path/../$libbase/$base"
573             else
574                 changes="$changes -change $lib @executable_path/../lib/$base"
575             fi
576         done
577         
578         if test "x$changes" != x ; then
579             if  install_name_tool $changes $dylib ; then
580                 :
581             else
582                 exit 1
583             fi
584         fi
585         
586         # now the change what the library thinks its own name is
587         
588         base=`basename $dylib`
589         install_name_tool -id @executable_path/../$libbase/$base $dylib
590     done
591 done
592
593 #
594 # and now ... the DMG
595
596
597 rm -rf $PRODUCT_PKG_DIR
598 mkdir $PRODUCT_PKG_DIR
599
600 DMGWINBOTTOM=440
601 DMGBACKGROUND=dmgbg
602
603 if [ x$SAE != x ] ; then
604         
605     # SAE packaging
606     
607     echo "Creating SAE packaging directory"
608     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
609     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
610     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
611     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
612     
613 elif [ x$MIXBUS != x ] ; then
614
615      # Mixbus packaging
616
617     echo "Creating Mixbus packaging directory"
618     mv $APPDIR $PRODUCT_PKG_DIR/
619     DMGBACKGROUND=dmgbgMB
620 else 
621
622     echo "Creating $APPNAME packaging directory"
623     mv $APPDIR $PRODUCT_PKG_DIR/
624
625 fi
626
627 if file ${PRODUCT_PKG_DIR}/$APPROOT/MacOS/$MAIN_EXECUTABLE | grep -q x86_64; then
628         OSX_ARCH=x86_64
629         OSX_BENSID=osx64
630 elif file ${PRODUCT_PKG_DIR}/$APPROOT/MacOS/$MAIN_EXECUTABLE | grep -q ppc; then
631         OSX_ARCH=ppc
632         OSX_BENSID=osxppc
633 else
634         OSX_ARCH=i386
635         OSX_BENSID=osx32
636 fi
637
638 if test x$WITH_HARRISON_LV2 != x ; then
639         curl -s -S --fail -#  \
640                 -z "${CACHEDIR}/${HARRISONLV2}.${OSX_BENSID}.zip" \
641                 -o "${CACHEDIR}/${HARRISONLV2}.${OSX_BENSID}.zip" \
642                 "${HARRISONDSPURL}/${HARRISONLV2}.${OSX_BENSID}.zip"
643
644         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2"
645         bsdtar -C "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/" -xf \
646                 "${CACHEDIR}/${HARRISONLV2}.${OSX_BENSID}.zip"
647 fi
648
649 if test x$WITH_HARVID != x ; then
650         echo "installing video tools.."
651         HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
652         XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
653         MULTIARCH=osx
654         echo "copying harvid and xjadeo ..."
655
656         rsync -Pa \
657                 rsync://ardour.org/video-tools/harvid-osx-${HARVID_VERSION}.tgz \
658                 "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz"
659
660         rsync -Pa \
661                 rsync://ardour.org/video-tools/jadeo-${XJADEO_VERSION:1}.dmg \
662                 "$CACHEDIR/jadeo-${XJADEO_VERSION:1}.dmg"
663
664         tar -x -z \
665                 -C $PRODUCT_PKG_DIR/$APPROOT \
666                 -f "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz" || exit 1
667
668         JADEO=$(hdiutil attach "$CACHEDIR/jadeo-${XJADEO_VERSION:1}.dmg" | grep Apple_HFS | grep dev/ | cut -f 3)
669         cp -r "${JADEO}/Jadeo.app" "$PRODUCT_PKG_DIR/"
670         hdiutil detach "${JADEO}"
671
672         XJCONTENT=${PRODUCT_PKG_DIR}/Jadeo.app/Contents
673         HVLIBS=${PRODUCT_PKG_DIR}/$APPROOT/lib/harvid
674
675         for file in ${XJCONTENT}/MacOS/Jadeo-bin ${XJCONTENT}/Frameworks/*.dylib ${HVLIBS}/*.dylib ${PRODUCT_PKG_DIR}/$APPROOT/MacOS/*harvid* ; do
676                 lipo -extract_family ${OSX_ARCH} ${file} -output ${file}.thin && \
677                 mv ${file}.thin ${file}
678         done
679
680         DMGWINBOTTOM=580
681         YPOS=$[ $DMGWINBOTTOM - 300 ]
682         XJADEOPOS="set position of item \"Jadeo.app\" of container window to {310, ${YPOS}}"
683
684         DMGBACKGROUND=${DMGBACKGROUND}xj
685 fi
686
687 ################################################################################
688 ### Mixbus plugins, etc
689 if test x$WITH_X42_LV2 != x ; then
690         echo "bundling x42 plugins"
691         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2"
692
693         for proj in x42-meters x42-midifilter x42-midimap x42-stereoroute x42-eq setBfree; do
694                 X42_VERSION=$(curl -s -S http://x42-plugins.com/x42/osx/${proj}.latest.txt)
695                 rsync -a -q --partial \
696                         rsync://x42-plugins.com/x42/osx/${proj}-lv2-osx-${X42_VERSION}.zip \
697                         "$CACHEDIR/${proj}-lv2-osx-${X42_VERSION}.zip"
698                 bsdtar -C "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/" -xf \
699                         "$CACHEDIR/${proj}-lv2-osx-${X42_VERSION}.zip"
700         done
701
702         for file in ${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/*/*.dylib ; do
703                 lipo -extract_family ${OSX_ARCH} ${file} -output ${file}.thin
704                 mv ${file}.thin ${file}
705         done
706 fi
707
708 if test -n "$MIXBUS"; then
709         echo "deploying harrison channelstrip for $OSX_BENSID"
710
711         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/ladspa/strip"
712
713         curl -s -S --fail -#  \
714                 -z "${CACHEDIR}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so" \
715                 -o "${CACHEDIR}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so" \
716                 "${HARRISONDSPURL}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so"
717
718         cp "${CACHEDIR}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so" \
719                 "${PRODUCT_PKG_DIR}/${APPROOT}/lib/ladspa/strip/${HARRISONCHANNELSTRIP}.so"
720
721         echo "deploying harrison vamp plugins for $OSX_BENSID"
722
723         curl -s -S --fail -#  \
724                 -z "${CACHEDIR}/harrison_vamp.${OSX_BENSID}.dylib" \
725                 -o "${CACHEDIR}/harrison_vamp.${OSX_BENSID}.dylib" \
726                 "${HARRISONDSPURL}/harrison_vamp.${OSX_BENSID}.dylib"
727
728         cp "${CACHEDIR}/harrison_vamp.${OSX_BENSID}.dylib" \
729                 "${PRODUCT_PKG_DIR}/${APPROOT}/lib/harrison_vamp.dylib"
730 fi
731
732 ################################################################################
733
734 if test x$DEMO_SESSION_URL != x ; then
735         mkdir -p $Shared/sessions
736         DEMO_SESSIONS=$(curl -s -S --fail $DEMO_SESSION_URL/index.txt)
737         for demo in $DEMO_SESSIONS; do
738                 curl -s -S --fail -# -o $Shared/sessions/$demo $DEMO_SESSION_URL/$demo
739         done
740 fi
741
742 ################################################################################
743
744 ( cd $PRODUCT_PKG_DIR ; find . ) > file_list.txt
745
746 echo "Building DMG ..."
747
748 # UC_DMG=$APPNAME-${release_version}-UC.dmg
749 # FINAL_DMG=$APPNAME-${release_version}.dmg
750
751 if [ x$DEBUG = xT ]; then
752         UC_DMG=$APPNAME-$release_version-dbg.dmg
753 else
754         UC_DMG=$APPNAME-$release_version.dmg
755 fi
756 VOLNAME=$APPNAME-$release_version
757
758 MNTPATH=`mktemp -d -t ardourimg`
759 TMPDMG=`mktemp -t ardour`
760 ICNSTMP=`mktemp -t ardouricon`
761 EXTRA_SPACE_MB=30
762 DMGMEGABYTES=$[ `du -sk "$PRODUCT_PKG_DIR" | cut -f 1` * 1024 / 1048576 + $EXTRA_SPACE_MB ]
763
764 echo "DMG MB = " $DMGMEGABYTES
765
766 rm -f $UC_DMG "$TMPDMG" "${TMPDMG}.dmg" "$ICNSTMP"
767 rm -rf "$MNTPATH"
768 mkdir -p "$MNTPATH"
769
770 TMPDMG="${TMPDMG}.dmg"
771
772 trap "rm -rf $MNTPATH $TMPDMG ${TMPDMG}.dmg $ICNSTMP" EXIT
773
774 hdiutil create -megabytes $DMGMEGABYTES -fs HFS+ -volname "${VOLNAME}" "$TMPDMG"
775 DiskDevice=$(hdid -nomount "$TMPDMG" | grep Apple_HFS | cut -f 1 -d ' ')
776 mount -t hfs -o nobrowse "${DiskDevice}" "${MNTPATH}"
777
778 cp -r ${PRODUCT_PKG_DIR}/* "${MNTPATH}" || exit
779 mkdir "${MNTPATH}/.background"
780 cp -vi ${DMGBACKGROUND}.png "${MNTPATH}/.background/dmgbg.png"
781
782 echo "setting DMG background ..."
783
784 if test $(sw_vers -productVersion | cut -d '.' -f 2) -lt 9; then
785         # OSX ..10.8.X
786         DISKNAME=${VOLNAME}
787 else
788         # OSX 10.9.X and later
789         DISKNAME=`basename "${MNTPATH}"`
790 fi
791
792 osascript << EOF
793   tell application "Finder"
794     activate
795     tell disk "${DISKNAME}"
796       open
797       delay 2
798       set current view of container window to icon view
799       set toolbar visible of container window to false
800       set statusbar visible of container window to false
801       set the bounds of container window to {400, 200, 800, ${DMGWINBOTTOM}}
802       set theViewOptions to the icon view options of container window
803       set arrangement of theViewOptions to not arranged
804       set icon size of theViewOptions to 64
805       set background picture of theViewOptions to file ".background:dmgbg.png"
806       make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
807       set position of item "${APPDIR}" of container window to {90, 100}
808       set position of item "Applications" of container window to {310, 100}
809       ${MIXBUSPOS}
810       ${HARVIDPOS}
811       ${XJADEOPOS}
812       close
813       open
814       update without registering applications
815       delay 5
816       eject
817     end tell
818   end tell
819 EOF
820
821 chmod -Rf go-w "${MNTPATH}"
822 sync
823
824 set -e
825 echo "compressing Image ..."
826
827 # Umount the image ('eject' above may already have done that)
828 umount "${DiskDevice}" || true
829 hdiutil eject "${DiskDevice}" || true
830 # Create a read-only version, use zlib compression
831 hdiutil convert -format UDZO "${TMPDMG}" -imagekey zlib-level=9 -o "${UC_DMG}"
832
833 if test $(sw_vers -productVersion | cut -d '.' -f 2) -gt 5; then
834 echo "setting file icon ..."
835
836 cp ${PRODUCT_PKG_DIR}/$Resources/appIcon.icns ${ICNSTMP}.icns
837 sips -i ${ICNSTMP}.icns
838 DeRez -only icns ${ICNSTMP}.icns > ${ICNSTMP}.rsrc
839 Rez -append ${ICNSTMP}.rsrc -o "$UC_DMG"
840 SetFile -a C "$UC_DMG"
841
842 rm ${ICNSTMP}.icns ${ICNSTMP}.rsrc
843 fi
844
845 rm -rf ${PRODUCT_PKG_DIR}
846
847 echo
848 echo "packaging suceeded."
849 ls -l "$UC_DMG"
850
851 echo "Done."
852 exit