4d5ef3ccc0188bafa0e9c4bd9ed3a8486f03a84f
[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
372 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Resources
373 cp ../../gtk2_ardour/mixer.bindings $Resources
374 cp ../../gtk2_ardour/step_editing.bindings $Resources
375 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
376
377 if test x$SAE != x ; then
378     cp $BUILD_ROOT/gtk2_ardour/SAE-de-keypad.bindings  $Resources
379     cp $BUILD_ROOT/gtk2_ardour/SAE-de-nokeypad.bindings  $Resources
380     cp $BUILD_ROOT/gtk2_ardour/SAE-us-keypad.bindings  $Resources
381     cp $BUILD_ROOT/gtk2_ardour/SAE-us-nokeypad.bindings  $Resources
382     cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
383     echo cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
384     cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
385     echo cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
386 else
387 #    cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
388 #    echo FOO cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
389     cp ../../instant.xml $Resources/instant.xml
390     echo cp ../../instant.xml $Resources/instant.xml
391 fi
392 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources
393 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources/ardour3_ui.conf
394 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Resources
395 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Resources
396
397 cp -r ../../gtk2_ardour/icons $Resources
398 cp -r ../../gtk2_ardour/pixmaps $Resources
399
400 # go through and recursively remove any .svn dirs in the bundle
401 for svndir in `find $APPDIR -name .svn -type dir`; do
402     rm -rf $svndir
403 done
404
405 # now fix up the executables
406 echo "Fixing up executable dependency names ..."
407 executables=$MAIN_EXECUTABLE
408 if test x$INTERNAL_JACK != x ; then
409     executables="$executables jackd"
410 fi
411 if test x$SAE != x ; then
412     executables="$executables"
413 fi
414
415 for exe in $executables; do
416     EXE=$APPROOT/MacOS/$exe
417     changes=""
418     if test x$INTERNAL_JACK != x ; then
419         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}'` ; do
420             base=`basename $lib`
421             changes="$changes -change $lib @executable_path/../Frameworks/$base"
422         done
423     else
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     fi
429     if test "x$changes" != "x" ; then
430         install_name_tool $changes $EXE
431     fi
432 done
433
434 echo "Fixing up library names ..."
435 # now do the same for all the libraries we include
436 for dylib in $JACK_SHARED_OBJECTS $Frameworks/*.dylib $Frameworks/modules/*.so $Surfaces/*.dylib ; do
437     # skip symlinks
438     if test ! -L $dylib ; then
439         
440         # change all the dependencies
441
442         changes=""
443         if test x$INTERNAL_JACK != x ; then
444             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}'` ; do
445                 base=`basename $lib`
446                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
447             done
448         else
449             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
450                 base=`basename $lib`
451                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
452             done
453         fi
454
455         if test "x$changes" != x ; then
456             if  install_name_tool $changes $dylib ; then
457                 :
458             else
459                 exit 1
460             fi
461         fi
462
463         # now the change what the library thinks its own name is
464
465         base=`basename $dylib`
466         install_name_tool -id @executable_path/../Frameworks/$base $dylib
467     fi
468 done
469
470 #
471 # and now ... the DMG
472
473
474 rm -rf $PRODUCT_PKG_DIR
475 mkdir $PRODUCT_PKG_DIR
476
477 if [ x$SAE != x ] ; then
478         
479     # SAE packaging
480     
481     echo "Creating SAE packaging directory"
482     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
483     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
484     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
485     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
486     
487 elif [ x$MIXBUS != x ] ; then
488
489      # Mixbus packaging
490
491     echo "Creating Mixbus packaging directory"
492     mv $APPDIR $PRODUCT_PKG_DIR/
493     cp MixBus_Install_QuickStart.pdf "$PRODUCT_PKG_DIR/Mixbus Install & Quick Start Guide.pdf"
494     
495     if [ -x $EXTERNAL_JACK != x ] ; then
496         cp $EXTERNAL_JACK $PRODUCT_PKG_DIR
497     fi
498     
499         # create dmg
500 else 
501
502     echo "Creating $APPNAME packaging directory"
503     mv $APPDIR $PRODUCT_PKG_DIR/
504
505 fi
506
507 echo "Building DMG ..."
508
509 # UC_DMG=$APPNAME-${release_version}-${svn_version}-UC.dmg
510 # FINAL_DMG=$APPNAME-${release_version}-${svn_version}.dmg
511 UC_DMG=$APPNAME-${release_version}-${svn_version}.dmg
512
513 rm -f $UC_DMG
514 echo hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
515 hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
516
517 # compress it
518 # echo "Compressing DMG ..."
519 # rm -f $FINAL_DMG
520 # hdiutil convert $UC_DMG -format UDBZ -o $FINAL_DMG
521
522 echo "Done."
523