improvements to build system for OSX native
[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
11 while [ $# -gt 0 ] ; do
12     echo "arg = $1"
13     case $1 in
14         --sae) SAE=1 ; shift ;;
15         --nojack) WITH_JACK= ; shift ;;
16         --noladpsa) WITH_LADSPA= ; shift ;;
17     esac
18 done
19
20 version=`grep -m 1 '^ardour_version' ../../SConstruct | cut -d' ' -f 3 | sed "s/'//g"`
21 echo "Version is $version"
22
23 # setup directory structure
24
25 APPROOT=Ardour2.app/Contents
26 Frameworks=$APPROOT/Frameworks
27 Resources=$APPROOT/Resources
28 Plugins=$APPROOT/Plugins
29 Shared=$Resources/share
30 Etc=$Resources/etc
31
32 echo "Removing old Ardour2.app tree ..."
33
34 rm -rf Ardour2.app
35
36 echo "Building new app directory structure ..."
37
38 # only bother to make the longest paths
39
40 mkdir -p $APPROOT/MacOS
41 mkdir -p $APPROOT/Resources
42 mkdir -p $APPROOT/Plugins
43 mkdir -p $Frameworks/modules
44 mkdir -p $Shared/templates
45 mkdir -p $Etc
46
47 # maybe set variables
48 env=""
49 if test x$SAE != x ; then
50     env="$env<key>ARDOUR_SAE</key><string>true</string>"
51 fi
52
53 if test x$WITH_JACK != x ; then
54     env="$env<key>ARDOUR_WITH_JACK</key><string>true</string>"
55 fi
56
57 env="<key>LSEnvironment</key><dict><key>ARDOUR_BUNDLED</key><string>true</string>$env</dict>"
58
59 # edit plist
60 sed -e "s?@ENV@?$env?g" -e "s?@VERSION@?$version?g" < Info.plist.in > Info.plist
61
62 # copy static files
63
64 cp Info.plist $APPROOT
65 cp -R Resources $APPROOT
66
67 echo "Copying ardour executable ...."
68 cp ../../gtk2_ardour/ardour-$version $APPROOT/MacOS/Ardour2
69 strip $APPROOT/MacOS/Ardour2
70 if test x$WITH_JACK != x ; then
71     cp /usr/local/lib/jack/jack_coreaudio.so $Frameworks
72     cp /usr/local/bin/jackd $APPROOT/MacOS
73 fi
74
75 cp -R $GTKQUARTZ_ROOT/etc/* $Etc
76 echo "Copying all Pango modules ..."
77 cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
78 echo "Copying all GDK Pixbuf loaders ..."
79 cp -R $GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/*.so $Frameworks/modules
80 # charset alias file
81 cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
82
83 pwd=`pwd`
84
85 if test x$WITH_LADSPA != x ; then
86     echo "Copying `ls ladspa | wc -l` plugins ..."
87     cp -r ladspa/* $Plugins
88 fi
89
90 # generate new Pango module file
91 cat > pangorc <<EOF 
92 [Pango]
93 ModulesPath=$GTKQUARTZ_ROOT/lib/pango/1.6.0/modules
94 EOF
95 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
96 rm pangorc
97
98 # generate a new GDK pixbufs loaders file
99 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
100
101 # this one is special - we will set GTK_PATH to $Frameworks/clearlooks
102 cp ../../libs/clearlooks/libclearlooks.dylib $Frameworks
103 mkdir -p $Frameworks/clearlooks/engines
104 (cd $Frameworks/clearlooks/engines && ln -s ../../libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
105
106 # XXX STILL NEED TO DO SURFACES AND PANNERS
107
108 cp ../../libs/surfaces/control_protocol/libardour_cp.dylib $Frameworks
109
110 while [ true ] ; do 
111     missing=false
112     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
113         if ! file $file | grep -qs Mach-O ; then
114             continue
115         fi
116         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)"`
117         echo -n "."
118         for dep in $deps ; do
119             base=`basename $dep`
120             if ! test -f $Frameworks/$base; then
121                 if echo $dep | grep -sq '^libs' ; then
122                     cp ../../$dep $Frameworks
123                 else
124                     cp $dep $Frameworks
125                 fi
126                 missing=true
127             fi
128         done
129     done
130     if test x$missing = xfalse ; then
131         # everything has been found
132         break
133     fi
134 done
135 echo
136
137 echo "Copying other stuff to Ardour2.app  ..."
138
139 cp ../../gtk2_ardour/ardour.bindings  $Resources
140 cp ../../gtk2_ardour/ardour.menus $Resources
141 cp ../../gtk2_ardour/ardour-sae.menus $Resources
142 cp ../../ardour_system.rc $Resources
143 cp ../../gtk2_ardour/ardour2_ui_default.conf $Resources
144 cp ../../gtk2_ardour/ardour2_ui_light.rc $Resources
145 cp ../../gtk2_ardour/ardour2_ui_dark.rc $Resources
146
147 cp -r ../../gtk2_ardour/icons $Resources
148 cp -r ../../gtk2_ardour/pixmaps $Resources
149
150 # share stuff
151
152 cp -R ../../gtk2_ardour/splash.png $Shared
153 cp ../../templates/*.template $Shared/templates/
154
155 # go through and recursively remove any .svn dirs in the bundle
156 for svndir in `find Ardour2.app -name .svn -type dir`; do
157     rm -rf $svndir
158 done
159
160 # now fix up the executables
161 echo "Fixing up executable dependency names ..."
162 executables=Ardour2
163 if test x$WITH_JACK != x ; then
164     executables="$executables jackd"
165 fi
166
167 for exe in $executables; do
168     EXE=$APPROOT/MacOS/$exe
169     changes=""
170     for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
171         base=`basename $lib`
172         changes="$changes -change $lib @executable_path/../Frameworks/$base"
173     done
174     if test "x$changes" != "x" ; then
175         install_name_tool $changes $EXE
176     fi
177 done
178
179 echo "Fixing up library names ..."
180 # now do the same for all the libraries we include
181 for dylib in $Frameworks/*.dylib $Frameworks/modules/*.so ; do
182     # skip symlinks
183     if test ! -L $dylib ; then
184         
185         # change all the dependencies
186
187         changes=""
188         for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
189             base=`basename $lib`
190             changes="$changes -change $lib @executable_path/../Frameworks/$base"
191         done
192
193         if test "x$changes" != x ; then
194             if  install_name_tool $changes $dylib ; then
195                 :
196             else
197                 exit 1
198             fi
199         fi
200
201         # now the change what the library thinks its own name is
202
203         base=`basename $dylib`
204         install_name_tool -id @executable_path/../Frameworks/$base $dylib
205     fi
206 done
207
208 echo "Done."
209