add linux bundle tools from 2.X
[ardour.git] / tools / linux_packaging / build
1 #!/bin/bash
2
3 #
4
5 . ./buildenv
6
7 # script for pulling together a Linux app bundle.
8
9 SAE=
10 MIXBUS=
11 INTERNAL_JACK=1
12 WITH_LADSPA=0
13 STRIP=1
14 PRINT_SYSDEPS=
15 WITH_NLS=
16 EXTERNAL_JACK=
17
18 while [ $# -gt 0 ] ; do
19     echo "arg = $1"
20     case $1 in
21
22         #
23         # top level build targets
24         #
25
26         --sae) WITH_NLS= ; 
27                SAE=1 ; 
28                INTERNAL_JACK=1; 
29                WITH_LADSPA=1; 
30                STRIP= ; 
31                APPNAME=Ardour ;
32                shift ;;
33         --mixbus) MIXBUS=1; 
34                   WITH_NLS=1 ; 
35                   SAE= ; 
36                   INTERNAL_JACK=; 
37                   WITH_LADSPA=; 
38                   STRIP= ; 
39                   APPNAME=Mixbus ;
40                   shift ;;
41         --public) WITH_NLS=1 ; 
42                   SAE= ; 
43                   INTERNAL_JACK=; 
44                   WITH_LADSPA=; 
45                   STRIP= ; 
46                   APPNAME=Ardour ;
47                   shift ;;
48         --allinone) SAE= ; 
49                     WITH_NLS= ; 
50                     INTERNAL_JACK=1; 
51                     WITH_LADSPA=1; 
52                     STRIP= ; 
53                     shift ;;
54         --test) SAE= ; INTERNAL_JACK=; WITH_LADSPA=; STRIP= ; shift ;;
55
56         #
57         # specific build flags
58         #
59
60         --nojack) INTERNAL_JACK= ; shift ;;
61         --noladspa) WITH_LADSPA= ; shift ;;
62         --nostrip) STRIP= ; shift ;;
63         --sysdeps) PRINT_SYSDEPS=1; shift ;;
64         --nls) WITH_NLS=1 ; shift ;;
65         --external_jack) EXTERNAL_JACK=$2; shift ; shift ;;
66     esac
67 done
68
69 if [ x$EXTERNAL_JACK != x -a x$INTERNAL_JACK != x ] ; then
70     echo "It makes no sense to package JACK internally and externally. Please pick one."
71 fi
72
73 release_version=`grep -m 1 '^ardour_version' ../../SConstruct | cut -d' ' -f 3 | sed "s/'//g"`
74 svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d' ' -f 6 | sed 's/[";]//g'`
75 echo "Version is $release_version / $svn_version"
76 info_string="$release_version/$svn_version built on `hostname` by `whoami` on `date`"
77 echo "Info string is $info_string"
78
79 # setup directory structure
80
81 APPDIR=${APPNAME}
82 APPBIN=$APPDIR/bin
83 APPLIB=$APPDIR/lib
84 Libraries=$APPLIB
85 Etc=$APPDIR/etc
86 Shared=$APPDIR/share
87 Plugins=$APPLIB/plugins
88 Surfaces=$APPLIB/surfaces
89 Panners=$APPLIB/panners
90 Locale=$Shared/locale
91 Modules=$Libraries/modules
92 Loaders=$Libraries/loaders
93
94 if [ x$PRINT_SYSDEPS != x ] ; then
95 #
96 # print system dependencies
97 #
98
99     for file in $APPBIN/* $Libraries/* $Modules/* $Plugins/*.so ; do 
100         if ! file $file | grep -qs Mach-O ; then
101             continue
102         fi
103         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
104     done | sort | uniq
105     exit 0
106 fi
107
108 echo "Removing old $APPDIR tree ..."
109
110 rm -rf $APPDIR
111
112 echo "Building new app directory structure ..."
113
114 # only bother to make the longest paths
115
116 mkdir -p $APPDIR
117 mkdir -p $APPBIN
118 mkdir -p $APPLIB
119 mkdir -p $Etc
120 mkdir -p $Plugins
121 mkdir -p $Modules
122 mkdir -p $Loaders
123 mkdir -p $Shared
124 mkdir -p $Locale
125 mkdir -p $Surfaces
126 mkdir -p $Panners
127 mkdir -p $Shared/templates
128
129 # maybe set variables
130 ENVIRONMENT=environment
131 rm -f $ENVIRONMENT
132 touch $ENVIRONMENT
133
134 if test x$SAE != x ; then
135     appname="Ardour2/SAE"
136     echo "export ARDOUR_SAE=true" >> $ENVIRONMENT
137     #
138     # current default for SAE version is German keyboard layout without a keypad
139     #
140     echo export ARDOUR_KEYBOARD_LAYOUT=de-nokeypad >> $ENVIRONMENT
141     echo export ARDOUR_UI_CONF=ardour2_ui_sae.conf >> $ENVIRONMENT
142     echo export ARDOUR2_UI_RC=ardour2_ui_dark_sae.rc >> $ENVIRONMENT
143 elif test x$MIXBUS != x ; then
144     appname="Ardour2/Mixbus"
145     echo export ARDOUR_MIXBUS=true >> $ENVIRONMENT
146     #
147     # current default for MIXBUS version is US keyboard layout without a keypad
148     #
149     echo export ARDOUR_KEYBOARD_LAYOUT=us-nokeypad >> $ENVIRONMENT
150     echo export ARDOUR_UI_CONF=ardour2_ui.conf >> $ENVIRONMENT
151     echo export ARDOUR2_UI_RC=ardour2_ui_dark.rc >> $ENVIRONMENT
152 else
153     appname="Ardour2"
154 fi
155
156 #
157 # if we're not going to bundle JACK, make sure we can find
158 # jack in the places where it might be
159 #
160
161 echo export 'PATH=/usr/local/bin:/opt/bin:$PATH' >> $ENVIRONMENT
162
163 # create startup helper script
164
165 sed -e "/^%ENV%/r $ENVIRONMENT" -e '/^%ENV%/d' < ardour.sh.in > $APPBIN/ardour2
166 rm $ENVIRONMENT && chmod 775 $APPBIN/ardour2
167 MAIN_EXECUTABLE=ardour-$release_version
168
169 echo "Copying ardour executable ...."
170 cp ../../gtk2_ardour/$MAIN_EXECUTABLE $APPBIN
171 if test x$STRIP != x ; then
172     strip $APPBIN/$MAIN_EXECUTABLE
173 fi
174
175 # copy locale files
176 if test x$WITH_NLS != x ; then
177     echo "NLS support ..."
178     echo "I hope you remembered to run scons msgupdate!"
179     LINGUAS=
180     for file in ../../gtk2_ardour/*.mo 
181     do
182         lang=`basename $file | sed 's/\.mo//'`
183         mkdir -p $Locale/$lang/LC_MESSAGES
184         cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
185         LINGUAS="$LINGUAS $lang"
186     done
187     for file in ../../libs/ardour/*.mo 
188     do
189         lang=`basename $file | sed 's/\.mo//'`
190         mkdir -p $Locale/$lang/LC_MESSAGES
191         cp $file $Locale/$lang/LC_MESSAGES/libardour.mo
192     done
193
194     GTK_MESSAGES="atk10.mo gdk-pixbuf.mo gtk20-properties.mo gtk20.mo atk10.mo glib20.mo"
195     LOCALEROOT=/usr/share/locale
196
197     for l in $LINGUAS ; do
198         echo "Copying GTK i18n files for $l..."
199         for MO in $GTK_MESSAGES ; do 
200             if [ -f $LOCALEROOT/$l/LC_MESSAGES/$MO ] ; then
201                 cp $LOCALEROOT/$l/LC_MESSAGES/$MO $Locale/$l/LC_MESSAGES
202             else
203           # try with just the language spec
204                 just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
205                 if [ -f $LOCALEROOT/$just_lang/LC_MESSAGES/$MO ] ; then
206                     cp $LOCALEROOT/$just_lang/LC_MESSAGES/$MO $Locale/$just_lang/LC_MESSAGES
207                 fi
208             fi
209         done
210     done
211 else
212     echo "Skipping NLS support"
213 fi
214
215 GTKROOT=`pkg-config --libs-only-L gtk+-2.0 | sed s/-L//`
216 GTKROOT=`dirname $GTKROOT`
217 echo GTK stack root is $GTKROOT
218
219 GTKETC=${GTKROOT}/etc/gtk-2.0
220 GTKLIB=${GTKROOT}/lib/gtk-2.0/2.10.0
221 PANGOLIB=${GTKROOT}/lib/pango/1.6.0
222 GDKPIXBUFLIB=${GTKROOT}/lib/gdk-pixbuf-2.0/2.10.0
223
224 cp -R $GTKETC/* $Etc
225 echo "Copying all Pango modules ..."
226 cp -R $PANGOLIB/modules/*.so $Modules
227 echo "Copying all GDK Pixbuf loaders ..."
228 cp -R $GDKPIXBUFLIB/loaders/*.so $Loaders
229
230 pwd=`pwd`
231
232 if test x$WITH_LADSPA != x ; then
233     if test x$SAE != x ; then
234         plugdir=sae_ladspa
235     elif test x$MIXBUS != x ; then
236         plugdir=mixbus_ladspa
237     else
238         plugdir=ladspa
239     fi
240     echo "Copying `ls $plugdir | wc -l` plugins ..."
241     if [ -d $plugdir ] ; then
242         cp -r $plugdir/* $Plugins
243     fi
244 fi
245
246 pango-querymodules | sed "s?$GTKROOT/lib/pango/[0-9][0-9]*\.[0-9][0-9]*.[0-9][0-9]*/?@ROOTDIR@/?" > $Etc/pango.modules.in
247 gdk-pixbuf-query-loaders | sed "s?$GTKROOT/lib/gdk-pixbuf-2.0/[0-9][0-9]*\.[0-9][0-9]*.[0-9][0-9]*/?@ROOTDIR@/?" > $Etc/gdk-pixbuf.loaders.in
248
249 # We sort of rely on clearlooks, so include a version
250 # this one is special - we will set GTK_PATH to $Libraries/clearlooks
251 cp /usr/lib64/gtk-2.0/2.10.0/engines/libclearlooks.so $Libraries
252 mkdir -p $Libraries/clearlooks/engines
253 (cd $Libraries/clearlooks/engines && ln -s ../../libclearlooks.so* )
254
255 # XXX STILL NEED TO DO PANNERS FOR TRUNK
256 cp ../../libs/surfaces/*/libardour_*.so* $Surfaces
257 # hack ... move libardour_cp back into Libraries
258 mv $Surfaces/libardour_cp.so* $Libraries
259
260 # VAMP plugins that we use
261 cp ../../libs/vamp-plugins/libardourvampplugins.so* $Libraries
262
263 OURLIBDIR=../../libs
264 OURLIBS=$OURLIBDIR/vamp-sdk:$OURLIBDIR/surfaces/control_protocol:$OURLIBDIR/ardour:$OURLIBDIR/midi++2:$OURLIBDIR/pbd:$OURLIBDIR/rubberband:$OURLIBDIR/soundtouch:$OURLIBDIR/gtkmm2ext:$OURLIBDIR/sigc++2:$OURLIBDIR/glibmm2:$OURLIBDIR/gtkmm2/atk:$OURLIBDIR/gtkmm2/pango:$OURLIBDIR/gtkmm2/gdk:$OURLIBDIR/gtkmm2/gtk:$OURLIBDIR/libgnomecanvasmm:$OURLIBDIR/libsndfile
265
266 while [ true ] ; do 
267     missing=false
268     for file in $APPBIN/* $Libraries/* $Modules/* $Plugins/*.so ; do 
269         if ! file $file | grep -qs ELF ; then
270             continue
271         fi
272         # do not include libjack
273         deps=`LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | awk '{print $3}' | egrep "(/opt/|/local/|libs/|/usr/lib|/gtk)" | grep -v 'libjack\.'`
274         # LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | egrep "(/opt/|/local/|libs/|/usr/lib|/gtk)" | grep -v 'libjack\.'
275         echo -n "."
276         for dep in $deps ; do
277             if [ "x$dep" = "xnot" ] ; then 
278                   echo "Missing dependant library. Use ldd to find and fix"
279                   exit 1
280             fi
281
282             # don't use anything mapped at a specific address
283             if  echo $dep | grep -qs '0x' ; then continue; fi
284             # don't include any X Window libraries
285             if echo $dep | grep -qs libX ; then continue; fi  
286             # don't include libc
287             if echo $dep | grep -qs 'libc\.' ; then continue; fi
288
289             base=`basename $dep`
290             if ! test -f $Libraries/$base; then
291                 if echo $dep | grep -sq '^libs' ; then
292                     # echo Copying ../../$dep
293                     cp ../../$dep $Libraries
294                 else
295                     # echo Copying $dep
296                     cp $dep $Libraries
297                 fi
298                 missing=true
299             fi
300         done
301     done
302     if test x$missing = xfalse ; then
303         # everything has been found
304         break
305     fi
306 done
307 echo
308
309 # strip libraries
310 echo Stripping libraries
311 strip $APPLIB/*.so*
312
313 echo "Copying other stuff to $APPDIR  ..."
314
315 cp ../../gtk2_ardour/ergonomic-us.bindings  $Etc
316 cp ../../gtk2_ardour/mnemonic-us.bindings  $Etc
317 cp ../../gtk2_ardour/SAE-de-keypad.bindings  $Etc
318 cp ../../gtk2_ardour/SAE-de-nokeypad.bindings  $Etc
319 cp ../../gtk2_ardour/SAE-us-keypad.bindings  $Etc
320 cp ../../gtk2_ardour/SAE-us-nokeypad.bindings  $Etc
321 cp ../../gtk2_ardour/ardour.menus $Etc
322 cp ../../gtk2_ardour/ardour-sae.menus $Etc
323 if test x$SAE != x ; then
324     cp ../../ardour_system_sae.rc $Etc/ardour_system.rc
325     echo cp ../../ardour_system_sae.rc $Etc/ardour_system.rc
326     cp ../../instant.xml.sae $Etc/instant.xml
327     echo cp ../../instant.xml.sae $Etc/instant.xml
328 else
329 #    cp ../../ardour_system.rc $Etc/ardour_system.rc
330 #    echo FOO cp ../../ardour_system.rc $Etc/ardour_system.rc
331     cp ../../instant.xml $Etc/instant.xml
332     echo cp ../../instant.xml $Etc/instant.xml
333 fi
334 cp ../../gtk2_ardour/ardour2_ui_sae.conf $Etc
335 cp ../../gtk2_ardour/ardour2_ui_default.conf $Etc
336 cp ../../gtk2_ardour/ardour2_ui_default.conf $Etc/ardour2_ui.conf
337 cp ../../gtk2_ardour/ardour2_ui_light.rc $Etc
338 cp ../../gtk2_ardour/ardour2_ui_dark.rc $Etc
339 cp ../../gtk2_ardour/ardour2_ui_light_sae.rc $Etc
340 cp ../../gtk2_ardour/ardour2_ui_dark_sae.rc $Etc
341
342 cp -r ../../gtk2_ardour/icons $Etc
343 cp -r ../../gtk2_ardour/pixmaps $Etc
344
345 #
346 # put sooper sekrit ingredients here and they will be copied
347 #
348
349 if [ -d specialSauce ] ; then
350     cp -r specialSauce $Etc
351 fi
352
353 # share stuff
354
355 cp -R ../../gtk2_ardour/splash.png $Shared
356 cp ../../templates/*.template $Shared/templates/
357
358 # go through and recursively remove any .svn dirs in the bundle
359 for svndir in `find $APPDIR -name .svn -type d`; do
360     rm -rf $svndir
361 done
362
363 #
364 # and now ... the final package
365
366
367 if [ x$SAE != x ] ; then
368         
369     # SAE packaging
370     
371     echo "Creating SAE packaging directory"
372     cp HowToInstallArdourSAE.pdf "$APPDIR/How To Install Ardour SAE.pdf"
373     cp SAE-de-keypad.pdf "$APPDIR/Ardour SAE Shortcuts (keypad).pdf"
374     cp SAE-de-nokeypad.pdf "$APPDIR/Ardour SAE Shortcuts.pdf"
375     
376 elif [ x$MIXBUS != x ] ; then
377
378      # Mixbus packaging
379
380     echo "Creating Mixbus packaging directory"
381     cp MixBus_Install_QuickStart.pdf "$APPDIR/Mixbus Install & Quick Start Guide.pdf"
382     
383     if [ -x $EXTERNAL_JACK != x ] ; then
384         cp $EXTERNAL_JACK $PRODUCT_PKG_DIR
385     fi
386 fi
387
388 #echo "Building tarball ..."
389
390 #rm -f $APPNAME-$release_version.tar.bz2
391 #tar -jcf $APPNAME-$release_version.tar.bz2 $APPDIR
392
393 echo "Done."
394