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