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