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