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