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