potential fix for partial stripping of a linux bundle
[ardour.git] / tools / linux_packaging / build
1 #!/bin/bash
2
3 #
4
5 . ./buildenv
6
7 # script for pulling together a Linux app bundle.
8 #
9 # This will create a bundle for a single architecture.
10 # Execute this scirpt on both x86 and x86_64 and then use
11 # package to merge the 2 bundles into a final package with the
12 # installer.
13
14 MIXBUS=
15 WITH_LADSPA=0
16 STRIP=all
17 PRINT_SYSDEPS=
18 WITH_NLS=
19 EXTERNAL_JACK=
20 VENDOR=Ardour ;
21 BUILDTYPE=""
22
23 if [ $# -eq 0 ] ; then
24         echo ""  
25         echo "ERROR - Please specify build type"
26         echo "    --public"
27         echo "    --mixbus"
28         echo ""  
29         exit 1
30 fi
31
32 while [ $# -gt 0 ] ; do
33         echo "arg = $1"
34         case $1 in
35
36         #
37         # top level build targets
38         #
39
40         --mixbus)
41                 MIXBUS=1; 
42                 WITH_NLS=1 ; 
43                 WITH_LADSPA=; 
44                 STRIP=all
45                 APPNAME=Mixbus ;
46                 VENDOR=Harrison ;
47                 shift ;;
48         --public)
49                 WITH_NLS=1 ; 
50                 WITH_LADSPA=; 
51                 STRIP=all ; 
52                 APPNAME=Ardour ;
53                 shift ;;
54         --allinone)
55                 WITH_NLS= ; 
56                 WITH_LADSPA=1; 
57                 STRIP=all; 
58                 shift ;;
59         --test) WITH_LADSPA=; STRIP= ; shift ;;
60
61         #
62         # specific build flags
63         #
64
65         --nojack) INTERNAL_JACK= ; shift ;;
66         --noladspa) WITH_LADSPA= ; shift ;;
67         --strip) STRIP=$2 ; shift ; shift ;;
68         --sysdeps) PRINT_SYSDEPS=1; shift ;;
69         --nls) WITH_NLS=1 ; shift ;;
70
71         *)
72                 #catch all for unknown arguments
73                 echo ""
74                 echo "!!! ERROR !!! - Unknown argument $1"
75                 echo ""
76                 exit 1
77                 ;;
78         esac
79 done
80
81 if test x$STRIP != xall -a x$STRIP != xnone -a x$STRIP != xsome ; then
82     echo "Unknown strip option \"$STRIP\""
83     echo "Legal values are: all, none, some"
84     exit 1
85 fi
86
87 release_version=`grep -m 1 '^VERSION' ../../wscript | awk '{print $3}' | sed "s/'//g"`
88 svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d"'" -f 2`
89 echo "Version is $release_version / $svn_version"
90 info_string="$release_version/$svn_version built on `hostname` by `whoami` on `date`"
91 echo "Info string is $info_string"
92
93 # Figure out our CPU type
94 case `uname -m` in
95         i[3456789]86|x86|i86pc)
96                 echo "Architecture is x86"
97                 ARCH='x86'
98                 ARCH_BITS='32-bit'
99                 ;;
100         x86_64|amd64|AMD64)
101                 echo "Architecture is x86_64"
102                 ARCH='x86_64'
103                 ARCH_BITS='64-bit'
104                 ;;
105         *)
106                 echo ""
107                 echo "ERROR - Unknown architecture `uname -m`"
108                 echo ""
109                 exit 1
110                 ;;
111 esac
112
113 # Figure out the Build Type
114 if grep -q "DEBUG = True" ../../build/c4che/default.cache.py; then
115         DEBUG="T"
116 else
117         DEBUG="F"
118 fi
119
120 if [ x$DEBUG != x ]; 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 # the waf build tree to use when copying built/generated files
129
130 BUILD_ROOT=../../build/default
131
132 # setup directory structure
133
134 if [ -z "${BUILDTYPE}" ]; then
135         APPDIR=${APPNAME}_${ARCH}-${release_version}_${svn_version}
136         APP_VER_NAME=${APPNAME}-${release_version}_${svn_version}
137 else
138         APPDIR=${APPNAME}_${ARCH}-${release_version}_${svn_version}-${BUILDTYPE}
139         APP_VER_NAME=${APPNAME}-${release_version}_${svn_version}-${BUILDTYPE}
140 fi
141
142 APPBIN=$APPDIR/bin
143 APPLIB=$APPDIR/lib
144 Libraries=$APPLIB
145 Etc=$APPDIR/etc
146 Shared=$APPDIR/share
147 Plugins=$APPLIB/plugins
148 Surfaces=$APPLIB/surfaces
149 Panners=$APPLIB/panners
150 Locale=$Shared/locale
151 MidiMaps=$Shared/midi_maps
152 Modules=$Libraries/modules
153 Loaders=$Libraries/loaders
154
155
156 if [ x$PRINT_SYSDEPS != x ] ; then
157 #
158 # print system dependencies
159 #
160
161         for file in $APPBIN/* $Libraries/* $Modules/* $Plugins/*.so ; do 
162                 if ! file $file | grep -qs Mach-O ; then
163                         continue
164                 fi
165                 otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
166         done | sort | uniq
167         exit 0
168 fi
169
170 echo "Removing old $APPDIR tree ..."
171 rm -rf $APPDIR/
172
173 echo "Building new app directory structure ..."
174
175 # only bother to make the longest paths
176
177 mkdir -p $APPDIR
178 mkdir -p $APPBIN
179 mkdir -p $APPLIB
180 mkdir -p $Etc
181 mkdir -p $Plugins
182 mkdir -p $Modules
183 mkdir -p $Loaders
184 mkdir -p $Shared
185 mkdir -p $Locale
186 mkdir -p $Surfaces
187 mkdir -p $MidiMaps
188 mkdir -p $Panners
189 mkdir -p $Shared/templates
190 mkdir -p $Shared/doc
191
192 # maybe set variables
193 ENVIRONMENT=environment
194 rm -f $ENVIRONMENT
195 touch $ENVIRONMENT
196
197 if test x$MIXBUS != x ; then
198         echo export ARDOUR_MIXBUS=true >> $ENVIRONMENT
199         #
200         # current default for MIXBUS version is US keyboard layout without a keypad
201         #
202         echo export ARDOUR_KEYBOARD_LAYOUT=us-nokeypad >> $ENVIRONMENT
203         echo export ARDOUR_UI_CONF=ardour3_ui.conf >> $ENVIRONMENT
204         echo export ARDOUR3_UI_RC=ardour3_ui_dark.rc >> $ENVIRONMENT
205 fi
206
207 #
208 # if we're not going to bundle JACK, make sure we can find
209 # jack in the places where it might be
210 #
211
212 echo export 'PATH=/usr/local/bin:/opt/bin:$PATH' >> $ENVIRONMENT
213
214 # create startup helper script
215
216 sed -e "/^%ENV%/r $ENVIRONMENT" -e '/^%ENV%/d' -e 's/%VER%/'"${release_version}"'/' < ardour.sh.in > $APPBIN/ardour3
217 rm $ENVIRONMENT && chmod 775 $APPBIN/ardour3
218 #MAIN_EXECUTABLE=ardour-$release_version
219 MAIN_EXECUTABLE=ardour-3.0
220
221 echo "Copying ardour executable ...."
222 cp $BUILD_ROOT/gtk2_ardour/$MAIN_EXECUTABLE $APPBIN
223 if test x$STRIP = xall ; then
224         strip $APPBIN/$MAIN_EXECUTABLE
225 fi
226
227 # copy locale files
228 # note that at present(feb 2011), the .mo files end up in the source tree which is
229 # not really as it should be.
230 if test x$WITH_NLS != x ; then
231         echo "NLS support ..."
232         echo "I hope you remembered to run scons msgupdate!"
233         LINGUAS=
234         files=`find ../../gtk2_ardour/ -name "*.mo"`
235
236         if [ -z "$files" ]; then
237                 echo ""
238                 echo "!!!! WARNING !!!! - Did not find any .mo files in ../../gtk2_ardour"
239                 echo ""
240         fi
241  
242         for file in $files 
243         do
244                 echo $file
245                 lang=`basename $file | sed 's/\.mo//'`
246                 mkdir -p $Locale/$lang/LC_MESSAGES
247                 cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
248                 LINGUAS="$LINGUAS $lang"
249         done
250
251         files=`find ../../libs/ardour/ -name "*.mo"`
252
253         if [ -z "$files" ]; then
254                 echo ""
255                 echo "!!!! WARNING !!!! - Did not find any .mo files in ../../libs/ardour"
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/libardour.mo
265         done
266
267         GTK_MESSAGES="atk10.mo gdk-pixbuf.mo gtk20-properties.mo gtk20.mo atk10.mo glib20.mo"
268         LOCALEROOT=/usr/share/locale
269
270         for l in $LINGUAS ; do
271                 echo "Copying GTK i18n files for $l..."
272                 for MO in $GTK_MESSAGES ; do 
273                         if [ -f $LOCALEROOT/$l/LC_MESSAGES/$MO ] ; then
274                                 cp $LOCALEROOT/$l/LC_MESSAGES/$MO $Locale/$l/LC_MESSAGES
275                         else
276                                 # try with just the language spec
277                                 just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
278                                 if [ -f $LOCALEROOT/$just_lang/LC_MESSAGES/$MO ] ; then
279                                         cp $LOCALEROOT/$just_lang/LC_MESSAGES/$MO $Locale/$just_lang/LC_MESSAGES
280                                 fi
281                         fi
282                 done
283         done
284 else
285         echo "Skipping NLS support"
286 fi
287
288 ### Find gtk ###
289 GTKROOT=`pkg-config --libs-only-L gtk+-2.0 | sed -e "s/-L//" -e "s/[[:space:]]//g"`
290 if [ ! -z "$GTKROOT" ]; then
291         echo "Found GTKROOT using pkg-config"
292 elif [ -d /usr/lib/gtk-2.0 ]; then
293         GTKROOT="/usr/lib"
294 elif [ -d /usr/local/lib/gtk-2.0 ]; then
295         GTKROOT="/usr/local/lib"
296 else
297         echo ""
298         echo "!!! ERROR !!! - Unable to locate gtk-2.0 directory. Packager will exit"
299         echo ""
300         exit 1
301 fi
302
303 echo "GTKROOT is ${GTKROOT}"
304 versionDir=`ls ${GTKROOT}/gtk-2.0/ | grep "[0-9]*\.[0-9]*\.[0-9]*"`
305
306 num=0
307 for name in $versionDir ; do
308     num=$(($num + 1))
309 done
310
311 if [ $num -eq 1 ]; then
312         GTKLIB=${GTKROOT}/gtk-2.0/$versionDir
313         echo "GTKLIB is ${GTKLIB}"
314 else
315         echo ""
316         echo "!!! ERROR !!! - More than one gtk-2.0 version found in ${GTKROOT}/gtk-2.0/  ( $versionDir ). Packager will exit"
317         echo ""
318         exit 1
319 fi
320
321
322 ### Find pango ###
323 PANGOROOT=`pkg-config --libs-only-L pango | sed -e "s/-L//" -e "s/[[:space:]]//g"`
324 if [ ! -z "$PANGOROOT" ]; then
325         echo "Found PANGOROOT using pkg-config"
326 elif [ -d /usr/lib/pango ]; then
327         PANGOROOT="/usr/lib"
328 elif [ -d /usr/local/lib/pango ]; then
329         PANGOROOT="/usr/local/lib"
330 else
331         echo ""
332         echo "!!! ERROR !!! - Unable to locate pango directory. Packager will exit"
333         echo ""
334         exit 1
335 fi
336
337 echo "PANGOROOT is ${PANGOROOT}"
338 versionDir=`ls ${PANGOROOT}/pango/ | grep "[0-9]*\.[0-9]*\.[0-9]*"`
339
340 num=0
341 for name in $versionDir ; do
342         num=$(($num + 1))
343 done
344
345 if [ $num -eq 1 ]; then
346         PANGOLIB=${PANGOROOT}/pango/$versionDir
347         echo "PANGOLIB is ${PANGOLIB}"
348 else
349         echo ""
350         echo "!!! ERROR !!! - More than one pango version found in ${PANGOROOT}/pango/  ( $versionDir ). Packager will exit"
351         echo ""
352         exit 1
353 fi
354
355
356 ### Find gdk-pixbuf ###
357 GDKPIXBUFROOT=`pkg-config --libs-only-L gdk-pixbuf-2.0 | sed -e "s/-L//" -e "s/[[:space:]]//g"`
358 if [ ! -z "$GDKPIXBUFROOT" ]; then
359         echo "Found GDKPIXBUFROOT using pkg-config"
360 elif [ -d /usr/lib/gdk-pixbuf-2.0 ]; then
361         GDKPIXBUFROOT="/usr/lib/gdk-pixbuf-2.0"
362 elif [ -d /usr/local/lib/gdk-pixbuf-2.0 ]; then
363         GDKPIXBUFROOT="/usr/local/lib/gdk-pixbuf-2.0"
364 elif [ -d ${GTKLIB}/loaders ]; then  #odd ball case
365         GDKPIXBUFROOT=${GTKROOT}
366         GDKPIXBUFLIB=${GTKLIB}
367 else
368         echo ""
369         echo "!!! ERROR !!! - Unable to locate gdk-pixbuf-2.0 directory. Packager will exit"
370         echo ""
371         exit 1
372 fi
373
374 echo "GDKPIXBUFROOT is ${GDKPIXBUFROOT}"
375
376 if [ -z ${GDKPIXBUFLIB} ]; then
377         versionDir=`ls ${GDKPIXBUFROOT}/gdk-pixbuf-2.0/ | grep "[0-9]*\.[0-9]*\.[0-9]*"`
378
379         num=0
380         for name in $versionDir ; do
381             num=$(($num + 1))
382         done
383
384         if [ $num -eq 1 ]; then
385                 GDKPIXBUFLIB=${GDKPIXBUFROOT}/gdk-pixbuf-2.0/$versionDir
386                 echo "GDKPIXBUFLIB is ${GDKPIXBUFLIB}"
387         else
388                 echo ""
389                 echo "!!! ERROR !!! - More than one gdk-pixbuf-2.0 version found in ${GDKPIXBUFROOT}/pango/  ( $versionDir ). Packager will exit"
390                 echo ""
391                 exit 1
392         fi
393 fi
394
395
396
397 echo "Copying all Pango modules ..."
398 cp -R $PANGOLIB/modules/*.so $Modules
399
400 echo "Copying all GDK Pixbuf loaders ..."
401 cp -R $GDKPIXBUFLIB/loaders/*.so $Loaders
402
403 pango-querymodules | sed "s?$PANGOLIB/?@ROOTDIR@/?" > $Etc/pango.modules.in
404 gdk-pixbuf-query-loaders | sed "s?$GDKPIXBUFLIB/?@ROOTDIR@/?" > $Etc/gdk-pixbuf.loaders.in
405
406 # We sort of rely on clearlooks, so include a version
407 # this one is special - we will set GTK_PATH to $Libraries/clearlooks
408
409 if [ ! -e ${GTKLIB}/engines/libclearlooks.so ]; then
410         echo ""
411         echo "!!! ERROR !!! - not able to locate libclearlooks.so"
412         echo ""
413         echo "Packager with exit"
414         exit 1
415 fi
416
417 echo "Copying clearlooks ..."
418 cp ${GTKLIB}/engines/libclearlooks.so $Libraries
419 mkdir -p $Libraries/clearlooks/engines
420 (cd $Libraries/clearlooks/engines && ln -s ../../libclearlooks* libclearlooks.so )
421
422 # LADSPA
423 if test x$WITH_LADSPA != x ; then
424         if test x$MIXBUS != x ; then
425                 plugdir=mixbus_ladspa
426         else
427                 plugdir=ladspa
428         fi
429         echo "Copying `ls $plugdir | wc -l` plugins ..."
430         if [ -d $plugdir ] ; then
431                 cp -r $plugdir/* $Plugins
432         fi
433 fi
434
435 # Control Surfaces
436 cp $BUILD_ROOT/libs/surfaces/*/libardour*.so* $Surfaces
437 # hack ... move libardour_cp back into Libraries
438 mv $Surfaces/libardourcp.so* $Libraries
439
440 # MidiMaps
441 cp $BUILD_ROOT/../../midi_maps/*.map $MidiMaps
442
443 # Panners
444 cp $BUILD_ROOT/libs/panners/*/lib*.so* $Panners
445
446 # VAMP plugins that we use
447 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.so* $Libraries
448
449 OURLIBDIR=$BUILD_ROOT/libs
450 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/qm-dsp
451
452 echo $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
453
454 checkedIdx=0
455
456 while [ true ] ; do 
457         missing=false
458         filelist=`find $APPLIB/ -type f`
459         filelist="$APPBIN/$MAIN_EXECUTABLE $filelist"
460
461         for file in $filelist  ; do 
462                 if ! file $file | grep -qs ELF ; then
463                         continue
464                 fi
465
466                 # speed this up a bit by not checking things multiple times.
467                 for i in "${depCheckedList[@]}"; do
468                         if [ $i == $file ]; then
469                                 continue 2
470                         fi
471                 done
472                 depCheckedList[$checkIdx]=$file
473                 checkIdx=$(($checkIdx + 1))
474                 
475                 # do not include libjack
476                 deps=`LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | awk '{print $3}'`
477
478                 # LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | egrep "(/opt/|/local/|libs/|/usr/lib|/gtk)" | grep -v 'libjack\.'
479                 echo -n "."
480                 for dep in $deps ; do
481                         if test "not" = ${dep}; then 
482                                 echo ""
483                                 echo "!!! ERROR !!! - Missing dependant library for $file."
484                                 echo ""
485                                 (LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file)
486                                 echo ""
487                                 echo "!!! ERROR !!! - See Above"
488                                 exit 1
489                         fi
490
491                         # don't use anything mapped at a specific address
492                         if echo $dep | grep -qs '0x' ; then continue; fi
493                         # don't include /lib
494                         if echo $dep | grep -qs "^/lib/" ; then continue; fi
495                         # don't include jack
496                         if echo $dep | grep -qs libjack ; then continue; fi
497                         # don't include any X Window libraries
498                         if echo $dep | grep -qs libX ; then continue; fi  
499                         if echo $dep | grep -qs libxcb ; then continue; fi  
500                         # don't include libc
501                         if echo $dep | grep -qs 'libc\.' ; then continue; fi
502                         # don't include libstdc++
503                         if echo $dep | grep -qs libstdc++ ; then continue; fi
504
505                         base=`basename $dep`
506                         if ! test -f $Libraries/$base; then
507                                 parent=$(basename ${file})
508                                 if echo $dep | grep -sq '^libs' ; then
509                                         echo "Copying dependant lib $BUILD_ROOT/$dep    (required by ${parent})"
510                                         cp $BUILD_ROOT/$dep $Libraries
511                                 else
512                                         echo "Copying dependant lib $dep    (required by ${parent})"
513                                         cp $dep $Libraries
514                                         deplibs = "$deplibs $base"
515                                 fi
516                                 missing=true
517                         fi
518                 done
519         done
520         if test x$missing = xfalse ; then
521                 # everything has been found
522                 break
523         fi
524 done
525 echo
526
527 # strip libraries
528 if test x$STRIP = xall ; then
529     echo Stripping all libraries
530     find $APPLIB/ -name "*.so*" | xargs strip
531 else if test x$STRIP = xsome ; then
532     echo Stripping dependent libraries
533     for l in $deplibs ; do
534         strip $APPLIB/$l
535     done
536 fi
537 find $APPLIB/ -name "*.so*" | xargs chmod a+rx
538
539 echo "Copying other stuff to $APPDIR  ..."
540
541 # these are all generated by waf
542 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings       $Etc
543 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Etc
544 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Etc
545 cp $BUILD_ROOT/ardour_system.rc $Etc/ardour_system.rc
546 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Etc
547 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Etc
548
549 # these are copied straight from the source tree
550
551 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui.conf
552 cp ../../instant.xml $Etc/instant.xml
553 cp -r ../../gtk2_ardour/icons $Etc
554 cp -r ../../gtk2_ardour/pixmaps $Etc
555
556 #
557 # put sooper sekrit ingredients here and they will be copied
558 #
559
560 if [ -d specialSauce ] ; then
561         cp -r specialSauce $Etc
562 fi
563
564 # share stuff
565
566 cp -R ../../gtk2_ardour/splash.png $Shared
567 # currently no templates
568 #cp ../../templates/*.template $Shared/templates/
569
570 # go through and recursively remove any .svn dirs in the bundle
571 for svndir in `find $APPDIR -name .svn -type d`; do
572         rm -rf $svndir
573 done
574
575 #
576 # Add the uninstaller
577 #
578 sed -e "s/%REPLACE_PGM%/${APPNAME}/" -e "s/%REPLACE_VENDOR%/${VENDOR}/" -e "s/%REPLACE_VERSION%/${release_version}/" -e "s/%REPLACE_BUILD%/${svn_version}/" -e "s/%REPLACE_TYPE%/${BUILDTYPE}/" < uninstall.sh.in > $APPBIN/${APP_VER_NAME}.uninstall.sh
579 chmod a+x $APPBIN/${APP_VER_NAME}.uninstall.sh
580
581 #Sanity Check file
582 if [ -e $BUILD_ROOT/tools/sanity_check/sanityCheck ]; then
583         cp $BUILD_ROOT/tools/sanity_check/sanityCheck $APPBIN
584 else
585         echo "!!!ERROR !!! sanityCheck program is missing. packager will exit without being complete"
586         exit 1
587 fi
588
589 echo "Building tarball ..."
590
591 rm -f $APPDIR.tar.bz2
592 tar -cjf $APPDIR.tar.bz2 $APPDIR
593
594 rm -rf $APPDIR/
595
596 echo "Done."
597