Merge branch 'master' into cairocanvas
[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
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/doc
202
203 # maybe set variables
204 ENVIRONMENT=environment
205 rm -f $ENVIRONMENT
206 touch $ENVIRONMENT
207
208 if test x$MIXBUS != x ; then
209         echo export ARDOUR_MIXBUS=true >> $ENVIRONMENT
210         #
211         # current default for MIXBUS version is US keyboard layout without a keypad
212         #
213         echo export ARDOUR_KEYBOARD_LAYOUT=us-nokeypad >> $ENVIRONMENT
214         echo export ARDOUR_UI_CONF=ardour3_ui.conf >> $ENVIRONMENT
215         echo export ARDOUR3_UI_RC=ardour3_ui_dark.rc >> $ENVIRONMENT
216 fi
217
218 #
219 # if we're not going to bundle JACK, make sure we can find
220 # jack in the places where it might be
221 #
222
223 echo export 'PATH=/usr/local/bin:/opt/bin:$PATH' >> $ENVIRONMENT
224
225 # create startup helper script
226
227 sed -e "/^%ENV%/r $ENVIRONMENT" -e '/^%ENV%/d' -e 's/%VER%/'"${release_version}"'/' < ardour.sh.in > $APPBIN/ardour3
228 rm $ENVIRONMENT && chmod 775 $APPBIN/ardour3
229 MAIN_EXECUTABLE=ardour-${release_version}
230
231 echo "Copying ardour executable ...."
232 cp $BUILD_ROOT/gtk2_ardour/$MAIN_EXECUTABLE $APPBIN
233 if test x$STRIP = xall ; then
234         strip $APPBIN/$MAIN_EXECUTABLE
235 fi
236
237 # copy locale files
238 # note that at present(feb 2011), the .mo files end up in the source tree which is
239 # not really as it should be.
240 if test x$WITH_NLS != x ; then
241         echo "NLS support ..."
242         echo "I hope you remembered to run scons msgupdate!"
243         LINGUAS=
244
245         for pkg in gtk2_ardour libs/ardour libs/gtkmm2ext ; do 
246             files=`find ../../$pkg -name "*.mo"`
247
248             #
249             # the package name is appended with a number so that
250             # it can be parallel installed during a regular install
251             # with older (and newer) versions. it is just the major
252             # number of the release (i.e. leading digits)
253             #
254
255             vsuffix=`echo $release_version | sed 's/^\([0-9][0-9]*\).*/\1/'`
256
257             if [ -z "$files" ]; then
258                 echo ""
259                 echo "!!!! WARNING !!!! - Did not find any .mo files in ../../$pkg"
260                 echo ""
261             fi
262  
263             for file in $files 
264             do
265                 echo $file
266                 lang=`basename $file | sed 's/\.mo//'`
267                 mkdir -p $Locale/$lang/LC_MESSAGES
268                 cp $file $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
269                 echo copy $file to $Locale/$lang/LC_MESSAGES/`basename $pkg`$vsuffix.mo
270                 if echo $LINGUAS | grep $lang >/dev/null 2>&1 ; then
271                     :
272                 else 
273                     LINGUAS="$LINGUAS $lang"
274                 fi
275             done
276         done
277
278         GTK_MESSAGES="atk10.mo gdk-pixbuf.mo gtk20-properties.mo gtk20.mo atk10.mo glib20.mo"
279         LOCALEROOT=$GTKSTACK_ROOT/share/locale
280
281         for l in $LINGUAS ; do
282                 echo "Copying GTK i18n files for $l..."
283                 for MO in $GTK_MESSAGES ; do 
284                         if [ -f $LOCALEROOT/$l/LC_MESSAGES/$MO ] ; then
285                                 cp $LOCALEROOT/$l/LC_MESSAGES/$MO $Locale/$l/LC_MESSAGES
286                         else
287                                 # try with just the language spec
288                                 just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
289                                 if [ -f $LOCALEROOT/$just_lang/LC_MESSAGES/$MO ] ; then
290                                         cp $LOCALEROOT/$just_lang/LC_MESSAGES/$MO $Locale/$just_lang/LC_MESSAGES
291                                 fi
292                         fi
293                 done
294         done
295 else
296         echo "Skipping NLS support"
297 fi
298
299 #
300 # Copy stuff that may be dynamically loaded
301
302
303 cp -R $GTKSTACK_ROOT/etc/* $Etc
304 echo "Copying all Pango modules ..."
305 cp -R $GTKSTACK_ROOT/lib/pango/1.6.0/modules/*.so $Modules
306 echo "Copying all GDK Pixbuf loaders ..."
307 cp -R $GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so $Loaders
308
309 # Generate a pango module file using the actual Pango that we're going to bundle
310
311 cat > pangorc <<EOF 
312 [Pango]
313 ModulesPath=$GTKSTACK_ROOT/lib/pango/1.6.0/modules
314 EOF
315 env PANGO_RC_FILE=pangorc $GTKSTACK_ROOT/bin/pango-querymodules | sed "s?$GTKSTACK_ROOT/lib/pango/1.6.0/?@ROOTDIR@/?" > $Etc/pango.modules.in
316 rm pangorc
317
318 # Ditto for gdk-pixbuf loaders
319 gdk-pixbuf-query-loaders | sed "s?$GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/?@ROOTDIR@/?" > $Etc/gdk-pixbuf.loaders.in
320
321 # We rely on clearlooks, so include a version from our own build tree
322 # this one is special - we will set GTK_PATH to $Libraries/gtkengines
323
324 GTK_ENGINE_DIR=$Libraries/gtkengines/engines
325 mkdir -p $GTK_ENGINE_DIR
326
327 echo "Copying GTK engines ..."
328 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.so $Libraries
329 (cd $GTK_ENGINE_DIR && ln -s ../../libclearlooks.so . )
330
331 cp $GTKSTACK_ROOT/lib/gtk-2.0/2.10.0/engines/libpixmap.so $Libraries
332 (cd $GTK_ENGINE_DIR && ln -s ../../libpixmap.so . )
333
334 # LADSPA
335 if test x$WITH_LADSPA != x ; then
336         if test x$MIXBUS != x ; then
337                 plugdir=mixbus_ladspa
338         else
339                 plugdir=ladspa
340         fi
341         echo "Copying `ls $plugdir | wc -l` plugins ..."
342         if [ -d $plugdir ] ; then
343                 cp -r $plugdir/* $Plugins
344         fi
345 fi
346
347 # Control Surfaces
348 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.so* $Surfaces
349 cp $BUILD_ROOT/libs/surfaces/control_protocol/libardourcp.so* $Libraries
350
351 # MidiMaps
352 # got to be careful with names here
353 for x in $BUILD_ROOT/../midi_maps/*.map ; do
354     cp "$x" $MidiMaps
355 done
356
357 # MIDNAM Patch Files
358 # got to be careful with names here
359 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
360     cp "$x" $PatchFiles
361 done
362
363 # MackieControl data
364 # got to be careful with names here
365 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
366     cp "$x" $MackieControl
367 done
368
369 # Templates
370 #for f in $BUILD_ROOT/../templates/* ; do 
371 #    if [ -d "$f" ] ; then
372 #       echo Template: $f ; cp -r "$f" $Templates ; 
373 #    fi
374 #done
375
376 # ExportFormats
377 # got to be careful with names here
378 for x in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do
379     cp "$x" $ExportFormats
380 done
381
382 # Panners
383 cp $BUILD_ROOT/libs/panners/*/lib*.so* $Panners
384
385 # VAMP plugins that we use
386 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.so* $Libraries
387
388 # Suil modules
389 cp $ARDOURSTACK_ROOT/lib/suil-0/lib* $Libraries
390
391 OURLIBDIR=$BUILD_ROOT/libs
392 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
393
394 echo $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
395
396 checkedIdx=0
397 deplibs=
398
399 while [ true ] ; do 
400         missing=false
401         filelist=`find $APPLIB/ -type f`
402         filelist="$APPBIN/$MAIN_EXECUTABLE $filelist"
403
404         for file in $filelist  ; do 
405                 if ! file $file | grep -qs ELF ; then
406                         continue
407                 fi
408
409                 # speed this up a bit by not checking things multiple times.
410                 for i in "${depCheckedList[@]}"; do
411                         if [ $i == $file ]; then
412                                 continue 2
413                         fi
414                 done
415                 depCheckedList[$checkIdx]=$file
416                 checkIdx=$(($checkIdx + 1))
417                 
418                 # do not include libjack
419                 deps=`LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | awk '{print $3}'`
420
421                 echo -n "."
422                 for dep in $deps ; do
423                         if test "not" = ${dep}; then 
424                                 echo ""
425                                 echo "!!! ERROR !!! - Missing dependant library for $file."
426                                 echo "Searched: " $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
427                                 echo ""
428                                 (LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file)
429                                 echo ""
430                                 echo "!!! ERROR !!! - See Above"
431                                 exit 1
432                         fi
433
434                         # don't use anything mapped at a specific address
435                         if echo $dep | grep -qs '0x' ; then continue; fi
436                         # don't include /lib
437                         if echo $dep | grep -qs "^/lib/" ; then continue; fi
438                         # don't include jack
439                         if echo $dep | grep -qs libjack ; then continue; fi
440                         # don't include ALSA
441                         if echo $dep | grep -qs libasound ; then continue; fi
442                         # don't include any X Window libraries
443                         if echo $dep | grep -qs libX\. ; then continue; fi  
444                         if echo $dep | grep -qs libxcb ; then continue; fi  
445                         if echo $dep | grep -qs libICE\. ; then continue; fi  
446                         if echo $dep | grep -qs libSM\. ; then continue; fi  
447                         # don't include libc
448                         if echo $dep | grep -qs 'libc\.' ; then continue; fi
449                         # don't include libstdc++
450                         if echo $dep | grep -qs libstdc++ ; then continue; fi
451
452                         base=`basename $dep`
453                         if ! test -f $Libraries/$base; then
454                                 parent=$(basename ${file})
455                                 if echo $dep | grep -sq '^libs' ; then
456                                         echo "Copying dependant lib $BUILD_ROOT/$dep    (required by ${parent})"
457                                         cp $BUILD_ROOT/$dep $Libraries
458                                 else
459                                         echo "Copying dependant lib $dep    (required by ${parent})"
460                                         cp $dep $Libraries
461                                 fi
462                                 #
463                                 # reset RPATH so that the runtime linker never looks
464                                 # in places we don't want it to
465                                 #
466                                 chrpath -r foo $Libraries/`basename $dep`
467                                 if echo $dep | grep -sq '^/' ; then
468                                     # absolute path, candidate for stripping
469                                     deplibs="$deplibs $base"
470                                 fi
471                                 missing=true
472                         fi
473                 done
474         done
475         if test x$missing = xfalse ; then
476                 # everything has been found
477                 break
478         fi
479 done
480 echo
481
482 # strip libraries
483 if test x$STRIP = xall ; then
484     echo Stripping all libraries
485     # Must be writable so that we can strip
486     find $APPLIB/ -name "*.so*" | xargs chmod u+w
487     # and strip ...
488     find $APPLIB/ -name "*.so*" | xargs strip
489 elif test x$STRIP = xsome ; then
490     echo Stripping dependent libraries
491     for l in $deplibs ; do
492         chmod u+w $APPLIB/$l
493         strip $APPLIB/$l
494     done
495 fi
496 find $APPLIB/ -name "*.so*" | xargs chmod a+rx
497
498 echo "Copying other stuff to $APPDIR  ..."
499
500 # these are all generated by waf
501 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings       $Etc
502 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Etc
503 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Etc
504 cp ../../ardour_system.rc $Etc/ardour_system.rc
505 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_*.rc $Etc
506
507 # these are copied straight from the source tree
508
509 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui_default.conf
510 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui.conf
511 cp ../../instant.xml $Etc/instant.xml
512 cp ../../gtk2_ardour/step_editing.bindings $Etc
513 cp ../../gtk2_ardour/mixer.bindings $Etc
514 cp -r ../../gtk2_ardour/icons $Shared
515 cp -r ../../gtk2_ardour/pixmaps $Shared
516
517
518 #
519 # put sooper sekrit ingredients here and they will be copied
520 #
521
522 if [ -d specialSauce ] ; then
523         cp -r specialSauce $Etc
524 fi
525
526 # share stuff
527
528 cp -R ../../gtk2_ardour/splash.png $Shared
529 cp -R ../../gtk2_ardour/ArdourMono.ttf $Shared
530
531 # go through and recursively remove any .svn dirs in the bundle
532 for svndir in `find $APPDIR -name .svn -type d`; do
533         rm -rf $svndir
534 done
535
536 if test x$WITH_HARVID != x ; then
537         cd $APPBIN
538         HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
539         XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
540
541         rsync -Pa \
542                 rsync://ardour.org/video-tools/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz \
543                 "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz"
544
545         rsync -Pa \
546                 rsync://ardour.org/video-tools/xjadeo-${MULTIARCH}-${XJADEO_VERSION}.tgz \
547                 "$CACHEDIR/xjadeo-${MULTIARCH}-${XJADEO_VERSION}.tgz"
548
549         tar -x -z \
550                 --exclude=README --exclude=harvid.1 --strip-components=1 \
551                 -f "$CACHEDIR/harvid-${MULTIARCH}-${HARVID_VERSION}.tgz" || exit 1
552
553         tar -x -z \
554                 --exclude=README --exclude=xjadeo.1 --strip-components=1 \
555                 -f "$CACHEDIR/xjadeo-${MULTIARCH}-${XJADEO_VERSION}.tgz" || exit 1
556         mv xjadeo xjremote
557         cd -
558 fi
559
560 #
561 # Add the uninstaller
562 #
563 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
564 chmod a+x $APPBIN/${APP_VER_NAME}.uninstall.sh
565
566 #Sanity Check file
567 if [ -e $BUILD_ROOT/tools/sanity_check/sanityCheck ]; then
568         cp $BUILD_ROOT/tools/sanity_check/sanityCheck $APPBIN
569 else
570         echo "!!!ERROR !!! sanityCheck program is missing. packager will exit without being complete"
571         exit 1
572 fi
573
574 echo "Building tarball ..."
575
576 rm -f $APPDIR.tar.bz2
577 tar -cjf $APPDIR.tar.bz2 $APPDIR
578
579 echo "Calculating bundle size"
580 du -sb $APPDIR/  | awk '{print $1}' > $APPDIR.size
581
582 rm -rf $APPDIR/
583
584 echo "Done."
585