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