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