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