Unify build-system customization (Ardour/Mixbus)
[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 # dynamically loaded NSS/SSL libs
432 nsslibs="libsoftokn3.dylib libnsspem.dylib libnssckbi.dylib libfreebl3.dylib libnssdbm3.dylib libplds4.dylib"
433 for nsslib in $nsslibs; do
434         cp $GTKSTACK_ROOT/lib/$nsslib $Frameworks/ || true
435 done
436
437 # TODO check if this is still needed, even when building on 10.5
438 if file $BUILD_ROOT/gtk2_ardour/ardour-$release_version | grep -q ppc; then
439 STDCPP='|libstdc\+\+'
440 else
441 STDCPP=
442 fi
443
444 while [ true ] ; do 
445     missing=false
446     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Panners/*.dylib $Backends/*.dylib $Surfaces/*.dylib ; do
447         if ! file $file | grep -qs Mach-O ; then
448             continue
449         fi
450         # libffi contains "S" (other section symbols) that should not be stripped.
451         if [[ $file == *"libffi"* ]] ; then
452             continue
453         fi
454
455         if test x$STRIP != x ; then
456                 strip -u -r -arch all $file &>/dev/null
457         fi
458
459         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/$STDCPP)" | grep -v 'libjack\.' | grep -v "$(basename $file)"`
460         # echo -n "."
461         for dep in $deps ; do
462             base=`basename $dep`
463             if ! test -f $Frameworks/$base; then
464                 if echo $dep | grep -sq '^libs' ; then
465                     cp $BUILD_ROOT/$dep $Frameworks
466                 else
467                     cp $dep $Frameworks
468                 fi
469                 missing=true
470             fi
471         done
472     done
473     if test x$missing = xfalse ; then
474         # everything has been found
475         break
476     fi
477 done
478 echo
479
480 echo "Copying other stuff to $APPDIR  ..."
481
482 cp $BUILD_ROOT/gtk2_ardour/ardour.keys  $Resources
483 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
484 cp $BUILD_ROOT/gtk2_ardour/default_ui_config $Resources
485 cp $BUILD_ROOT/gtk2_ardour/clearlooks.rc $Resources
486
487 # Copied directly from source tree
488
489 mkdir ${Resources}/icons
490 mkdir ${Resources}/resources
491 cp ../../system_config $Resources/system_config
492 cp ../../gtk2_ardour/icons/*.png ${Resources}/icons/
493 cp -r ../../gtk2_ardour/icons/cursor_* ${Resources}/icons/
494 cp ../../gtk2_ardour/ArdourMono.ttf $Shared
495 cp ../../gtk2_ardour/resources/${PRODUCT_PKG_DIR}-* ${Resources}/resources/
496
497
498 # Themes: only install those named for this app
499 cp ../../gtk2_ardour/themes/*-${lower_case_appname}.colors $Themes
500
501 # go through and recursively remove any .svn dirs in the bundle
502 for svndir in `find $APPDIR -name .svn -type dir`; do
503     rm -rf $svndir
504 done
505
506 # session utils start script
507 if test "$HAVE_SESSION_UTILS" = true ; then
508         cat >> $Frameworks/ardour-util.sh << EOF
509 #!/bin/sh
510
511 BIN_DIR=\$(dirname "\$0")
512 BUNDLE_DIR=\$(dirname "\$BIN_DIR")
513
514 export ARDOUR_DATA_PATH="\$BUNDLE_DIR/share"
515 export ARDOUR_CONFIG_PATH="\$BUNDLE_DIR/etc"
516 export ARDOUR_DLL_PATH="\$BUNDLE_DIR/lib"
517 export VAMP_PATH="\$BUNDLE_DIR/lib"\${VAMP_PATH:+:\$VAMP_PATH}
518
519 SELF=\$(basename "\$0")
520 exec "\$BUNDLE_DIR/lib/\$SELF" "\$@"
521 EOF
522         chmod +x $Frameworks/ardour-util.sh
523 fi
524
525
526 # install bundled LV2s to <app>/Contents/lib/LV2/
527 cp -R $BUILD_ROOT/libs/LV2 $Frameworks/
528
529 # lv2 core, classifications etc - TODO check if we need the complete LV2 ontology
530 if test -d $ARDOURSTACK_ROOT/lib/lv2/lv2core.lv2 ; then
531         cp -R $ARDOURSTACK_ROOT/lib/lv2/lv2core.lv2 $Frameworks/LV2/
532 elif test -d $GTKSTACK_ROOT/lib/lv2/lv2core.lv2 ; then
533         cp -R $GTKSTACK_ROOT/lib/lv2/lv2core.lv2 $Frameworks/LV2/
534 fi
535
536
537 # now fix up the executables
538 echo "Fixing up executable dependency names ..."
539 executables=$MAIN_EXECUTABLE
540 if test x$SAE != x ; then
541     executables="$executables"
542 fi
543 if test "$HAVE_SESSION_UTILS" = true ; then
544         for file in  $Frameworks/${lower_case_appname}${major_version}-*; do
545                 BN=$(basename $file)
546                 executables="$executables ../lib/${BN}"
547         done
548 fi
549
550 if test -f "$Frameworks/ardour-vst-scanner"; then
551         executables="$executables ../lib/ardour-vst-scanner"
552 fi
553
554 for exe in $executables; do
555     echo "Processing Executable: $exe"
556     EXE=$APPROOT/MacOS/$exe
557     changes=""
558     for lib in `otool -L $EXE | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/$STDCPP)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
559       base=`basename $lib`
560       changes="$changes -change $lib @executable_path/../lib/$base"
561     done
562     if test "x$changes" != "x" ; then
563         install_name_tool $changes $EXE
564     fi
565 done
566
567 echo "Fixing up library names ..."
568 # now do the same for all the libraries we include
569 for libdir in $Frameworks $Frameworks/modules $Surfaces $Panners $Backends $Frameworks/LV2/* ; do
570
571     libbase=`basename $libdir`
572     
573     for dylib in $libdir/*.dylib $libdir/*.so ; do
574         
575        # skip symlinks
576         
577         if test -L $dylib ; then
578             continue
579         fi
580         
581         # change all the dependencies
582         
583         changes=""
584         for lib in `otool -L $dylib | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/$STDCPP)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
585             base=`basename $lib`
586             if echo $lib | grep -s libbase; then
587                 changes="$changes -change $lib @executable_path/../$libbase/$base"
588             else
589                 changes="$changes -change $lib @executable_path/../lib/$base"
590             fi
591         done
592         
593         if test "x$changes" != x ; then
594             if  install_name_tool $changes $dylib ; then
595                 :
596             else
597                 exit 1
598             fi
599         fi
600         
601         # now the change what the library thinks its own name is
602         
603         base=`basename $dylib`
604         install_name_tool -id @executable_path/../$libbase/$base $dylib
605     done
606 done
607
608 #
609 # and now ... the DMG
610
611
612 rm -rf $PRODUCT_PKG_DIR
613 mkdir $PRODUCT_PKG_DIR
614
615 DMGWINBOTTOM=440
616 DMGBACKGROUND=dmgbg
617
618 if [ x$SAE != x ] ; then
619         
620     # SAE packaging
621     
622     echo "Creating SAE packaging directory"
623     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
624     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
625     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
626     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
627     
628 elif [ x$MIXBUS != x ] ; then
629
630      # Mixbus packaging
631
632     echo "Creating Mixbus packaging directory"
633     mv $APPDIR $PRODUCT_PKG_DIR/
634     DMGBACKGROUND=dmgbgMB
635 else 
636
637     echo "Creating $APPNAME packaging directory"
638     mv $APPDIR $PRODUCT_PKG_DIR/
639
640 fi
641
642 if file ${PRODUCT_PKG_DIR}/$APPROOT/MacOS/$MAIN_EXECUTABLE | grep -q x86_64; then
643         OSX_ARCH=x86_64
644         OSX_BENSID=osx64
645 elif file ${PRODUCT_PKG_DIR}/$APPROOT/MacOS/$MAIN_EXECUTABLE | grep -q ppc; then
646         OSX_ARCH=ppc
647         OSX_BENSID=osxppc
648 else
649         OSX_ARCH=i386
650         OSX_BENSID=osx32
651 fi
652
653 if test x$WITH_HARRISON_LV2 != x ; then
654         curl -s -S --fail -#  \
655                 -z "${CACHEDIR}/${HARRISONLV2}.${OSX_BENSID}.zip" \
656                 -o "${CACHEDIR}/${HARRISONLV2}.${OSX_BENSID}.zip" \
657                 "${HARRISONDSPURL}/${HARRISONLV2}.${OSX_BENSID}.zip"
658
659         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2"
660         bsdtar -C "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/" -xf \
661                 "${CACHEDIR}/${HARRISONLV2}.${OSX_BENSID}.zip"
662 fi
663
664 if test x$WITH_HARVID != x ; then
665         echo "installing video tools.."
666         if test $OSX_ARCH = ppc; then
667                 # EOL
668                 HARVID_VERSION=v0.8.2
669                 XJADEO_VERSION=v0.8.8
670         else
671                 HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
672                 XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
673         fi
674         MULTIARCH=osx
675         echo "copying harvid and xjadeo ..."
676
677         rsync -Pa \
678                 rsync://ardour.org/video-tools/harvid-osx-${HARVID_VERSION}.tgz \
679                 "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz"
680
681         rsync -Pa \
682                 rsync://ardour.org/video-tools/jadeo-${XJADEO_VERSION:1}.dmg \
683                 "$CACHEDIR/jadeo-${XJADEO_VERSION:1}.dmg"
684
685         tar -x -z \
686                 -C $PRODUCT_PKG_DIR/$APPROOT \
687                 -f "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz" || exit 1
688
689         JADEO=$(hdiutil attach "$CACHEDIR/jadeo-${XJADEO_VERSION:1}.dmg" | grep Apple_HFS | grep dev/ | cut -f 3)
690         cp -r "${JADEO}/Jadeo.app" "$PRODUCT_PKG_DIR/"
691         hdiutil detach "${JADEO}"
692
693         XJCONTENT=${PRODUCT_PKG_DIR}/Jadeo.app/Contents
694         HVLIBS=${PRODUCT_PKG_DIR}/$APPROOT/lib/harvid
695
696         for file in ${XJCONTENT}/MacOS/Jadeo-bin ${XJCONTENT}/Frameworks/*.dylib ${HVLIBS}/*.dylib ${PRODUCT_PKG_DIR}/$APPROOT/MacOS/*harvid* ; do
697                 lipo -extract_family ${OSX_ARCH} ${file} -output ${file}.thin && \
698                 mv ${file}.thin ${file}
699         done
700
701         DMGWINBOTTOM=580
702         YPOS=$[ $DMGWINBOTTOM - 300 ]
703         XJADEOPOS="set position of item \"Jadeo.app\" of container window to {310, ${YPOS}}"
704
705         DMGBACKGROUND=${DMGBACKGROUND}xj
706 fi
707
708 ################################################################################
709 ### Mixbus plugins, etc
710 if true; then
711         echo "Bundling General MIDI Synth LV2"
712         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2"
713
714         for proj in x42-gmsynth; do
715                 X42_VERSION=$(curl -s -S http://x42-plugins.com/x42/osx/${proj}.latest.txt)
716                 rsync -a -q --partial \
717                         rsync://x42-plugins.com/x42/osx/${proj}-lv2-osx-${X42_VERSION}.zip \
718                         "$CACHEDIR/${proj}-lv2-osx-${X42_VERSION}.zip"
719                 bsdtar -C "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/" -xf \
720                         "$CACHEDIR/${proj}-lv2-osx-${X42_VERSION}.zip"
721         done
722
723         for file in ${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/*/*.dylib ; do
724                 lipo -extract_family ${OSX_ARCH} ${file} -output ${file}.thin
725                 mv ${file}.thin ${file}
726         done
727
728 fi
729
730 if test x$WITH_X42_LV2 != x ; then
731         echo "bundling x42 plugins"
732         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2"
733
734         for proj in x42-meters x42-midifilter x42-midimap x42-stereoroute x42-eq setBfree x42-avldrums x42-whirl x42-limiter; do
735                 X42_VERSION=$(curl -s -S http://x42-plugins.com/x42/osx/${proj}.latest.txt)
736                 rsync -a -q --partial \
737                         rsync://x42-plugins.com/x42/osx/${proj}-lv2-osx-${X42_VERSION}.zip \
738                         "$CACHEDIR/${proj}-lv2-osx-${X42_VERSION}.zip"
739                 bsdtar -C "${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/" -xf \
740                         "$CACHEDIR/${proj}-lv2-osx-${X42_VERSION}.zip"
741         done
742
743         for file in ${PRODUCT_PKG_DIR}/${APPROOT}/lib/LV2/*/*.dylib ; do
744                 lipo -extract_family ${OSX_ARCH} ${file} -output ${file}.thin
745                 mv ${file}.thin ${file}
746         done
747 fi
748
749 if test -n "$MIXBUS"; then
750         echo "deploying harrison channelstrip for $OSX_BENSID"
751
752         mkdir -p "${PRODUCT_PKG_DIR}/${APPROOT}/lib/ladspa/strip"
753
754         curl -s -S --fail -#  \
755                 -z "${CACHEDIR}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so" \
756                 -o "${CACHEDIR}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so" \
757                 "${HARRISONDSPURL}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so"
758
759         cp "${CACHEDIR}/${HARRISONCHANNELSTRIP}.${OSX_BENSID}.so" \
760                 "${PRODUCT_PKG_DIR}/${APPROOT}/lib/ladspa/strip/${HARRISONCHANNELSTRIP}.so"
761
762         echo "deploying harrison vamp plugins for $OSX_BENSID"
763
764         curl -s -S --fail -#  \
765                 -z "${CACHEDIR}/harrison_vamp.${OSX_BENSID}.dylib" \
766                 -o "${CACHEDIR}/harrison_vamp.${OSX_BENSID}.dylib" \
767                 "${HARRISONDSPURL}/harrison_vamp.${OSX_BENSID}.dylib"
768
769         cp "${CACHEDIR}/harrison_vamp.${OSX_BENSID}.dylib" \
770                 "${PRODUCT_PKG_DIR}/${APPROOT}/lib/harrison_vamp.dylib"
771 fi
772
773 ################################################################################
774
775 if test x$DEMO_SESSION_URL != x ; then
776         mkdir -p $Shared/sessions
777         DEMO_SESSIONS=$(curl -s -S --fail $DEMO_SESSION_URL/index.txt)
778         for demo in $DEMO_SESSIONS; do
779                 curl -s -S --fail -# -o $Shared/sessions/$demo $DEMO_SESSION_URL/$demo
780         done
781 fi
782
783 ################################################################################
784
785 ( cd $PRODUCT_PKG_DIR ; find . ) > file_list.txt
786
787 echo "Building DMG ..."
788
789 # UC_DMG=$APPNAME-${release_version}-UC.dmg
790 # FINAL_DMG=$APPNAME-${release_version}.dmg
791
792 if [ x$DEBUG = xT ]; then
793         UC_DMG=$APPNAME-$release_version-dbg.dmg
794 else
795         UC_DMG=$APPNAME-$release_version.dmg
796 fi
797 VOLNAME=$APPNAME-$release_version
798
799 MNTPATH=`mktemp -d -t ardourimg`
800 TMPDMG=`mktemp -t ardour`
801 ICNSTMP=`mktemp -t ardouricon`
802 EXTRA_SPACE_MB=30
803 DMGMEGABYTES=$[ `du -sk "$PRODUCT_PKG_DIR" | cut -f 1` * 1024 / 1048576 + $EXTRA_SPACE_MB ]
804
805 echo "DMG MB = " $DMGMEGABYTES
806
807 rm -f $UC_DMG "$TMPDMG" "${TMPDMG}.dmg" "$ICNSTMP"
808 rm -rf "$MNTPATH"
809 mkdir -p "$MNTPATH"
810
811 TMPDMG="${TMPDMG}.dmg"
812
813 trap "rm -rf $MNTPATH $TMPDMG ${TMPDMG}.dmg $ICNSTMP" EXIT
814
815 hdiutil create -megabytes $DMGMEGABYTES -fs HFS+ -volname "${VOLNAME}" "$TMPDMG"
816 DiskDevice=$(hdid -nomount "$TMPDMG" | grep Apple_HFS | cut -f 1 -d ' ')
817 mount -t hfs -o nobrowse "${DiskDevice}" "${MNTPATH}"
818
819 cp -r ${PRODUCT_PKG_DIR}/* "${MNTPATH}" || exit
820 mkdir "${MNTPATH}/.background"
821 cp -vi ${DMGBACKGROUND}.png "${MNTPATH}/.background/dmgbg.png"
822
823 echo "setting DMG background ..."
824
825 if test $(sw_vers -productVersion | cut -d '.' -f 2) -lt 9; then
826         # OSX ..10.8.X
827         DISKNAME=${VOLNAME}
828 else
829         # OSX 10.9.X and later
830         DISKNAME=`basename "${MNTPATH}"`
831 fi
832
833 osascript << EOF
834   tell application "Finder"
835     activate
836     tell disk "${DISKNAME}"
837       open
838       delay 2
839       set current view of container window to icon view
840       set toolbar visible of container window to false
841       set statusbar visible of container window to false
842       set the bounds of container window to {400, 200, 800, ${DMGWINBOTTOM}}
843       set theViewOptions to the icon view options of container window
844       set arrangement of theViewOptions to not arranged
845       set icon size of theViewOptions to 64
846       set background picture of theViewOptions to file ".background:dmgbg.png"
847       make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
848       set position of item "${APPDIR}" of container window to {90, 100}
849       set position of item "Applications" of container window to {310, 100}
850       ${MIXBUSPOS}
851       ${HARVIDPOS}
852       ${XJADEOPOS}
853       close
854       open
855       update without registering applications
856       delay 3
857       set position of item "${APPDIR}" of container window to {90, 100}
858       set position of item "Applications" of container window to {310, 100}
859       ${MIXBUSPOS}
860       ${HARVIDPOS}
861       ${XJADEOPOS}
862       close
863       open
864       update without registering applications
865       delay 3
866       eject
867     end tell
868   end tell
869 EOF
870
871 chmod -Rf go-w "${MNTPATH}"
872 sync
873
874 set -e
875 echo "compressing Image ..."
876
877 # Umount the image ('eject' above may already have done that)
878 umount "${DiskDevice}" || true
879 hdiutil eject "${DiskDevice}" || true
880 # Create a read-only version, use zlib compression
881 hdiutil convert -format UDZO "${TMPDMG}" -imagekey zlib-level=9 -o "${UC_DMG}"
882
883 if test $(sw_vers -productVersion | cut -d '.' -f 2) -gt 5; then
884 echo "setting file icon ..."
885
886 cp ${PRODUCT_PKG_DIR}/$Resources/appIcon.icns ${ICNSTMP}.icns
887 sips -i ${ICNSTMP}.icns
888 DeRez -only icns ${ICNSTMP}.icns > ${ICNSTMP}.rsrc
889 Rez -append ${ICNSTMP}.rsrc -o "$UC_DMG"
890 SetFile -a C "$UC_DMG"
891
892 rm ${ICNSTMP}.icns ${ICNSTMP}.rsrc
893 fi
894
895 rm -rf ${PRODUCT_PKG_DIR}
896
897 echo
898 echo "packaging suceeded."
899 ls -l "$UC_DMG"
900
901 echo "Done."
902 exit