2fa6c6d4602fc93b4cb041955f87e5f5e7952f37
[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 Plugins=$APPROOT/Plugins
101 Surfaces=$APPROOT/Surfaces
102 Panners=$APPROOT/Panners
103 MidiMaps=$APPROOT/MidiMaps
104 ExportFormats=$APPROOT/ExportFormats
105 Templates=$APPROOT/Templates
106 Shared=$Resources/share
107 Etc=$Resources/etc
108 Locale=$Resources/locale
109
110 if [ x$PRINT_SYSDEPS != x ] ; then
111 #
112 # print system dependencies
113 #
114
115     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
116         if ! file $file | grep -qs Mach-O ; then
117             continue
118         fi
119         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
120     done | sort | uniq
121     exit 0
122 fi
123
124 echo "Removing old $APPDIR tree ..."
125
126 rm -rf $APPDIR
127
128 echo "Building new app directory structure ..."
129
130 # only bother to make the longest paths
131
132 mkdir -p $APPROOT/MacOS
133 mkdir -p $APPROOT/Resources
134 mkdir -p $Plugins
135 mkdir -p $Surfaces
136 mkdir -p $Panners
137 mkdir -p $MidiMaps
138 mkdir -p $ExportFormats
139 mkdir -p $Templates
140 mkdir -p $Frameworks/modules
141 mkdir -p $Shared/templates
142 mkdir -p $Etc
143
144 # maybe set variables
145 env=""
146 if test x$SAE != x ; then
147     appname="Ardour3/SAE"
148     env="$env<key>ARDOUR_SAE</key><string>true</string>"
149     #
150     # current default for SAE version is German keyboard layout without a keypad
151     #
152     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de-nokeypad</string>"
153     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui_sae.conf</string>"
154     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark_sae.rc</string>"
155 elif test x$MIXBUS != x ; then
156     appname="Ardour3/Mixbus"
157     env="$env<key>ARDOUR_MIXBUS</key><string>true</string>"
158     #
159     # current default for MIXBUS version is US keyboard layout without a keypad
160     #
161     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>us-nokeypad</string>"
162     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui.conf</string>"
163     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark.rc</string>"
164 else
165     appname="Ardour3"
166 fi
167
168 #
169 # if we're not going to bundle JACK, make sure we can find
170 # jack in the places where it might be
171 #
172
173 env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>"
174 env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
175
176 env="<key>LSEnvironment</key><dict>$env<key>ARDOUR_BUNDLED</key><string>true</string></dict>"
177
178 # edit plist
179 sed -e "s?@ENV@?$env?g" \
180     -e "s?@VERSION@?$release_version/$svn_version?g" \
181     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
182 # and plist strings
183 sed -e "s?@APPNAME@?$appname?" \
184     -e "s?@ENV@?$env?g" \
185     -e "s?@VERSION@?$release_version/$svn_version?g" \
186     -e "s?@INFOSTRING@?$info_string?g" < InfoPlist.strings.in > Resources/InfoPlist.strings || exit 1
187
188 # copy static files
189
190 cp Info.plist $APPROOT
191 cp -R Resources $APPROOT
192
193 #
194 # if we build a bundle without jack, then
195 # make the Ardour3 executable a helper
196 # script that checks to see if JACK is
197 # installed.
198 #
199
200 cp startup_script $APPROOT/MacOS/Ardour3
201 chmod 775 $APPROOT/MacOS/Ardour3
202 MAIN_EXECUTABLE=Ardour3.bin
203
204 echo "Copying ardour executable ...."
205 cp $BUILD_ROOT/gtk2_ardour/ardour-$release_version $APPROOT/MacOS/$MAIN_EXECUTABLE
206 if test x$SAE != x ; then
207     # cp $BUILD_ROOT/gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
208     cp  Ardour3-SAE.icns $Resources/appIcon.icns
209 elif test x$MIXBUS != x ; then
210     cp  Mixbus.icns $Resources/appIcon.icns
211 else
212     cp  Ardour3.icns $Resources/appIcon.icns
213 fi
214 cp  typeArdour.icns $Resources/
215 if test x$STRIP != x ; then
216     strip $APPROOT/MacOS/Ardour3
217 fi
218
219 # copy locale files
220 if test x$WITH_NLS != x ; then
221     echo "NLS support ..."
222     echo "I hope you remembered to run scons msgupdate!"
223     LINGUAS=
224     for file in $BUILD_ROOT/gtk2_ardour/*.mo 
225     do
226         lang=`basename $file | sed 's/\.mo//'`
227         mkdir -p $Locale/$lang/LC_MESSAGES
228         cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
229         LINGUAS="$LINGUAS $lang"
230     done
231     for file in $BUILD_ROOT/libs/ardour/*.mo 
232     do
233         lang=`basename $file | sed 's/\.mo//'`
234         mkdir -p $Locale/$lang/LC_MESSAGES
235         cp $file $Locale/$lang/LC_MESSAGES/libardour.mo
236     done
237     for l in $LINGUAS
238     do
239       if [ -d $GTKQUARTZ_ROOT/share/locale/$l ] ; then
240           echo "Copying GTK i18n files for $l..."
241           cp -r $GTKQUARTZ_ROOT/share/locale/$l $Locale
242       else
243           # try with just the language spec
244           just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
245           if [ -d $GTKQUARTZ_ROOT/share/locale/$just_lang ] ; then
246               echo "Copying GTK i18n files for $l..."
247               cp -r $GTKQUARTZ_ROOT/share/locale/$just_lang $Locale
248           fi
249       fi
250     done
251 else
252     echo "Skipping NLS support"
253 fi
254
255 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
256 echo "Copying all Pango modules ..."
257 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
258 echo "Copying all GDK Pixbuf loaders ..."
259 cp -R $GDKPIXBUF_LOADERS/*.so $Frameworks/modules
260 # charset alias file
261 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
262
263 pwd=`pwd`
264
265 if test x$WITH_LADSPA != x ; then
266     if test x$SAE != x ; then
267         plugdir=sae_ladspa
268     elif test x$MIXBUS != x ; then
269         plugdir=mixbus_ladspa
270     else
271         plugdir=ladspa
272     fi
273     echo "Copying `ls $plugdir | wc -l` plugins ..."
274     cp -r $plugdir/* $Plugins
275 fi
276
277 # generate new Pango module file
278 cat > pangorc <<EOF 
279 [Pango]
280 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
281 EOF
282 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
283 rm pangorc
284
285 # generate a new GDK pixbufs loaders file
286 gdk-pixbuf-query-loaders | sed "s?$GDKPIXBUF_LOADERS/?@executable_path/../Frameworks/modules/?" > $Resources/gdk-pixbuf.loaders
287
288 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
289 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.dylib $Frameworks
290 mkdir -p $Frameworks/clearlooks/engines
291 (cd $Frameworks/clearlooks/engines && ln -s $BUILD_ROOT/libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
292
293 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.dylib $Surfaces
294 cp $BUILD_ROOT/libs/panners/*/lib*.dylib $Panners
295 (cd ../../export && 
296     for f in *.preset ; do 
297         echo ExportFormat: $f; cp "$f" ../tools/osx_packaging/$ExportFormats ; 
298 done)
299 (cd $BUILD_ROOT/templates && \
300     for f in * ; do 
301         echo Template: $f ; cp -r "$f" ../../tools/osx_packaging/$Templates ; 
302 done)
303
304 # MIDI maps
305 cp ../../midi_maps/*.map $MidiMaps
306
307 # VAMP plugins that we use
308 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
309
310 while [ true ] ; do 
311     missing=false
312     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Panners/*.dylib $Surfaces/*.dylib $Plugins/*.so ; do 
313         if ! file $file | grep -qs Mach-O ; then
314             continue
315         fi
316         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | grep -v 'libjack\.'`
317         # echo -n "."
318         for dep in $deps ; do
319             base=`basename $dep`
320             if ! test -f $Frameworks/$base; then
321                 if echo $dep | grep -sq '^libs' ; then
322                     cp $BUILD_ROOT/$dep $Frameworks
323                 else
324                     cp $dep $Frameworks
325                 fi
326                 missing=true
327             fi
328         done
329     done
330     if test x$missing = xfalse ; then
331         # everything has been found
332         break
333     fi
334 done
335 echo
336
337 echo "Copying other stuff to $APPDIR  ..."
338
339 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings  $Resources
340
341 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Resources
342 cp ../../gtk2_ardour/mixer.bindings $Resources
343 cp ../../gtk2_ardour/step_editing.bindings $Resources
344 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
345
346 if test x$SAE != x ; then
347     cp $BUILD_ROOT/gtk2_ardour/SAE-de-keypad.bindings  $Resources
348     cp $BUILD_ROOT/gtk2_ardour/SAE-de-nokeypad.bindings  $Resources
349     cp $BUILD_ROOT/gtk2_ardour/SAE-us-keypad.bindings  $Resources
350     cp $BUILD_ROOT/gtk2_ardour/SAE-us-nokeypad.bindings  $Resources
351     cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
352     echo cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
353     cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
354     echo cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
355 else
356 #    cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
357 #    echo FOO cp $BUILD_ROOT/ardour_system.rc $Resources/ardour_system.rc
358     cp ../../instant.xml $Resources/instant.xml
359     echo cp ../../instant.xml $Resources/instant.xml
360 fi
361 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources
362 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources/ardour3_ui.conf
363 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Resources
364 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Resources
365
366 cp -r ../../gtk2_ardour/icons $Resources
367 cp -r ../../gtk2_ardour/pixmaps $Resources
368
369 # splash screen stuff
370 cp -R ../../gtk2_ardour/splash.png $Shared
371
372 # go through and recursively remove any .svn dirs in the bundle
373 for svndir in `find $APPDIR -name .svn -type dir`; do
374     rm -rf $svndir
375 done
376
377 # now fix up the executables
378 echo "Fixing up executable dependency names ..."
379 executables=$MAIN_EXECUTABLE
380 if test x$SAE != x ; then
381     executables="$executables"
382 fi
383
384 for exe in $executables; do
385     EXE=$APPROOT/MacOS/$exe
386     changes=""
387     for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
388       base=`basename $lib`
389       changes="$changes -change $lib @executable_path/../Frameworks/$base"
390     done
391     if test "x$changes" != "x" ; then
392         install_name_tool $changes $EXE
393     fi
394 done
395
396 echo "Fixing up library names ..."
397 # now do the same for all the libraries we include
398 for libdir in $Frameworks $Frameworks/modules $Surfaces $Panners ; do
399
400     libbase=`basename $libdir`
401     
402     for dylib in $libdir/*.dylib $libdir/*.so ; do
403         
404        # skip symlinks
405         
406         if test -L $dylib ; then
407             continue
408         fi
409         
410         # change all the dependencies
411         
412         changes=""
413         for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
414             base=`basename $lib`
415             if echo $lib | grep -s libbase; then
416                 changes="$changes -change $lib @executable_path/../$libbase/$base"
417             else
418                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
419             fi
420         done
421         
422         if test "x$changes" != x ; then
423             if  install_name_tool $changes $dylib ; then
424                 :
425             else
426                 exit 1
427             fi
428         fi
429         
430         # now the change what the library thinks its own name is
431         
432         base=`basename $dylib`
433         install_name_tool -id @executable_path/../$libbase/$base $dylib
434     done
435 done
436
437 #
438 # and now ... the DMG
439
440
441 rm -rf $PRODUCT_PKG_DIR
442 mkdir $PRODUCT_PKG_DIR
443
444 if [ x$SAE != x ] ; then
445         
446     # SAE packaging
447     
448     echo "Creating SAE packaging directory"
449     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
450     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
451     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
452     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
453     
454 elif [ x$MIXBUS != x ] ; then
455
456      # Mixbus packaging
457
458     echo "Creating Mixbus packaging directory"
459     mv $APPDIR $PRODUCT_PKG_DIR/
460     cp MixBus_Install_QuickStart.pdf "$PRODUCT_PKG_DIR/Mixbus Install & Quick Start Guide.pdf"
461
462 else 
463
464     echo "Creating $APPNAME packaging directory"
465     mv $APPDIR $PRODUCT_PKG_DIR/
466
467 fi
468
469 echo "Building DMG ..."
470
471 # UC_DMG=$APPNAME-${release_version}-${svn_version}-UC.dmg
472 # FINAL_DMG=$APPNAME-${release_version}-${svn_version}.dmg
473 UC_DMG=$APPNAME-${release_version}-${svn_version}.dmg
474
475 rm -f $UC_DMG
476 echo hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
477 hdiutil create $UC_DMG -volname $APPNAME-$release_version -fs HFS+ -srcfolder $PRODUCT_PKG_DIR
478
479 # compress it
480 # echo "Compressing DMG ..."
481 # rm -f $FINAL_DMG
482 # hdiutil convert $UC_DMG -format UDBZ -o $FINAL_DMG
483
484 echo "Done."
485