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