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