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