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