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