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