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