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