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