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