4160b07d5614056b3ac50398c21267de9bda96cc
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 # script for pulling together a MacOSX app bundle.
4
5 GTKQUARTZ_ROOT=/opt/gtk
6
7 SAE=
8 WITH_JACK=1
9 WITH_LADSPA=1
10 STRIP=1
11 PRINT_SYSDEPS=
12
13 while [ $# -gt 0 ] ; do
14     echo "arg = $1"
15     case $1 in
16         --sae) SAE=1 ; shift ;;
17         --nojack) WITH_JACK= ; shift ;;
18         --noladspa) WITH_LADSPA= ; shift ;;
19         --nostrip) STRIP= ; shift ;;
20         --sysdeps) PRINT_SYSDEPS=1; shift ;;
21     esac
22 done
23
24 version=`grep -m 1 '^ardour_version' ../../SConstruct | cut -d' ' -f 3 | sed "s/'//g"`
25 echo "Version is $version"
26 info_string="$version built on `hostname` by `whoami` on `date`"
27 echo "Info string is $info_string"
28
29 # setup directory structure
30
31 APPROOT=Ardour2.app/Contents
32 Frameworks=$APPROOT/Frameworks
33 Resources=$APPROOT/Resources
34 Plugins=$APPROOT/Plugins
35 Shared=$Resources/share
36 Etc=$Resources/etc
37
38 if [ x$PRINT_SYSDEPS != x ] ; then
39 #
40 # print system dependencies
41 #
42
43     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
44         if ! file $file | grep -qs Mach-O ; then
45             continue
46         fi
47         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
48     done | sort | uniq
49     exit 0
50 fi
51
52 echo "Removing old Ardour2.app tree ..."
53
54 rm -rf Ardour2.app
55
56 echo "Building new app directory structure ..."
57
58 # only bother to make the longest paths
59
60 mkdir -p $APPROOT/MacOS
61 mkdir -p $APPROOT/Resources
62 mkdir -p $APPROOT/Plugins
63 mkdir -p $Frameworks/modules
64 mkdir -p $Shared/templates
65 mkdir -p $Etc
66
67 # maybe set variables
68 env=""
69 if test x$SAE != x ; then
70     env="$env<key>ARDOUR_SAE</key><string>true</string>"
71     #
72     # current default for SAE version is German keyboard layout
73     #
74     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de</string>"
75 fi
76
77 #
78 # if we're not going to bundle JACK, make sure we can find
79 # jack in the places where it might be
80 #
81
82 if test x$WITH_JACK != x ; then
83     env="$env<key>ARDOUR_WITH_JACK</key><string>true</string>"
84 else
85     env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin</string>"
86     env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
87 fi
88
89 env="<key>LSEnvironment</key><dict><key>ARDOUR_BUNDLED</key><string>true</string>$env</dict>"
90
91 # edit plist
92 sed -e "s?@ENV@?$env?g" \
93     -e "s?@VERSION@?$version?g" \
94     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
95
96 # copy static files
97
98 cp Info.plist $APPROOT
99 cp -R Resources $APPROOT
100
101 echo "Copying ardour executable ...."
102 cp ../../gtk2_ardour/ardour-$version $APPROOT/MacOS/Ardour2
103 if test x$STRIP != x ; then
104     strip $APPROOT/MacOS/Ardour2
105 fi
106 if test x$WITH_JACK != x ; then
107     cp /usr/local/lib/jack/jack_coreaudio.so $Frameworks
108     cp /usr/local/bin/jackd $APPROOT/MacOS
109 fi
110
111 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
112 echo "Copying all Pango modules ..."
113 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
114 echo "Copying all GDK Pixbuf loaders ..."
115 cp -R $GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/*.so $Frameworks/modules
116 # charset alias file
117 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
118
119 pwd=`pwd`
120
121 if test x$WITH_LADSPA != x ; then
122     echo "Copying `ls ladspa | wc -l` plugins ..."
123     cp -r ladspa/* $Plugins
124 fi
125
126 # generate new Pango module file
127 cat > pangorc <<EOF 
128 [Pango]
129 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
130 EOF
131 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
132 rm pangorc
133
134 # generate a new GDK pixbufs loaders file
135 sed "s?$GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/?@executable_path/../Frameworks/modules/?" < $GTKQUARTZ_ROOT/etc/gtk-2.0/gdk-pixbuf.loaders > $Resources/gdk-pixbuf.loaders
136
137 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
138 cp ../../libs/clearlooks/libclearlooks.dylib $Frameworks
139 mkdir -p $Frameworks/clearlooks/engines
140 (cd $Frameworks/clearlooks/engines && ln -s ../../libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
141
142 # XXX STILL NEED TO DO PANNERS FOR TRUNK
143
144 cp ../../libs/surfaces/*/libardour_*.dylib $Frameworks
145
146 while [ true ] ; do 
147     missing=false
148     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
149         if ! file $file | grep -qs Mach-O ; then
150             continue
151         fi
152         if test x$WITH_JACK != x ; then
153             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)"`
154         else
155             # do not include libjack
156             deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | grep -v 'libjack\.'`
157         fi
158         echo -n "."
159         for dep in $deps ; do
160             base=`basename $dep`
161             if ! test -f $Frameworks/$base; then
162                 if echo $dep | grep -sq '^libs' ; then
163                     cp ../../$dep $Frameworks
164                 else
165                     cp $dep $Frameworks
166                 fi
167                 missing=true
168             fi
169         done
170     done
171     if test x$missing = xfalse ; then
172         # everything has been found
173         break
174     fi
175 done
176 echo
177
178 echo "Copying other stuff to Ardour2.app  ..."
179
180 cp ../../gtk2_ardour/ardour.bindings  $Resources
181 cp ../../gtk2_ardour/ardour-sae-ansi.bindings  $Resources
182 cp ../../gtk2_ardour/ardour-sae-de.bindings  $Resources
183 cp ../../gtk2_ardour/ardour.menus $Resources
184 cp ../../gtk2_ardour/ardour-sae.menus $Resources
185 cp ../../ardour_system.rc $Resources
186 cp ../../gtk2_ardour/ardour2_ui_default.conf $Resources
187 cp ../../gtk2_ardour/ardour2_ui_light.rc $Resources
188 cp ../../gtk2_ardour/ardour2_ui_dark.rc $Resources
189
190 cp -r ../../gtk2_ardour/icons $Resources
191 cp -r ../../gtk2_ardour/pixmaps $Resources
192
193 # share stuff
194
195 cp -R ../../gtk2_ardour/splash.png $Shared
196 cp ../../templates/*.template $Shared/templates/
197
198 # go through and recursively remove any .svn dirs in the bundle
199 for svndir in `find Ardour2.app -name .svn -type dir`; do
200     rm -rf $svndir
201 done
202
203 # now fix up the executables
204 echo "Fixing up executable dependency names ..."
205 executables="Ardour2"
206 if test x$WITH_JACK != x ; then
207     executables="$executables jackd"
208 fi
209
210 for exe in $executables; do
211     EXE=$APPROOT/MacOS/$exe
212     changes=""
213     if test x$WITH_JACK != x ; then
214         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
215             base=`basename $lib`
216             changes="$changes -change $lib @executable_path/../Frameworks/$base"
217         done
218     else
219         for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
220             base=`basename $lib`
221             changes="$changes -change $lib @executable_path/../Frameworks/$base"
222         done
223     fi
224     if test "x$changes" != "x" ; then
225         install_name_tool $changes $EXE
226     fi
227 done
228
229 echo "Fixing up library names ..."
230 # now do the same for all the libraries we include
231 for dylib in $Frameworks/*.dylib $Frameworks/modules/*.so ; do
232     # skip symlinks
233     if test ! -L $dylib ; then
234         
235         # change all the dependencies
236
237         changes=""
238         if test x$WITH_JACK != x ; then
239             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
240                 base=`basename $lib`
241                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
242             done
243         else
244             for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
245                 base=`basename $lib`
246                 changes="$changes -change $lib @executable_path/../Frameworks/$base"
247             done
248         fi
249
250         if test "x$changes" != x ; then
251             if  install_name_tool $changes $dylib ; then
252                 :
253             else
254                 exit 1
255             fi
256         fi
257
258         # now the change what the library thinks its own name is
259
260         base=`basename $dylib`
261         install_name_tool -id @executable_path/../Frameworks/$base $dylib
262     fi
263 done
264
265 echo "Done."
266