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