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