package small-splash image in binary bundles
[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 # where harvid and xjadeo binaries are cached
18 if test -z "$CACHEDIR" -o ! -d "$CACHEDIR"; then
19         CACHEDIR=`pwd`
20 fi
21
22 MIXBUS=
23 WITH_LADSPA=0
24 WITH_HARVID=
25 STRIP=all
26 PRINT_SYSDEPS=
27 WITH_NLS=
28 EXTERNAL_JACK=
29 VENDOR=Ardour ;
30 BUILDTYPE=""
31
32
33 if [ $# -eq 0 ] ; then
34         echo ""  
35         echo "ERROR - Please specify build type"
36         echo "    --public"
37         echo "    --mixbus"
38         echo ""  
39         exit 1
40 fi
41
42 while [ $# -gt 0 ] ; do
43         echo "arg = $1"
44         case $1 in
45
46         #
47         # top level build targets
48         #
49
50         --mixbus)
51                 MIXBUS=1; 
52                 WITH_NLS=1 ; 
53                 WITH_LADSPA=; 
54                 STRIP=all
55                 APPNAME=Mixbus ;
56                 VENDOR=Harrison ;
57                 shift ;;
58         --public)
59                 WITH_NLS=1 ; 
60                 WITH_LADSPA=; 
61                 STRIP=all ; 
62                 APPNAME=Ardour ;
63                 shift ;;
64         --allinone)
65                 WITH_NLS= ; 
66                 WITH_LADSPA=1; 
67                 STRIP=all; 
68                 shift ;;
69         --test) WITH_LADSPA=; STRIP= ; shift ;;
70
71         #
72         # specific build flags
73         #
74
75         --nojack) INTERNAL_JACK= ; shift ;;
76         --noladspa) WITH_LADSPA= ; shift ;;
77         --strip) STRIP=$2 ; shift ; shift ;;
78         --sysdeps) PRINT_SYSDEPS=1; shift ;;
79         --nls) WITH_NLS=1 ; shift ;;
80         --harvid) WITH_HARVID=1 ; shift ;;
81
82         *)
83                 #catch all for unknown arguments
84                 echo ""
85                 echo "!!! ERROR !!! - Unknown argument $1"
86                 echo ""
87                 exit 1
88                 ;;
89         esac
90 done
91
92 if test x$STRIP != xall -a x$STRIP != xnone -a x$STRIP != xsome ; then
93     echo "Unknown strip option \"$STRIP\""
94     echo "Legal values are: all, none, some"
95     exit 1
96 fi
97
98 . ../define_versions.sh
99
100 echo "Version is $version / $commit"
101 info_string="$version ($commit) built on `hostname` by `whoami` on `date`"
102 echo "Info string is $info_string"
103
104 # Figure out our CPU type
105 case `uname -m` in
106         i[3456789]86|x86|i86pc)
107                 echo "Architecture is x86"
108                 ARCH='x86'
109                 ARCH_BITS='32-bit'
110                 MULTIARCH='i386-linux-gnu'
111                 ;;
112         x86_64|amd64|AMD64)
113                 echo "Architecture is x86_64"
114                 ARCH='x86_64'
115                 ARCH_BITS='64-bit'
116                 MULTIARCH='x86_64-linux-gnu'
117                 ;;
118         *)
119                 echo ""
120                 echo "ERROR - Unknown architecture `uname -m`"
121                 echo ""
122                 exit 1
123                 ;;
124 esac
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}-${version}
138         APP_VER_NAME=${APPNAME}-${version}
139 else
140         APPDIR=${APPNAME}_${ARCH}-${version}-${BUILDTYPE}
141         APP_VER_NAME=${APPNAME}-${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 Backends=$APPLIB/backends
154
155 Modules=$Libraries/modules
156 Loaders=$Libraries/loaders
157
158 Templates=$Shared/templates
159 ExportFormats=$Shared/export
160 Locale=$Shared/locale
161 MidiMaps=$Shared/midi_maps
162 PatchFiles=$Shared/patchfiles
163 MackieControl=$Shared/mcp
164
165 if [ x$PRINT_SYSDEPS != x ] ; then
166 #
167 # print system dependencies
168 #
169
170         for file in $APPBIN/* $Libraries/* $Modules/* $Plugins/*.so ; do 
171                 if ! file $file | grep -qs Mach-O ; then
172                         continue
173                 fi
174                 otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
175         done | sort | uniq
176         exit 0
177 fi
178
179 echo "Removing old $APPDIR tree ..."
180 rm -rf $APPDIR/
181
182 echo "Building new app directory structure ..."
183
184 # only bother to make the longest paths
185
186 mkdir -p $APPDIR
187 mkdir -p $APPBIN
188 mkdir -p $APPLIB
189 mkdir -p $Etc
190 mkdir -p $Plugins
191 mkdir -p $Modules
192 mkdir -p $Loaders
193 mkdir -p $Shared
194 mkdir -p $Locale
195 mkdir -p $Surfaces
196 mkdir -p $MidiMaps
197 mkdir -p $PatchFiles
198 mkdir -p $MackieControl
199 mkdir -p $ExportFormats
200 mkdir -p $Panners
201 mkdir -p $Backends
202 mkdir -p $Templates
203 mkdir -p $Shared/doc
204
205 # maybe set variables
206 ENVIRONMENT=environment
207 rm -f $ENVIRONMENT
208 touch $ENVIRONMENT
209
210 if test x$MIXBUS != x ; then
211         echo export ARDOUR_MIXBUS=true >> $ENVIRONMENT
212         #
213         # current default for MIXBUS version is US keyboard layout without a keypad
214         #
215         echo export ARDOUR_KEYBOARD_LAYOUT=us-nokeypad >> $ENVIRONMENT
216         echo export ARDOUR_UI_CONF=ardour3_ui.conf >> $ENVIRONMENT
217         echo export ARDOUR3_UI_RC=ardour3_ui_dark.rc >> $ENVIRONMENT
218 fi
219
220 #
221 # if we're not going to bundle JACK, make sure we can find
222 # jack in the places where it might be
223 #
224
225 echo export 'PATH=/usr/local/bin:/opt/bin:$PATH' >> $ENVIRONMENT
226
227 # create startup helper script
228
229 sed -e "/^%ENV%/r $ENVIRONMENT" -e '/^%ENV%/d' -e 's/%VER%/'"${release_version}"'/' < ardour.sh.in > $APPBIN/ardour3
230 rm $ENVIRONMENT && chmod 775 $APPBIN/ardour3
231 MAIN_EXECUTABLE=ardour-${release_version}
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 pkg in gtk2_ardour libs/ardour libs/gtkmm2ext ; do 
248             files=`find ../../$pkg -name "*.mo"`
249
250             #
251             # the package name is appended with a number so that
252             # it can be parallel installed during a regular install
253             # with older (and newer) versions. it is just the major
254             # number of the release (i.e. leading digits)
255             #
256
257             vsuffix=`echo $release_version | sed 's/^\([0-9][0-9]*\).*/\1/'`
258
259             if [ -z "$files" ]; then
260                 echo ""
261                 echo "!!!! WARNING !!!! - Did not find any .mo files in ../../$pkg"
262                 echo ""
263             fi
264  
265             for file in $files 
266             do
267                 echo $file
268                 lang=`basename $file | sed 's/\.mo//'`
269                 mkdir -p $Locale/$lang/LC_MESSAGES
270                 cp $file $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
271                 echo copy $file to $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
272                 if echo $LINGUAS | grep $lang >/dev/null 2>&1 ; then
273                     :
274                 else 
275                     LINGUAS="$LINGUAS $lang"
276                 fi
277             done
278         done
279
280         GTK_MESSAGES="atk10.mo gdk-pixbuf.mo gtk20-properties.mo gtk20.mo atk10.mo glib20.mo"
281         LOCALEROOT=$GTKSTACK_ROOT/share/locale
282
283         for l in $LINGUAS ; do
284                 echo "Copying GTK i18n files for $l..."
285                 for MO in $GTK_MESSAGES ; do 
286                         if [ -f $LOCALEROOT/$l/LC_MESSAGES/$MO ] ; then
287                                 cp $LOCALEROOT/$l/LC_MESSAGES/$MO $Locale/$l/LC_MESSAGES
288                         else
289                                 # try with just the language spec
290                                 just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
291                                 if [ -f $LOCALEROOT/$just_lang/LC_MESSAGES/$MO ] ; then
292                                         cp $LOCALEROOT/$just_lang/LC_MESSAGES/$MO $Locale/$just_lang/LC_MESSAGES
293                                 fi
294                         fi
295                 done
296         done
297 else
298         echo "Skipping NLS support"
299 fi
300
301 #
302 # Copy stuff that may be dynamically loaded
303
304
305 cp -R $GTKSTACK_ROOT/etc/* $Etc
306 echo "Copying all Pango modules ..."
307 cp -R $GTKSTACK_ROOT/lib/pango/1.8.0/modules/*.so $Modules
308 echo "Copying all GDK Pixbuf loaders ..."
309 cp -R $GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so $Loaders
310
311 # Generate a pango module file using the actual Pango that we're going to bundle
312
313 cat > pangorc <<EOF 
314 [Pango]
315 ModulesPath=$GTKSTACK_ROOT/lib/pango/1.8.0/modules
316 EOF
317 env PANGO_RC_FILE=pangorc $GTKSTACK_ROOT/bin/pango-querymodules | sed "s?$GTKSTACK_ROOT/lib/pango/1.8.0/?@ROOTDIR@/?" > $Etc/pango.modules.in
318 rm pangorc
319
320 # Ditto for gdk-pixbuf loaders
321 gdk-pixbuf-query-loaders | sed "s?$GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/?@ROOTDIR@/?" > $Etc/gdk-pixbuf.loaders.in
322
323 # We rely on clearlooks, so include a version from our own build tree
324 # this one is special - we will set GTK_PATH to $Libraries/gtkengines
325
326 GTK_ENGINE_DIR=$Libraries/gtkengines/engines
327 mkdir -p $GTK_ENGINE_DIR
328
329 echo "Copying GTK engines ..."
330 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.so $Libraries
331 (cd $GTK_ENGINE_DIR && ln -s ../../libclearlooks.so . )
332
333 cp $GTKSTACK_ROOT/lib/gtk-2.0/2.10.0/engines/libpixmap.so $Libraries
334 (cd $GTK_ENGINE_DIR && ln -s ../../libpixmap.so . )
335
336 # LADSPA
337 if test x$WITH_LADSPA != x ; then
338         if test x$MIXBUS != x ; then
339                 plugdir=mixbus_ladspa
340         else
341                 plugdir=ladspa
342         fi
343         echo "Copying `ls $plugdir | wc -l` plugins ..."
344         if [ -d $plugdir ] ; then
345                 cp -r $plugdir/* $Plugins
346         fi
347 fi
348
349 # Control Surfaces
350 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.so* $Surfaces
351 cp $BUILD_ROOT/libs/surfaces/control_protocol/libardourcp.so* $Libraries
352
353 # MidiMaps
354 # got to be careful with names here
355 for x in $BUILD_ROOT/../midi_maps/*.map ; do
356     cp "$x" $MidiMaps
357 done
358
359 # MIDNAM Patch Files
360 # got to be careful with names here
361 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
362     cp "$x" $PatchFiles
363 done
364
365 # MackieControl data
366 # got to be careful with names here
367 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
368     cp "$x" $MackieControl
369 done
370
371 # Templates
372 #for f in $BUILD_ROOT/../templates/* ; do 
373 #    if [ -d "$f" ] ; then
374 #       echo Template: $f ; cp -r "$f" $Templates ; 
375 #    fi
376 #done
377
378 # ExportFormats
379 # got to be careful with names here
380 for x in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do
381     cp "$x" $ExportFormats
382 done
383
384 # Panners
385 cp $BUILD_ROOT/libs/panners/*/lib*.so* $Panners
386
387 # Backends
388 cp $BUILD_ROOT/libs/backends/*/lib*.so* $Backends
389
390 # VAMP plugins that we use
391 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.so* $Libraries
392
393 # Suil modules
394 cp $ARDOURSTACK_ROOT/lib/suil-0/lib* $Libraries
395
396 OURLIBDIR=$BUILD_ROOT/libs
397 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/libltc:$OURLIBDIR/qm-dsp
398
399 echo $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
400
401 checkedIdx=0
402 deplibs=
403
404 while [ true ] ; do 
405         missing=false
406         filelist=`find $APPLIB/ -type f`
407         filelist="$APPBIN/$MAIN_EXECUTABLE $filelist"
408
409         for file in $filelist  ; do 
410                 if ! file $file | grep -qs ELF ; then
411                         continue
412                 fi
413
414                 # speed this up a bit by not checking things multiple times.
415                 for i in "${depCheckedList[@]}"; do
416                         if [ $i == $file ]; then
417                                 continue 2
418                         fi
419                 done
420                 depCheckedList[$checkIdx]=$file
421                 checkIdx=$(($checkIdx + 1))
422                 
423                 # do not include libjack
424                 deps=`LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | awk '{print $3}'`
425
426                 echo -n "."
427                 for dep in $deps ; do
428                         if test "not" = ${dep}; then 
429                                 echo ""
430                                 echo "!!! ERROR !!! - Missing dependant library for $file."
431                                 echo "Searched: " $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
432                                 echo ""
433                                 (LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file)
434                                 echo ""
435                                 echo "!!! ERROR !!! - See Above"
436                                 exit 1
437                         fi
438
439                         # don't use anything mapped at a specific address
440                         if echo $dep | grep -qs '0x' ; then continue; fi
441                         # don't include /lib
442                         if echo $dep | grep -qs "^/lib/" ; then continue; fi
443                         # don't include jack
444                         if echo $dep | grep -qs libjack ; then continue; fi
445                         # don't include ALSA
446                         if echo $dep | grep -qs libasound ; then continue; fi
447                         # don't include any X Window libraries
448                         if echo $dep | grep -qs libX\. ; then continue; fi  
449                         if echo $dep | grep -qs libxcb ; then continue; fi  
450                         if echo $dep | grep -qs libICE\. ; then continue; fi  
451                         if echo $dep | grep -qs libSM\. ; then continue; fi  
452                         # don't include libc
453                         if echo $dep | grep -qs 'libc\.' ; then continue; fi
454                         # don't include libstdc++
455                         if echo $dep | grep -qs libstdc++ ; then continue; fi
456
457                         base=`basename $dep`
458                         if ! test -f $Libraries/$base; then
459                                 parent=$(basename ${file})
460                                 if echo $dep | grep -sq '^libs' ; then
461                                         echo "Copying dependant lib $BUILD_ROOT/$dep    (required by ${parent})"
462                                         cp $BUILD_ROOT/$dep $Libraries
463                                 else
464                                         echo "Copying dependant lib $dep    (required by ${parent})"
465                                         cp $dep $Libraries
466                                 fi
467                                 #
468                                 # reset RPATH so that the runtime linker never looks
469                                 # in places we don't want it to
470                                 #
471                                 chrpath -r foo $Libraries/`basename $dep`
472                                 if echo $dep | grep -sq '^/' ; then
473                                     # absolute path, candidate for stripping
474                                     deplibs="$deplibs $base"
475                                 fi
476                                 missing=true
477                         fi
478                 done
479         done
480         if test x$missing = xfalse ; then
481                 # everything has been found
482                 break
483         fi
484 done
485 echo
486
487 # strip libraries
488 if test x$STRIP = xall ; then
489     echo Stripping all libraries
490     # Must be writable so that we can strip
491     find $APPLIB/ -name "*.so*" | xargs chmod u+w
492     # and strip ...
493     find $APPLIB/ -name "*.so*" | xargs strip
494 elif test x$STRIP = xsome ; then
495     echo Stripping dependent libraries
496     for l in $deplibs ; do
497         chmod u+w $APPLIB/$l
498         strip $APPLIB/$l
499     done
500 fi
501 find $APPLIB/ -name "*.so*" | xargs chmod a+rx
502
503 echo "Copying other stuff to $APPDIR  ..."
504
505 # these are all generated by waf
506 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings       $Etc
507 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Etc
508 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Etc
509 cp ../../ardour_system.rc $Etc/ardour_system.rc
510 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_*.rc $Etc
511
512 # these are copied straight from the source tree
513
514 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui_default.conf
515 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui.conf
516 cp ../../instant.xml $Etc/instant.xml
517 cp ../../gtk2_ardour/step_editing.bindings $Etc
518 cp ../../gtk2_ardour/mixer.bindings $Etc
519 cp -r ../../gtk2_ardour/icons $Shared
520 cp -r ../../gtk2_ardour/pixmaps $Shared
521
522
523 #
524 # put sooper sekrit ingredients here and they will be copied
525 #
526
527 if [ -d specialSauce ] ; then
528         cp -r specialSauce $Etc
529 fi
530
531 # share stuff
532
533 cp -R ../../gtk2_ardour/splash.png $Shared
534 cp -R ../../gtk2_ardour/small-splash.png $Shared
535 cp -R ../../gtk2_ardour/ArdourMono.ttf $Shared
536
537 # go through and recursively remove any .svn dirs in the bundle
538 for svndir in `find $APPDIR -name .svn -type d`; do
539         rm -rf $svndir
540 done
541
542 if test x$WITH_HARVID != x ; then
543         cd $APPBIN
544         HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
545         XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
546
547         rsync -Pa \
548                 rsync://ardour.org/video-tools/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz \
549                 "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz"
550
551         rsync -Pa \
552                 rsync://ardour.org/video-tools/xjadeo-${MULTIARCH}-${XJADEO_VERSION}.tgz \
553                 "$CACHEDIR/xjadeo-${MULTIARCH}-${XJADEO_VERSION}.tgz"
554
555         tar -x -z \
556                 --exclude=README --exclude=harvid.1 --strip-components=1 \
557                 -f "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz" || exit 1
558
559         tar -x -z \
560                 --exclude=README --exclude=xjadeo.1 --strip-components=1 \
561                 -f "$CACHEDIR/xjadeo-${MULTIARCH}-${XJADEO_VERSION}.tgz" || exit 1
562         mv xjadeo xjremote
563         cd -
564 fi
565
566 #
567 # Add the uninstaller
568 #
569 sed -e "s/%REPLACE_PGM%/${APPNAME}/" -e "s/%REPLACE_VENDOR%/${VENDOR}/" -e "s/%REPLACE_VERSION%/${version}/" -e "s/%REPLACE_TYPE%/${BUILDTYPE}/" < uninstall.sh.in > $APPBIN/${APP_VER_NAME}.uninstall.sh
570 chmod a+x $APPBIN/${APP_VER_NAME}.uninstall.sh
571
572 #Sanity Check file
573 if [ -e $BUILD_ROOT/tools/sanity_check/sanityCheck ]; then
574         cp $BUILD_ROOT/tools/sanity_check/sanityCheck $APPBIN
575 else
576         echo "!!!ERROR !!! sanityCheck program is missing. packager will exit without being complete"
577         exit 1
578 fi
579
580 echo "Building tarball ..."
581
582 rm -f $APPDIR.tar.bz2
583 tar -cjf $APPDIR.tar.bz2 $APPDIR
584
585 echo "Calculating bundle size"
586 du -sb $APPDIR/  | awk '{print $1}' > $APPDIR.size
587
588 rm -rf $APPDIR/
589
590 echo "Done."
591