tweaks to packaging to make SUIL (and thus LV2 UI's) work
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 # script for pulling together a MacOSX app bundle.
4
5 GTKQUARTZ_ROOT=$HOME/gtk/inst
6 ARDOURSTACK_ROOT=$HOME/a3/inst
7
8 if pkg-config --modversion gtk+-2.0 | grep -s 2.22 ; then
9     # older GTK
10     GDKPIXBUF_LOADERS=$GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders
11     echo 
12     echo
13     echo "*****************************************************"
14     echo "You are building with the OLD GTK stack. I hope that is ok"
15     echo "*****************************************************"
16     echo
17     echo
18 else
19     # newer GTK
20     GDKPIXBUF_LOADERS=$GTKQUARTZ_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders
21     echo 
22     echo
23     echo "*****************************************************"
24     echo "You are building with the NEW GTK stack. I hope that is ok"
25     echo "*****************************************************"
26     echo
27     echo
28 fi
29
30 SAE=
31 MIXBUS=
32 WITH_LADSPA=1
33 STRIP=1
34 PRINT_SYSDEPS=
35 WITH_NLS=
36
37 while [ $# -gt 0 ] ; do
38     echo "arg = $1"
39     case $1 in
40
41         #
42         # top level build targets
43         #
44
45         --sae) WITH_NLS= ; 
46                SAE=1 ; 
47                WITH_LADSPA=1; 
48                STRIP= ; 
49                PRODUCT_PKG_DIR=ArdourSAE ; 
50                APPNAME=Ardour ;
51                shift ;;
52         --mixbus) MIXBUS=1; 
53                   WITH_NLS=1 ; 
54                   SAE= ; 
55                   WITH_LADSPA=; 
56                   STRIP= ; 
57                   PRODUCT_PKG_DIR=MixBus;
58                   APPNAME=Mixbus ;
59                   shift ;;
60         --public) WITH_NLS= ; 
61                   SAE= ; 
62                   WITH_LADSPA=1; 
63                   STRIP= ; 
64                   PRODUCT_PKG_DIR=Ardour;
65                   APPNAME=Ardour ;
66                   shift ;;
67         --allinone) SAE= ; 
68                     WITH_NLS= ; 
69                     WITH_LADSPA=1; 
70                     STRIP= ; 
71                     PRODUCT_PKG_DIR=Ardour ;
72                     shift ;;
73         --test) SAE= ; WITH_LADSPA=; STRIP= ; shift ;;
74
75         #
76         # specific build flags
77         #
78
79         --noladspa) WITH_LADSPA= ; shift ;;
80         --nostrip) STRIP= ; shift ;;
81         --sysdeps) PRINT_SYSDEPS=1; shift ;;
82         --nls) WITH_NLS=1 ; shift ;;
83     esac
84 done
85
86 BUILD_ROOT=../../build
87
88 #release_version=`grep -m 1 '^VERSION' ../../wscript | cut -d' ' -f 3 | sed "s/'//g"`
89 release_version=3.0
90 svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d' ' -f 8 | sed 's/[^0-9]//g'`
91 echo "Version is $release_version / $svn_version"
92 info_string="$release_version/$svn_version built on `hostname` by `whoami` on `date`"
93 echo "Info string is $info_string"
94
95 # setup directory structure
96
97 APPDIR=${APPNAME}.app
98 APPROOT=$APPDIR/Contents
99 Frameworks=$APPROOT/lib
100 Resources=$APPROOT/Resources
101 #
102 # Since this is OS X, don't try to distinguish between etc and shared
103 # (machine dependent and independent data) - just put everything
104 # into Resources.
105
106 Shared=$Resources
107 Etc=$Resources
108 Locale=$Resources/locale
109 #
110 # Bundled Plugins live in a top level folder
111
112 Plugins=$APPROOT/Plugins
113 Surfaces=$Frameworks/surfaces
114 Panners=$Frameworks/panners
115 MidiMaps=$Shared/midi_maps
116 ExportFormats=$Shared/export
117 Templates=$Shared/templates
118 PatchFiles=$Shared/patchfiles
119 MackieControl=$Shared/mcp
120
121 if [ x$PRINT_SYSDEPS != x ] ; then
122 #
123 # print system dependencies
124 #
125
126     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
127         if ! file $file | grep -qs Mach-O ; then
128             continue
129         fi
130         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
131     done | sort | uniq
132     exit 0
133 fi
134
135 echo "Removing old $APPDIR tree ..."
136
137 rm -rf $APPDIR
138
139 echo "Building new app directory structure ..."
140
141 # only bother to make the longest paths
142
143 mkdir -p $APPROOT/MacOS
144 mkdir -p $APPROOT/Resources
145 mkdir -p $Plugins
146 mkdir -p $Surfaces
147 mkdir -p $Panners
148 mkdir -p $MidiMaps
149 mkdir -p $ExportFormats
150 mkdir -p $Templates
151 mkdir -p $Frameworks/modules
152 mkdir -p $Shared/templates
153 mkdir -p $Etc
154 mkdir -p $MackieControl
155
156 # maybe set variables
157 env=""
158 if test x$SAE != x ; then
159     appname="Ardour3/SAE"
160     env="$env<key>ARDOUR_SAE</key><string>true</string>"
161     #
162     # current default for SAE version is German keyboard layout without a keypad
163     #
164     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de-nokeypad</string>"
165     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui_sae.conf</string>"
166     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark_sae.rc</string>"
167 elif test x$MIXBUS != x ; then
168     appname="Ardour3/Mixbus"
169     env="$env<key>ARDOUR_MIXBUS</key><string>true</string>"
170     #
171     # current default for MIXBUS version is US keyboard layout without a keypad
172     #
173     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>us-nokeypad</string>"
174     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui.conf</string>"
175     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark.rc</string>"
176 else
177     appname="Ardour3"
178 fi
179
180 #
181 # if we're not going to bundle JACK, make sure we can find
182 # jack in the places where it might be
183 #
184
185 env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>"
186 env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
187
188 env="<key>LSEnvironment</key><dict>$env<key>ARDOUR_BUNDLED</key><string>true</string></dict>"
189
190 # edit plist
191 sed -e "s?@ENV@?$env?g" \
192     -e "s?@VERSION@?$release_version/$svn_version?g" \
193     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
194 # and plist strings
195 sed -e "s?@APPNAME@?$appname?" \
196     -e "s?@ENV@?$env?g" \
197     -e "s?@VERSION@?$release_version/$svn_version?g" \
198     -e "s?@INFOSTRING@?$info_string?g" < InfoPlist.strings.in > Resources/InfoPlist.strings || exit 1
199
200 # copy static files
201
202 cp Info.plist $APPROOT
203 cp -R Resources $APPROOT
204
205 #
206 # if we build a bundle without jack, then
207 # make the Ardour3 executable a helper
208 # script that checks to see if JACK is
209 # installed.
210 #
211
212 cp startup_script $APPROOT/MacOS/Ardour3
213 chmod 775 $APPROOT/MacOS/Ardour3
214 MAIN_EXECUTABLE=Ardour3.bin
215
216 echo "Copying ardour executable ...."
217 cp $BUILD_ROOT/gtk2_ardour/ardour-$release_version $APPROOT/MacOS/$MAIN_EXECUTABLE
218 if test x$SAE != x ; then
219     # cp $BUILD_ROOT/gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
220     cp  Ardour3-SAE.icns $Resources/appIcon.icns
221 elif test x$MIXBUS != x ; then
222     cp  Mixbus.icns $Resources/appIcon.icns
223 else
224     cp  Ardour3.icns $Resources/appIcon.icns
225 fi
226 cp  typeArdour.icns $Resources/
227 if test x$STRIP != x ; then
228     strip $APPROOT/MacOS/Ardour3
229 fi
230
231 # copy locale files
232 if test x$WITH_NLS != x ; then
233     echo "NLS support ..."
234     echo "I hope you remembered to run scons msgupdate!"
235     LINGUAS=
236     for file in $BUILD_ROOT/gtk2_ardour/*.mo 
237     do
238         lang=`basename $file | sed 's/\.mo//'`
239         mkdir -p $Locale/$lang/LC_MESSAGES
240         cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
241         LINGUAS="$LINGUAS $lang"
242     done
243     for file in $BUILD_ROOT/libs/ardour/*.mo 
244     do
245         lang=`basename $file | sed 's/\.mo//'`
246         mkdir -p $Locale/$lang/LC_MESSAGES
247         cp $file $Locale/$lang/LC_MESSAGES/libardour.mo
248     done
249     for l in $LINGUAS
250     do
251       if [ -d $GTKQUARTZ_ROOT/share/locale/$l ] ; then
252           echo "Copying GTK i18n files for $l..."
253           cp -r $GTKQUARTZ_ROOT/share/locale/$l $Locale
254       else
255           # try with just the language spec
256           just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
257           if [ -d $GTKQUARTZ_ROOT/share/locale/$just_lang ] ; then
258               echo "Copying GTK i18n files for $l..."
259               cp -r $GTKQUARTZ_ROOT/share/locale/$just_lang $Locale
260           fi
261       fi
262     done
263 else
264     echo "Skipping NLS support"
265 fi
266
267 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
268 echo "Copying all Pango modules ..."
269 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
270 echo "Copying all GDK Pixbuf loaders ..."
271 cp -R $GDKPIXBUF_LOADERS/*.so $Frameworks/modules
272 # charset alias file
273 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
274
275 pwd=`pwd`
276
277 if test x$WITH_LADSPA != x ; then
278     if test x$SAE != x ; then
279         plugdir=sae_ladspa
280     elif test x$MIXBUS != x ; then
281         plugdir=mixbus_ladspa
282     else
283         plugdir=ladspa
284     fi
285     echo "Copying `ls $plugdir | wc -l` plugins ..."
286     cp -r $plugdir/* $Plugins
287 fi
288
289 # generate new Pango module file
290 cat > pangorc <<EOF 
291 [Pango]
292 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
293 EOF
294 env PANGO_RC_FILE=pangorc $GTKQUARTZ_ROOT/bin/pango-querymodules | sed "s?$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/?@executable_path/../lib/modules/?" > $Resources/pango.modules
295 rm pangorc
296
297 # generate a new GDK pixbufs loaders file
298 gdk-pixbuf-query-loaders | sed "s?$GDKPIXBUF_LOADERS/?@executable_path/../lib/modules/?" > $Resources/gdk-pixbuf.loaders
299
300 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
301 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.dylib $Frameworks
302 mkdir -p $Frameworks/clearlooks/engines
303 (cd $Frameworks/clearlooks/engines && ln -s $BUILD_ROOT/libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
304
305 # Control Surface shared libraries
306 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.dylib $Surfaces
307 # hack ... move libardour_cp back into Frameworks
308 mv $Surfaces/libardourcp*.dylib $Frameworks
309
310 # Panners
311 cp $BUILD_ROOT/libs/panners/*/lib*.dylib $Panners
312
313
314 # Export Formats/Presets
315 for f in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do 
316     echo ExportFormat: $f 
317     cp "$f" $ExportFormats ; 
318 done
319
320 # Session and Route templates
321 for f in $BUILD_ROOT/../templates/* ; do 
322     if [ -d "$f" ] ; then
323         echo Template: $f 
324         cp -r "$f" $Templates ; 
325     fi
326 done
327
328 # MidiMaps
329 # got to be careful with names here
330 for x in $BUILD_ROOT/../midi_maps/*.map ; do
331     cp "$x" $MidiMaps
332     echo Copied MIDI map $x 
333 done
334
335 # MIDNAM Patch Files
336 # got to be careful with names here
337 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
338     cp "$x" $PatchFiles
339     echo Copied MIDNAM file "$x"
340 done
341
342 # MackieControl data
343 # got to be careful with names here
344 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
345     cp "$x" $MackieControl
346     echo Copied Mackie Control file $x 
347 done
348
349 # VAMP plugins that we use
350 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
351
352 # SUIL Modules
353 cp $ARDOURSTACK_ROOT/lib/suil-0/libsuil* $Frameworks
354
355 while [ true ] ; do 
356     missing=false
357     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Panners/*.dylib $Surfaces/*.dylib $Plugins/*.so ; do 
358         if ! file $file | grep -qs Mach-O ; then
359             continue
360         fi
361         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | grep -v 'libjack\.'`
362         # echo -n "."
363         for dep in $deps ; do
364             base=`basename $dep`
365             if ! test -f $Frameworks/$base; then
366                 if echo $dep | grep -sq '^libs' ; then
367                     cp $BUILD_ROOT/$dep $Frameworks
368                 else
369                     cp $dep $Frameworks
370                 fi
371                 missing=true
372             fi
373         done
374     done
375     if test x$missing = xfalse ; then
376         # everything has been found
377         break
378     fi
379 done
380 echo
381
382 echo "Copying other stuff to $APPDIR  ..."
383
384 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings  $Resources
385
386 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Resources
387 cp ../../gtk2_ardour/mixer.bindings $Resources
388 cp ../../gtk2_ardour/step_editing.bindings $Resources
389 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
390
391 if test x$SAE != x ; then
392     cp $BUILD_ROOT/gtk2_ardour/SAE-de-keypad.bindings  $Resources
393     cp $BUILD_ROOT/gtk2_ardour/SAE-de-nokeypad.bindings  $Resources
394     cp $BUILD_ROOT/gtk2_ardour/SAE-us-keypad.bindings  $Resources
395     cp $BUILD_ROOT/gtk2_ardour/SAE-us-nokeypad.bindings  $Resources
396     cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
397     echo cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
398     cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
399     echo cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
400 else
401 #    cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
402 #    echo FOO cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
403     cp ../../instant.xml $Resources/instant.xml
404     echo cp ../../instant.xml $Resources/instant.xml
405 fi
406 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources
407 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources/ardour3_ui.conf
408 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Resources
409 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Resources
410
411 cp -r ../../gtk2_ardour/icons $Resources
412 cp -r ../../gtk2_ardour/pixmaps $Resources
413
414 # splash screen stuff
415 cp -R ../../gtk2_ardour/splash.png $Shared
416
417 # go through and recursively remove any .svn dirs in the bundle
418 for svndir in `find $APPDIR -name .svn -type dir`; do
419     rm -rf $svndir
420 done
421
422 # now fix up the executables
423 echo "Fixing up executable dependency names ..."
424 executables=$MAIN_EXECUTABLE
425 if test x$SAE != x ; then
426     executables="$executables"
427 fi
428
429 for exe in $executables; do
430     EXE=$APPROOT/MacOS/$exe
431     changes=""
432     for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
433       base=`basename $lib`
434       changes="$changes -change $lib @executable_path/../lib/$base"
435     done
436     if test "x$changes" != "x" ; then
437         install_name_tool $changes $EXE
438     fi
439 done
440
441 echo "Fixing up library names ..."
442 # now do the same for all the libraries we include
443 for libdir in $Frameworks $Frameworks/modules $Surfaces $Panners ; do
444
445     libbase=`basename $libdir`
446     
447     for dylib in $libdir/*.dylib $libdir/*.so ; do
448         
449        # skip symlinks
450         
451         if test -L $dylib ; then
452             continue
453         fi
454         
455         # change all the dependencies
456         
457         changes=""
458         for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
459             base=`basename $lib`
460             if echo $lib | grep -s libbase; then
461                 changes="$changes -change $lib @executable_path/../$libbase/$base"
462             else
463                 changes="$changes -change $lib @executable_path/../lib/$base"
464             fi
465         done
466         
467         if test "x$changes" != x ; then
468             if  install_name_tool $changes $dylib ; then
469                 :
470             else
471                 exit 1
472             fi
473         fi
474         
475         # now the change what the library thinks its own name is
476         
477         base=`basename $dylib`
478         install_name_tool -id @executable_path/../$libbase/$base $dylib
479     done
480 done
481
482 #
483 # and now ... the DMG
484
485
486 rm -rf $PRODUCT_PKG_DIR
487 mkdir $PRODUCT_PKG_DIR
488
489 if [ x$SAE != x ] ; then
490         
491     # SAE packaging
492     
493     echo "Creating SAE packaging directory"
494     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
495     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
496     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
497     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
498     
499 elif [ x$MIXBUS != x ] ; then
500
501      # Mixbus packaging
502
503     echo "Creating Mixbus packaging directory"
504     mv $APPDIR $PRODUCT_PKG_DIR/
505     cp MixBus_Install_QuickStart.pdf "$PRODUCT_PKG_DIR/Mixbus Install & Quick Start Guide.pdf"
506
507 else 
508
509     echo "Creating $APPNAME packaging directory"
510     mv $APPDIR $PRODUCT_PKG_DIR/
511
512 fi
513
514 echo "Building DMG ..."
515
516 # UC_DMG=$APPNAME-${release_version}-${svn_version}-UC.dmg
517 # FINAL_DMG=$APPNAME-${release_version}-${svn_version}.dmg
518 UC_DMG=$APPNAME-${release_version}-${svn_version}.dmg
519
520 rm -f $UC_DMG
521 echo hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
522 hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
523
524 # compress it
525 # echo "Compressing DMG ..."
526 # rm -f $FINAL_DMG
527 # hdiutil convert $UC_DMG -format UDBZ -o $FINAL_DMG
528
529 echo "Done."
530