quieten down linux build script
[ardour.git] / tools / linux_packaging / build
1 #!/bin/bash
2
3 # script for pulling together a Linux app bundle.
4 #
5 # This will create a bundle for a single architecture.
6 # Execute this scirpt on both x86 and x86_64 and then use
7 # package to merge the 2 bundles into a final package with the
8 # installer. See "noderun" for a complete build script.
9
10 # where the GTK stack is installed
11 GTKSTACK_ROOT=$HOME/gtk/inst
12 # where the Ardour dependencies are installed
13 ARDOURSTACK_ROOT=$HOME/a3/inst
14 # the waf build tree to use when copying built/generated files
15 BUILD_ROOT=../../build
16
17 MIXBUS=
18 WITH_LADSPA=0
19 STRIP=all
20 PRINT_SYSDEPS=
21 WITH_NLS=
22 EXTERNAL_JACK=
23 VENDOR=Ardour ;
24 BUILDTYPE=""
25
26 if [ $# -eq 0 ] ; then
27         echo ""  
28         echo "ERROR - Please specify build type"
29         echo "    --public"
30         echo "    --mixbus"
31         echo ""  
32         exit 1
33 fi
34
35 while [ $# -gt 0 ] ; do
36         echo "arg = $1"
37         case $1 in
38
39         #
40         # top level build targets
41         #
42
43         --mixbus)
44                 MIXBUS=1; 
45                 WITH_NLS=1 ; 
46                 WITH_LADSPA=; 
47                 STRIP=all
48                 APPNAME=Mixbus ;
49                 VENDOR=Harrison ;
50                 shift ;;
51         --public)
52                 WITH_NLS=1 ; 
53                 WITH_LADSPA=; 
54                 STRIP=all ; 
55                 APPNAME=Ardour ;
56                 shift ;;
57         --allinone)
58                 WITH_NLS= ; 
59                 WITH_LADSPA=1; 
60                 STRIP=all; 
61                 shift ;;
62         --test) WITH_LADSPA=; STRIP= ; shift ;;
63
64         #
65         # specific build flags
66         #
67
68         --nojack) INTERNAL_JACK= ; shift ;;
69         --noladspa) WITH_LADSPA= ; shift ;;
70         --strip) STRIP=$2 ; shift ; shift ;;
71         --sysdeps) PRINT_SYSDEPS=1; shift ;;
72         --nls) WITH_NLS=1 ; shift ;;
73
74         *)
75                 #catch all for unknown arguments
76                 echo ""
77                 echo "!!! ERROR !!! - Unknown argument $1"
78                 echo ""
79                 exit 1
80                 ;;
81         esac
82 done
83
84 if test x$STRIP != xall -a x$STRIP != xnone -a x$STRIP != xsome ; then
85     echo "Unknown strip option \"$STRIP\""
86     echo "Legal values are: all, none, some"
87     exit 1
88 fi
89
90 # Error out whenever possible
91 set -e
92
93 release_version=`grep -m 1 '^VERSION' ../../wscript | awk '{print $3}' | sed "s/'//g"`
94 svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d"'" -f 2`
95 echo "Version is $release_version / $svn_version"
96 info_string="$release_version/$svn_version built on `hostname` by `whoami` on `date`"
97 echo "Info string is $info_string"
98
99 # Figure out our CPU type
100 case `uname -m` in
101         i[3456789]86|x86|i86pc)
102                 echo "Architecture is x86"
103                 ARCH='x86'
104                 ARCH_BITS='32-bit'
105                 ;;
106         x86_64|amd64|AMD64)
107                 echo "Architecture is x86_64"
108                 ARCH='x86_64'
109                 ARCH_BITS='64-bit'
110                 ;;
111         *)
112                 echo ""
113                 echo "ERROR - Unknown architecture `uname -m`"
114                 echo ""
115                 exit 1
116                 ;;
117 esac
118
119 # Figure out the Build Type
120 if grep -q "DEBUG = True" ../../build/c4che/default.cache.py; then
121         DEBUG="T"
122 else
123         DEBUG="F"
124 fi
125
126 if [ x$DEBUG = xT ]; then
127     BUILDTYPE="dbg"
128     if [ x$STRIP = xall ] ; then
129         echo "A debug build with --strip all makes no sense - STRIP reset to \"some\""
130         STRIP=some
131     fi
132 fi
133
134 # setup directory structure
135
136 if [ -z "${BUILDTYPE}" ]; then
137         APPDIR=${APPNAME}_${ARCH}-${release_version}_${svn_version}
138         APP_VER_NAME=${APPNAME}-${release_version}_${svn_version}
139 else
140         APPDIR=${APPNAME}_${ARCH}-${release_version}_${svn_version}-${BUILDTYPE}
141         APP_VER_NAME=${APPNAME}-${release_version}_${svn_version}-${BUILDTYPE}
142 fi
143
144 APPBIN=$APPDIR/bin
145 APPLIB=$APPDIR/lib
146 Libraries=$APPLIB
147 Etc=$APPDIR/etc
148 Shared=$APPDIR/share
149
150 Plugins=$APPLIB/plugins
151 Surfaces=$APPLIB/surfaces
152 Panners=$APPLIB/panners
153
154 Modules=$Libraries/modules
155 Loaders=$Libraries/loaders
156
157 Templates=$Shared/templates
158 ExportFormats=$Shared/export
159 Locale=$Shared/locale
160 MidiMaps=$Shared/midi_maps
161 PatchFiles=$Shared/patchfiles
162 MackieControl=$Shared/mcp
163
164 if [ x$PRINT_SYSDEPS != x ] ; then
165 #
166 # print system dependencies
167 #
168
169         for file in $APPBIN/* $Libraries/* $Modules/* $Plugins/*.so ; do 
170                 if ! file $file | grep -qs Mach-O ; then
171                         continue
172                 fi
173                 otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
174         done | sort | uniq
175         exit 0
176 fi
177
178 echo "Removing old $APPDIR tree ..."
179 rm -rf $APPDIR/
180
181 echo "Building new app directory structure ..."
182
183 # only bother to make the longest paths
184
185 mkdir -p $APPDIR
186 mkdir -p $APPBIN
187 mkdir -p $APPLIB
188 mkdir -p $Etc
189 mkdir -p $Plugins
190 mkdir -p $Modules
191 mkdir -p $Loaders
192 mkdir -p $Shared
193 mkdir -p $Locale
194 mkdir -p $Surfaces
195 mkdir -p $MidiMaps
196 mkdir -p $PatchFiles
197 mkdir -p $MackieControl
198 mkdir -p $ExportFormats
199 mkdir -p $Panners
200 mkdir -p $Templates
201 mkdir -p $Shared/templates
202 mkdir -p $Shared/doc
203
204 # maybe set variables
205 ENVIRONMENT=environment
206 rm -f $ENVIRONMENT
207 touch $ENVIRONMENT
208
209 if test x$MIXBUS != x ; then
210         echo export ARDOUR_MIXBUS=true >> $ENVIRONMENT
211         #
212         # current default for MIXBUS version is US keyboard layout without a keypad
213         #
214         echo export ARDOUR_KEYBOARD_LAYOUT=us-nokeypad >> $ENVIRONMENT
215         echo export ARDOUR_UI_CONF=ardour3_ui.conf >> $ENVIRONMENT
216         echo export ARDOUR3_UI_RC=ardour3_ui_dark.rc >> $ENVIRONMENT
217 fi
218
219 #
220 # if we're not going to bundle JACK, make sure we can find
221 # jack in the places where it might be
222 #
223
224 echo export 'PATH=/usr/local/bin:/opt/bin:$PATH' >> $ENVIRONMENT
225
226 # create startup helper script
227
228 sed -e "/^%ENV%/r $ENVIRONMENT" -e '/^%ENV%/d' -e 's/%VER%/'"${release_version}"'/' < ardour.sh.in > $APPBIN/ardour3
229 rm $ENVIRONMENT && chmod 775 $APPBIN/ardour3
230 # the 3.0 here is not the same as "release-version" because the latter may include "-betaN" etc.
231 MAIN_EXECUTABLE=ardour-3.0
232
233 echo "Copying ardour executable ...."
234 cp $BUILD_ROOT/gtk2_ardour/$MAIN_EXECUTABLE $APPBIN
235 if test x$STRIP = xall ; then
236         strip $APPBIN/$MAIN_EXECUTABLE
237 fi
238
239 # copy locale files
240 # note that at present(feb 2011), the .mo files end up in the source tree which is
241 # not really as it should be.
242 if test x$WITH_NLS != x ; then
243         echo "NLS support ..."
244         echo "I hope you remembered to run scons msgupdate!"
245         LINGUAS=
246
247         for dl in gtk2_ardour libs/ardour libs/gtkmm2ext ; do 
248             files=`find ../../$dl -name "*.mo"`
249
250             if [ -z "$files" ]; then
251                 echo ""
252                 echo "!!!! WARNING !!!! - Did not find any .mo files in ../../$dl"
253                 echo ""
254             fi
255  
256             for file in $files 
257             do
258                 echo $file
259                 lang=`basename $file | sed 's/\.mo//'`
260                 mkdir -p $Locale/$lang/LC_MESSAGES
261                 cp $file $Locale/$lang/LC_MESSAGES/`basename $dl`
262                 if echo $LINGUAS | grep $lang >/dev/null 2>&1 ; then
263                     :
264                 else 
265                     LINGUAS="$LINGUAS $lang"
266                 fi
267             done
268         done
269
270         GTK_MESSAGES="atk10.mo gdk-pixbuf.mo gtk20-properties.mo gtk20.mo atk10.mo glib20.mo"
271         LOCALEROOT=/usr/share/locale
272
273         for l in $LINGUAS ; do
274                 echo "Copying GTK i18n files for $l..."
275                 for MO in $GTK_MESSAGES ; do 
276                         if [ -f $LOCALEROOT/$l/LC_MESSAGES/$MO ] ; then
277                                 cp $LOCALEROOT/$l/LC_MESSAGES/$MO $Locale/$l/LC_MESSAGES
278                         else
279                                 # try with just the language spec
280                                 just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
281                                 if [ -f $LOCALEROOT/$just_lang/LC_MESSAGES/$MO ] ; then
282                                         cp $LOCALEROOT/$just_lang/LC_MESSAGES/$MO $Locale/$just_lang/LC_MESSAGES
283                                 fi
284                         fi
285                 done
286         done
287 else
288         echo "Skipping NLS support"
289 fi
290
291 #
292 # Copy stuff that may be dynamically loaded
293
294
295 cp -R $GTKSTACK_ROOT/etc/* $Etc
296 echo "Copying all Pango modules ..."
297 cp -R $GTKSTACK_ROOT/lib/pango/1.6.0/modules/*.so $Modules
298 echo "Copying all GDK Pixbuf loaders ..."
299 cp -R $GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so $Loaders
300
301 # Generate a pango module file using the actual Pango that we're going to bundle
302
303 cat > pangorc <<EOF 
304 [Pango]
305 ModulesPath=$GTKSTACK_ROOT/lib/pango/1.6.0/modules
306 EOF
307 env PANGO_RC_FILE=pangorc $GTKSTACK_ROOT/bin/pango-querymodules | sed "s?$GTKSTACK_ROOT/lib/pango/1.6.0/?@ROOTDIR@/?" > $Etc/pango.modules.in
308 rm pangorc
309
310 # Ditto for gdk-pixbuf loaders
311 gdk-pixbuf-query-loaders | sed "s?$GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/?@ROOTDIR@/?" > $Etc/gdk-pixbuf.loaders.in
312
313 # We rely on clearlooks, so include a version from our own build tree
314 # this one is special - we will set GTK_PATH to $Libraries/clearlooks
315
316 echo "Copying clearlooks ..."
317 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.so $Libraries
318 mkdir -p $Libraries/clearlooks/engines
319 (cd $Libraries/clearlooks/engines && ln -s ../../libclearlooks.so . )
320
321 # LADSPA
322 if test x$WITH_LADSPA != x ; then
323         if test x$MIXBUS != x ; then
324                 plugdir=mixbus_ladspa
325         else
326                 plugdir=ladspa
327         fi
328         echo "Copying `ls $plugdir | wc -l` plugins ..."
329         if [ -d $plugdir ] ; then
330                 cp -r $plugdir/* $Plugins
331         fi
332 fi
333
334 # Control Surfaces
335 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.so* $Surfaces
336 cp $BUILD_ROOT/libs/surfaces/control_protocol/libardourcp.so* $Libraries
337
338 # MidiMaps
339 # got to be careful with names here
340 for x in $BUILD_ROOT/../midi_maps/*.map ; do
341     cp "$x" $MidiMaps
342 done
343
344 # MIDNAM Patch Files
345 # got to be careful with names here
346 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
347     cp "$x" $PatchFiles
348 done
349
350 # MackieControl data
351 # got to be careful with names here
352 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
353     cp "$x" $MackieControl
354 done
355
356 # Templates
357 for f in $BUILD_ROOT/../templates/* ; do 
358     if [ -d "$f" ] ; then
359         echo Template: $f ; cp -r "$f" $Templates ; 
360     fi
361 done
362
363 # ExportFormats
364 # got to be careful with names here
365 for x in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do
366     cp "$x" $ExportFormats
367 done
368
369 # Panners
370 cp $BUILD_ROOT/libs/panners/*/lib*.so* $Panners
371
372 # VAMP plugins that we use
373 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.so* $Libraries
374
375 # Suil modules
376 cp $ARDOURSTACK_ROOT/lib/suil-0/lib* $Libraries
377
378 OURLIBDIR=$BUILD_ROOT/libs
379 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:$OURLIBDIR/evoral:$OURLIBDIR/evoral/src/libsmf:$OURLIBDIR/audiographer:$OURLIBDIR/timecode:$OURLIBDIR/taglib:$OURLIBDIR/qm-dsp
380
381 echo $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
382
383 checkedIdx=0
384 deplibs=
385
386 while [ true ] ; do 
387         missing=false
388         filelist=`find $APPLIB/ -type f`
389         filelist="$APPBIN/$MAIN_EXECUTABLE $filelist"
390
391         for file in $filelist  ; do 
392                 if ! file $file | grep -qs ELF ; then
393                         continue
394                 fi
395
396                 # speed this up a bit by not checking things multiple times.
397                 for i in "${depCheckedList[@]}"; do
398                         if [ $i == $file ]; then
399                                 continue 2
400                         fi
401                 done
402                 depCheckedList[$checkIdx]=$file
403                 checkIdx=$(($checkIdx + 1))
404                 
405                 # do not include libjack
406                 deps=`LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | awk '{print $3}'`
407
408                 echo -n "."
409                 for dep in $deps ; do
410                         if test "not" = ${dep}; then 
411                                 echo ""
412                                 echo "!!! ERROR !!! - Missing dependant library for $file."
413                                 echo ""
414                                 (LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file)
415                                 echo ""
416                                 echo "!!! ERROR !!! - See Above"
417                                 exit 1
418                         fi
419
420                         # don't use anything mapped at a specific address
421                         if echo $dep | grep -qs '0x' ; then continue; fi
422                         # don't include /lib
423                         if echo $dep | grep -qs "^/lib/" ; then continue; fi
424                         # don't include jack
425                         if echo $dep | grep -qs libjack ; then continue; fi
426                         # don't include ALSA
427                         if echo $dep | grep -qs libasound ; then continue; fi
428                         # don't include any X Window libraries
429                         if echo $dep | grep -qs libX\. ; then continue; fi  
430                         if echo $dep | grep -qs libxcb ; then continue; fi  
431                         if echo $dep | grep -qs libICE\. ; then continue; fi  
432                         if echo $dep | grep -qs libSM\. ; then continue; fi  
433                         # don't include libc
434                         if echo $dep | grep -qs 'libc\.' ; then continue; fi
435                         # don't include libstdc++
436                         if echo $dep | grep -qs libstdc++ ; then continue; fi
437
438                         base=`basename $dep`
439                         if ! test -f $Libraries/$base; then
440                                 parent=$(basename ${file})
441                                 if echo $dep | grep -sq '^libs' ; then
442                                         echo "Copying dependant lib $BUILD_ROOT/$dep    (required by ${parent})"
443                                         cp $BUILD_ROOT/$dep $Libraries
444                                 else
445                                         echo "Copying dependant lib $dep    (required by ${parent})"
446                                         cp $dep $Libraries
447                                 fi
448                                 if echo $dep | grep -sq '^/' ; then
449                                     # absolute path, candidate for stripping
450                                     deplibs="$deplibs $base"
451                                 fi
452                                 missing=true
453                         fi
454                 done
455         done
456         if test x$missing = xfalse ; then
457                 # everything has been found
458                 break
459         fi
460 done
461 echo
462
463 # strip libraries
464 if test x$STRIP = xall ; then
465     echo Stripping all libraries
466     # Must be writable so that we can strip
467     find $APPLIB/ -name "*.so*" | xargs chmod u+w
468     # and strip ...
469     find $APPLIB/ -name "*.so*" | xargs strip
470 elif test x$STRIP = xsome ; then
471     echo Stripping dependent libraries
472     for l in $deplibs ; do
473         chmod u+w $APPLIB/$l
474         strip $APPLIB/$l
475     done
476 fi
477 find $APPLIB/ -name "*.so*" | xargs chmod a+rx
478
479 echo "Copying other stuff to $APPDIR  ..."
480
481 # these are all generated by waf
482 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings       $Etc
483 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Etc
484 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Etc
485 cp $BUILD_ROOT/ardour_system.rc $Etc/ardour_system.rc
486 cp $BUILD_ROOT/gtk2_ardour/ardour3*.rc $Etc
487
488 # these are copied straight from the source tree
489
490 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui_default.conf
491 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui.conf
492 cp ../../instant.xml $Etc/instant.xml
493 cp ../../gtk2_ardour/step_editing.bindings $Etc
494 cp ../../gtk2_ardour/mixer.bindings $Etc
495 cp -r ../../gtk2_ardour/icons $Shared
496 cp -r ../../gtk2_ardour/pixmaps $Shared
497
498
499 #
500 # put sooper sekrit ingredients here and they will be copied
501 #
502
503 if [ -d specialSauce ] ; then
504         cp -r specialSauce $Etc
505 fi
506
507 # share stuff
508
509 cp -R ../../gtk2_ardour/splash.png $Shared
510
511 # go through and recursively remove any .svn dirs in the bundle
512 for svndir in `find $APPDIR -name .svn -type d`; do
513         rm -rf $svndir
514 done
515
516 #
517 # Add the uninstaller
518 #
519 sed -e "s/%REPLACE_PGM%/${APPNAME}/" -e "s/%REPLACE_VENDOR%/${VENDOR}/" -e "s/%REPLACE_VERSION%/${release_version}/" -e "s/%REPLACE_BUILD%/${svn_version}/" -e "s/%REPLACE_TYPE%/${BUILDTYPE}/" < uninstall.sh.in > $APPBIN/${APP_VER_NAME}.uninstall.sh
520 chmod a+x $APPBIN/${APP_VER_NAME}.uninstall.sh
521
522 #Sanity Check file
523 if [ -e $BUILD_ROOT/tools/sanity_check/sanityCheck ]; then
524         cp $BUILD_ROOT/tools/sanity_check/sanityCheck $APPBIN
525 else
526         echo "!!!ERROR !!! sanityCheck program is missing. packager will exit without being complete"
527         exit 1
528 fi
529
530 echo "Building tarball ..."
531
532 rm -f $APPDIR.tar.bz2
533 tar -cjf $APPDIR.tar.bz2 $APPDIR
534
535 echo "Calculating bundle size"
536 du -sb $APPDIR/  | awk '{print $1}' > $APPDIR.size
537
538 rm -rf $APPDIR/
539
540 echo "Done."
541