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