552c2764195876c876fd6f3ac7e6bd3f4352da1d
[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 if test x$WITH_NLS != x ; then
199         echo "NLS support ..."
200         echo "I hope you remembered to run scons msgupdate!"
201         LINGUAS=
202         files=`find $BUILD_ROOT/gtk2_ardour/ -name "*.mo"`
203
204         if [ -z "$files" ]; then
205                 echo ""
206                 echo "!!!! WARNING !!!! - Did not find any .mo files in $BUILD_ROOT/gtk2_ardour"
207                 echo ""
208         fi
209  
210         for file in $files 
211         do
212                 echo $file
213                 lang=`basename $file | sed 's/\.mo//'`
214                 mkdir -p $Locale/$lang/LC_MESSAGES
215                 cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
216                 LINGUAS="$LINGUAS $lang"
217         done
218
219         files=`find ../../libs/ardour/ -name "*.mo"`
220
221         if [ -z "$files" ]; then
222                 echo ""
223                 echo "!!!! WARNING !!!! - Did not find any .mo files in ../../libs/ardour"
224                 echo ""
225         fi
226
227         for file in $files 
228         do
229                 echo $file
230                 lang=`basename $file | sed 's/\.mo//'`
231                 mkdir -p $Locale/$lang/LC_MESSAGES
232                 cp $file $Locale/$lang/LC_MESSAGES/libardour.mo
233         done
234
235         GTK_MESSAGES="atk10.mo gdk-pixbuf.mo gtk20-properties.mo gtk20.mo atk10.mo glib20.mo"
236         LOCALEROOT=/usr/share/locale
237
238         for l in $LINGUAS ; do
239                 echo "Copying GTK i18n files for $l..."
240                 for MO in $GTK_MESSAGES ; do 
241                         if [ -f $LOCALEROOT/$l/LC_MESSAGES/$MO ] ; then
242                                 cp $LOCALEROOT/$l/LC_MESSAGES/$MO $Locale/$l/LC_MESSAGES
243                         else
244                                 # try with just the language spec
245                                 just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
246                                 if [ -f $LOCALEROOT/$just_lang/LC_MESSAGES/$MO ] ; then
247                                         cp $LOCALEROOT/$just_lang/LC_MESSAGES/$MO $Locale/$just_lang/LC_MESSAGES
248                                 fi
249                         fi
250                 done
251         done
252 else
253         echo "Skipping NLS support"
254 fi
255
256 ### Find gtk ###
257 GTKROOT=`pkg-config --libs-only-L gtk+-2.0 | sed -e "s/-L//" -e "s/[[:space:]]//g"`
258 if [ ! -z "$GTKROOT" ]; then
259         echo "Found GTKROOT using pkg-config"
260 elif [ -d /usr/lib/gtk-2.0 ]; then
261         GTKROOT="/usr/lib/gtk-2.0"
262 elif [ -d /usr/local/lib/gtk-2.0 ]; then
263         GTKROOT="/usr/local/lib/gtk-2.0"
264 else
265         echo ""
266         echo "!!! ERROR !!! - Unable to locate gtk-2.0 directory. Packager will exit"
267         echo ""
268         exit 1
269 fi
270
271 echo "GTKROOT is ${GTKROOT}"
272 versionDir=`ls ${GTKROOT}/gtk-2.0/ | grep "[0-9]*\.[0-9]*\.[0-9]*"`
273
274 num=0
275 for name in $versionDir ; do
276     num=$(($num + 1))
277 done
278
279 if [ $num -eq 1 ]; then
280         GTKLIB=${GTKROOT}/gtk-2.0/$versionDir
281         echo "GTKLIB is ${GTKLIB}"
282 else
283         echo ""
284         echo "!!! ERROR !!! - More than one gtk-2.0 version found in ${GTKROOT}/gtk-2.0/  ( $versionDir ). Packager will exit"
285         echo ""
286         exit 1
287 fi
288
289
290 ### Find pango ###
291 PANGOROOT=`pkg-config --libs-only-L pango | sed -e "s/-L//" -e "s/[[:space:]]//g"`
292 if [ ! -z "$PANGOROOT" ]; then
293         echo "Found PANGOROOT using pkg-config"
294 elif [ -d /usr/lib/pango ]; then
295         PANGOROOT="/usr/lib/pango"
296 elif [ -d /usr/local/lib/pango ]; then
297         PANGOROOT="/usr/local/lib/pango"
298 else
299         echo ""
300         echo "!!! ERROR !!! - Unable to locate pango directory. Packager will exit"
301         echo ""
302         exit 1
303 fi
304
305 echo "PANGOROOT is ${PANGOROOT}"
306 versionDir=`ls ${PANGOROOT}/pango/ | grep "[0-9]*\.[0-9]*\.[0-9]*"`
307
308 num=0
309 for name in $versionDir ; do
310         num=$(($num + 1))
311 done
312
313 if [ $num -eq 1 ]; then
314         PANGOLIB=${PANGOROOT}/pango/$versionDir
315         echo "PANGOLIB is ${PANGOLIB}"
316 else
317         echo ""
318         echo "!!! ERROR !!! - More than one pango version found in ${PANGOROOT}/pango/  ( $versionDir ). Packager will exit"
319         echo ""
320         exit 1
321 fi
322
323
324 ### Find gdk-pixbuf ###
325 GDKPIXBUFROOT=`pkg-config --libs-only-L gdk-pixbuf-2.0 | sed -e "s/-L//" -e "s/[[:space:]]//g"`
326 if [ ! -z "$GDKPIXBUFROOT" ]; then
327         echo "Found GDKPIXBUFROOT using pkg-config"
328 elif [ -d /usr/lib/gdk-pixbuf-2.0 ]; then
329         GDKPIXBUFROOT="/usr/lib/gdk-pixbuf-2.0"
330 elif [ -d /usr/local/lib/gdk-pixbuf-2.0 ]; then
331         GDKPIXBUFROOT="/usr/local/lib/gdk-pixbuf-2.0"
332 elif [ -d ${GTKLIB}/loaders ]; then  #odd ball case
333         GDKPIXBUFROOT=${GTKROOT}
334         GDKPIXBUFLIB=${GTKLIB}
335 else
336         echo ""
337         echo "!!! ERROR !!! - Unable to locate gdk-pixbuf-2.0 directory. Packager will exit"
338         echo ""
339         exit 1
340 fi
341
342 echo "GDKPIXBUFROOT is ${GDKPIXBUFROOT}"
343
344 if [ -z ${GDKPIXBUFLIB} ]; then
345         versionDir=`ls ${GDKPIXBUFROOT}/gdk-pixbuf-2.0/ | grep "[0-9]*\.[0-9]*\.[0-9]*"`
346
347         num=0
348         for name in $versionDir ; do
349             num=$(($num + 1))
350         done
351
352         if [ $num -eq 1 ]; then
353                 GDKPIXBUFLIB=${GDKPIXBUFROOT}/gdk-pixbuf-2.0/$versionDir
354                 echo "GDKPIXBUFLIB is ${GDKPIXBUFLIB}"
355         else
356                 echo ""
357                 echo "!!! ERROR !!! - More than one gdk-pixbuf-2.0 version found in ${GDKPIXBUFROOT}/pango/  ( $versionDir ). Packager will exit"
358                 echo ""
359                 exit 1
360         fi
361 fi
362
363
364
365 echo "Copying all Pango modules ..."
366 cp -R $PANGOLIB/modules/*.so $Modules
367
368 echo "Copying all GDK Pixbuf loaders ..."
369 cp -R $GDKPIXBUFLIB/loaders/*.so $Loaders
370
371 pango-querymodules | sed "s?$PANGOLIB/?@ROOTDIR@/?" > $Etc/pango.modules.in
372 gdk-pixbuf-query-loaders | sed "s?$GDKPIXBUFLIB/?@ROOTDIR@/?" > $Etc/gdk-pixbuf.loaders.in
373
374 # We sort of rely on clearlooks, so include a version
375 # this one is special - we will set GTK_PATH to $Libraries/clearlooks
376
377 #if [ ! -e ${GTKLIB}/engines/libclearlooks.so ]; then
378 #       echo ""
379 #       echo "!!! ERROR !!! - not able to locate libclearlooks.so"
380 #       echo ""
381 #       echo "Packager with exit"
382 #       exit 1
383 #fi
384
385 #echo "Copying clearlooks ..."
386 #cp ${GTKLIB}/engines/libclearlooks.so $Libraries
387 #mkdir -p $Libraries/clearlooks/engines
388 #(cd $Libraries/clearlooks/engines && ln -s ../../libclearlooks* libclearlooks.so )
389
390 # LADSPA
391 if test x$WITH_LADSPA != x ; then
392         if test x$MIXBUS != x ; then
393                 plugdir=mixbus_ladspa
394         else
395                 plugdir=ladspa
396         fi
397         echo "Copying `ls $plugdir | wc -l` plugins ..."
398         if [ -d $plugdir ] ; then
399                 cp -r $plugdir/* $Plugins
400         fi
401 fi
402
403 # Control Surfaces
404 cp $BUILD_ROOT/libs/surfaces/*/libardour*.so* $Surfaces
405 # hack ... move libardour_cp back into Libraries
406 mv $Surfaces/libardourcp.so* $Libraries
407
408 # Panners
409 cp $BUILD_ROOT/libs/panners/*/lib*.so* $Panners
410
411 # VAMP plugins that we use
412 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.so* $Libraries
413
414 OURLIBDIR=$BUILD_ROOT/libs
415 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
416
417 echo $OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
418
419 checkedIdx=0
420
421 while [ true ] ; do 
422         missing=false
423         filelist=`find $APPLIB/ -type f`
424         filelist="$APPBIN/$MAIN_EXECUTABLE $filelist"
425
426         for file in $filelist  ; do 
427                 if ! file $file | grep -qs ELF ; then
428                         continue
429                 fi
430
431                 # speed this up a bit by not checking things multiple times.
432                 for i in "${depCheckedList[@]}"; do
433                         if [ $i == $file ]; then
434                                 continue 2
435                         fi
436                 done
437                 depCheckedList[$checkIdx]=$file
438                 checkIdx=$(($checkIdx + 1))
439                 
440                 # do not include libjack
441                 deps=`LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | awk '{print $3}'`
442
443                 # LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file | egrep "(/opt/|/local/|libs/|/usr/lib|/gtk)" | grep -v 'libjack\.'
444                 echo -n "."
445                 for dep in $deps ; do
446                         if test "not" = ${dep}; then 
447                                 echo ""
448                                 echo "!!! ERROR !!! - Missing dependant library for $file."
449                                 echo ""
450                                 (LD_LIBRARY_PATH=$OURLIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ldd $file)
451                                 echo ""
452                                 echo "!!! ERROR !!! - See Above"
453                                 exit 1
454                         fi
455
456                         # don't use anything mapped at a specific address
457                         if echo $dep | grep -qs '0x' ; then continue; fi
458                         # don't include /lib
459                         if echo $dep | grep -qs "^/lib/" ; then continue; fi
460                         # don't include jack
461                         if echo $dep | grep -qs libjack ; then continue; fi
462                         # don't include any X Window libraries
463                         if echo $dep | grep -qs libX ; then continue; fi  
464                         if echo $dep | grep -qs libxcb ; then continue; fi  
465                         # don't include libc
466                         if echo $dep | grep -qs 'libc\.' ; then continue; fi
467                         # don't include libstdc++
468                         if echo $dep | grep -qs libstdc++ ; then continue; fi
469
470                         base=`basename $dep`
471                         if ! test -f $Libraries/$base; then
472                                 parent=$(basename ${file})
473                                 if echo $dep | grep -sq '^libs' ; then
474                                         echo "Copying dependant lib $BUILD_ROOT/$dep    (required by ${parent})"
475                                         cp $BUILD_ROOT/$dep $Libraries
476                                 else
477                                         echo "Copying dependant lib $dep    (required by ${parent})"
478                                         cp $dep $Libraries
479                                 fi
480                                 missing=true
481                         fi
482                 done
483         done
484         if test x$missing = xfalse ; then
485                 # everything has been found
486                 break
487         fi
488 done
489 echo
490
491 # strip libraries
492 echo Stripping libraries
493 find $APPLIB/ -name "*.so*" | xargs strip
494 find $APPLIB/ -name "*.so*" | xargs chmod a+rx
495
496 echo "Copying other stuff to $APPDIR  ..."
497
498 # these are all generated by waf
499 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings       $Etc
500 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Etc
501 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Etc
502 cp $BUILD_ROOT/ardour_system.rc $Etc/ardour_system.rc
503 # temporarily unavailable
504 #cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Etc
505 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Etc
506
507 # these are copied straight from the source tree
508
509 cp ../../gtk2_ardour/ardour3_ui_default.conf $Etc/ardour3_ui.conf
510 cp ../../instant.xml $Etc/instant.xml
511 cp -r ../../gtk2_ardour/icons $Etc
512 cp -r ../../gtk2_ardour/pixmaps $Etc
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 # currently no templates
526 #cp ../../templates/*.template $Shared/templates/
527
528 # go through and recursively remove any .svn dirs in the bundle
529 for svndir in `find $APPDIR -name .svn -type d`; do
530         rm -rf $svndir
531 done
532
533 #Sanity Check file
534 if [ -e $BUILD_ROOT/tools/sanity_check/sanityCheck ]; then
535         cp $BUILD_ROOT/tools/sanity_check/sanityCheck $APPDIR
536 else
537         echo "!!!ERROR !!! sanityCheck program is missing. packager will exit without being complete"
538         exit 1
539 fi
540
541 #
542 # and now ... the final package
543
544
545 if [ x$MIXBUS != x ] ; then
546
547         # Mixbus packaging
548
549         echo "Creating Mixbus packaging directory"
550         cp MixBus_Install_QuickStart.pdf "$APPDIR/Mixbus Install & Quick Start Guide.pdf"
551         
552         if [ -x $EXTERNAL_JACK != x ] ; then
553                 cp $EXTERNAL_JACK $PRODUCT_PKG_DIR
554         fi
555 fi
556
557 echo "Building tarball ..."
558
559 rm -f $APPDIR.tar.bz2
560 tar -cjf $APPDIR.tar.bz2 $APPDIR
561
562 echo "Done."
563