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