#!/bin/bash
# script for pulling together a MacOSX app bundle.
GTKQUARTZ_ROOT=/opt/gtk
SAE=
WITH_JACK=1
WITH_LADSPA=1
STRIP=1
PRINT_SYSDEPS=
while [ $# -gt 0 ] ; do
echo "arg = $1"
case $1 in
#
# top level build targets
#
--sae) SAE=1 ; WITH_JACK=1; WITH_LADSPA=1; STRIP= ; shift ;;
--public) SAE= ; WITH_JACK=; WITH_LADSPA=1; STRIP= ; shift ;;
--allinone) SAE= ; WITH_JACK=1; WITH_LADSPA=1; STRIP= ; shift ;;
--test) SAE= ; WITH_JACK=; WITH_LADSPA=; STRIP= ; shift ;;
#
# specific build flags
#
--nojack) WITH_JACK= ; shift ;;
--noladspa) WITH_LADSPA= ; shift ;;
--nostrip) STRIP= ; shift ;;
--sysdeps) PRINT_SYSDEPS=1; shift ;;
esac
done
version=`grep -m 1 '^ardour_version' ../../SConstruct | cut -d' ' -f 3 | sed "s/'//g"`
echo "Version is $version"
info_string="$version built on `hostname` by `whoami` on `date`"
echo "Info string is $info_string"
# setup directory structure
APPROOT=Ardour2.app/Contents
Frameworks=$APPROOT/Frameworks
Resources=$APPROOT/Resources
Plugins=$APPROOT/Plugins
Surfaces=$APPROOT/Surfaces
Shared=$Resources/share
Etc=$Resources/etc
if [ x$PRINT_SYSDEPS != x ] ; then
#
# print system dependencies
#
for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do
if ! file $file | grep -qs Mach-O ; then
continue
fi
otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)"
done | sort | uniq
exit 0
fi
echo "Removing old Ardour2.app tree ..."
rm -rf Ardour2.app
echo "Building new app directory structure ..."
# only bother to make the longest paths
mkdir -p $APPROOT/MacOS
mkdir -p $APPROOT/Resources
mkdir -p $APPROOT/Plugins
mkdir -p $APPROOT/Surfaces
mkdir -p $Frameworks/modules
mkdir -p $Shared/templates
mkdir -p $Etc
# maybe set variables
env=""
if test x$SAE != x ; then
env="$envARDOUR_SAEtrue"
#
# current default for SAE version is German keyboard layout
#
env="$envARDOUR_KEYBOARD_LAYOUTde"
env="$envARDOUR_UI_CONFardour2_ui_sae.conf"
fi
#
# if we're not going to bundle JACK, make sure we can find
# jack in the places where it might be
#
if test x$WITH_JACK != x ; then
env="$envARDOUR_WITH_JACKtrue"
else
env="$envPATH/usr/local/bin:/opt/bin"
env="$envDYLIB_FALLBACK_LIBRARY_PATH/usr/local/lib:/opt/lib"
fi
env="LSEnvironmentARDOUR_BUNDLEDtrue$env"
# edit plist
sed -e "s?@ENV@?$env?g" \
-e "s?@VERSION@?$version?g" \
-e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
# copy static files
cp Info.plist $APPROOT
cp -R Resources $APPROOT
echo "Copying ardour executable ...."
cp ../../gtk2_ardour/ardour-$version $APPROOT/MacOS/Ardour2
if test x$SAE != x ; then
cp ../../gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
fi
if test x$STRIP != x ; then
strip $APPROOT/MacOS/Ardour2
fi
if test x$WITH_JACK != x ; then
cp /usr/local/lib/jack/jack_coreaudio.so $Frameworks
cp /usr/local/bin/jackd $APPROOT/MacOS
fi
cp -R $GTKQUARTZ_ROOT/etc/* $Etc
echo "Copying all Pango modules ..."
cp -R $GTKQUARTZ_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
echo "Copying all GDK Pixbuf loaders ..."
cp -R $GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/*.so $Frameworks/modules
# charset alias file
cp -R $GTKQUARTZ_ROOT/lib/charset.alias $Resources
pwd=`pwd`
if test x$WITH_LADSPA != x ; then
echo "Copying `ls ladspa | wc -l` plugins ..."
cp -r ladspa/* $Plugins
fi
# generate new Pango module file
cat > pangorc < $Resources/pango.modules
rm pangorc
# generate a new GDK pixbufs loaders file
sed "s?$GTKQUARTZ_ROOT/lib/gtk-2.0/2.10.0/loaders/?@executable_path/../Frameworks/modules/?" < $GTKQUARTZ_ROOT/etc/gtk-2.0/gdk-pixbuf.loaders > $Resources/gdk-pixbuf.loaders
# this one is special - we will set GTK_PATH to $Frameworks/clearlooks
cp ../../libs/clearlooks/libclearlooks.dylib $Frameworks
mkdir -p $Frameworks/clearlooks/engines
(cd $Frameworks/clearlooks/engines && ln -s ../../libclearlooks.dylib libclearlooks.dylib && ln -s ../../libclearlooks.dylib libclearlooks.so)
# XXX STILL NEED TO DO PANNERS FOR TRUNK
cp ../../libs/surfaces/*/libardour_*.dylib $Surfaces
# hack ... move libardour_cp back into Frameworks
mv $Surfaces/libardour_cp.dylib $Frameworks
# VAMP plugins that we use
cp ../../libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
while [ true ] ; do
missing=false
for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do
if ! file $file | grep -qs Mach-O ; then
continue
fi
if test x$WITH_JACK != x ; then
deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)"`
else
# do not include libjack
deps=`otool -L $file | awk '{print $1}' | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | grep -v 'libjack\.'`
fi
echo -n "."
for dep in $deps ; do
base=`basename $dep`
if ! test -f $Frameworks/$base; then
if echo $dep | grep -sq '^libs' ; then
cp ../../$dep $Frameworks
else
cp $dep $Frameworks
fi
missing=true
fi
done
done
if test x$missing = xfalse ; then
# everything has been found
break
fi
done
echo
echo "Copying other stuff to Ardour2.app ..."
cp ../../gtk2_ardour/ergonomic-us.bindings $Resources
cp ../../gtk2_ardour/mnemonic-us.bindings $Resources
cp ../../gtk2_ardour/SAE-de.bindings $Resources
cp ../../gtk2_ardour/ardour.menus $Resources
cp ../../gtk2_ardour/ardour-sae.menus $Resources
if test x$SAE != x ; then
cp ../../ardour_system_sae.rc $Resources/ardour_system.rc
echo cp ../../ardour_system_sae.rc $Resources/ardour_system.rc
else
cp ../../ardour_system.rc $Resources/ardour_system.rc
echo FOO cp ../../ardour_system.rc $Resources/ardour_system.rc
fi
cp ../../gtk2_ardour/ardour2_ui_sae.conf $Resources
cp ../../gtk2_ardour/ardour2_ui_default.conf $Resources
cp ../../gtk2_ardour/ardour2_ui_light.rc $Resources
cp ../../gtk2_ardour/ardour2_ui_dark.rc $Resources
cp -r ../../gtk2_ardour/icons $Resources
cp -r ../../gtk2_ardour/pixmaps $Resources
# share stuff
cp -R ../../gtk2_ardour/splash.png $Shared
cp ../../templates/*.template $Shared/templates/
# go through and recursively remove any .svn dirs in the bundle
for svndir in `find Ardour2.app -name .svn -type dir`; do
rm -rf $svndir
done
# now fix up the executables
echo "Fixing up executable dependency names ..."
executables="Ardour2"
if test x$WITH_JACK != x ; then
executables="$executables jackd"
fi
if test x$SAE != x ; then
executables="$executables gtkevents"
fi
for exe in $executables; do
EXE=$APPROOT/MacOS/$exe
changes=""
if test x$WITH_JACK != x ; then
for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
base=`basename $lib`
changes="$changes -change $lib @executable_path/../Frameworks/$base"
done
else
for lib in `otool -L $EXE | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
base=`basename $lib`
changes="$changes -change $lib @executable_path/../Frameworks/$base"
done
fi
if test "x$changes" != "x" ; then
install_name_tool $changes $EXE
fi
done
echo "Fixing up library names ..."
# now do the same for all the libraries we include
for dylib in $Frameworks/*.dylib $Frameworks/modules/*.so $Surfaces/*.dylib ; do
# skip symlinks
if test ! -L $dylib ; then
# change all the dependencies
changes=""
if test x$WITH_JACK != x ; then
for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}'` ; do
base=`basename $lib`
changes="$changes -change $lib @executable_path/../Frameworks/$base"
done
else
for lib in `otool -L $dylib | egrep "($GTKQUARTZ_ROOT|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
base=`basename $lib`
changes="$changes -change $lib @executable_path/../Frameworks/$base"
done
fi
if test "x$changes" != x ; then
if install_name_tool $changes $dylib ; then
:
else
exit 1
fi
fi
# now the change what the library thinks its own name is
base=`basename $dylib`
install_name_tool -id @executable_path/../Frameworks/$base $dylib
fi
done
echo "Done."