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