Blame autobuild/synfigstudio-osx-build.sh

301617
#!/bin/bash
301617
#
301617
# SynfigStudio mac package build script
301617
# Copyright (c) 2008-2009 Simone Karin Lehmann (GimpOSX parts)
301617
# Copyright (c) 2012-2013 Konstantin Dmitriev
301617
#
301617
# This package is free software; you can redistribute it and/or
301617
# modify it under the terms of the GNU General Public License as
301617
# published by the Free Software Foundation; either version 2 of
301617
# the License, or (at your option) any later version.
301617
#
301617
# This package is distributed in the hope that it will be useful,
301617
# but WITHOUT ANY WARRANTY; without even the implied warranty of
301617
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
301617
# General Public License for more details.
301617
#
301617
#
301617
# = Usage notes =
BobSynfig c01942
#
301617
# * You need to have XCode and git installed
301617
# * Builds from current repository, current revision. So you should manually checkout the desired revision to build
301617
# * If no repository found - then  sources fetched into ~/src/synfig and the latest master branch is built
301617
# * Executing script without arguments makes a full clean build and produces dmg package
BobSynfig c01942
# * You can pass arguments to the script to invoke particular stage.
301617
#	Available stages: mkmacports, mkdeps, mketl, mksynfig, mksynfigstudio, mkapp, mkdmg
BobSynfig c01942
#	Example:
301617
#		synfigstudio-osx-build.sh mkdeps
301617
# * You can pass a custom command to be invoked in the build environment.
301617
#	Example (uninstalls glibmm package from the buildroot):
301617
#		synfigstudio-osx-build.sh port uninstall glibmm
301617
# * If you suspect something is wrong with your macports installation you can always start from scratch by removing ~/src/macports dir
301617
47e223
# TODO: Don't build into /tmp/skl
47e223
# TODO: Disable 32bit?
301617
301617
301617
#======= HEADER ===========
301617
301617
set -e
301617
301617
export RELEASE=1
301617
export BUILDROOT_VERSION=1
301617
3cd156
if [ `whoami` != "root" ]; then
3cd156
	echo "Please use sudo to run this script. Aborting."
3cd156
	exit 1
3cd156
fi
3cd156
4120fe
export SCRIPTPATH=$(cd `dirname "$0"`; pwd)
4120fe
4120fe
SYNFIG_REPO_DIR=$(dirname "$SCRIPTPATH")
4120fe
SCRIPTDIR_IS_REPO=0
4120fe
4120fe
if [ -e "$SYNFIG_REPO_DIR/build.conf" ]; then
4120fe
	source "$SYNFIG_REPO_DIR/build.conf"
4120fe
fi
4120fe
4120fe
if [ ! -z $UNIVERSAL ] && [[ ! $UNIVERSAL == 0 ]]; then
ab42cc
export BUILDDIR=~/synfig-buildroot/build.u
822cb2
else
4120fe
export BUILDDIR=~/synfig-buildroot/build
4120fe
export UNIVERSAL=0
822cb2
fi
3cd156
ab42cc
if [ ! -z $X11 ] && [[ ! $X11 == 0 ]]; then
8fb81e
	export X11=1
3cd156
	export BUILDDIR=${BUILDDIR}.x11
3cd156
fi
3cd156
ab42cc
if [ ! -z $DEBUG ] && [[ ! $DEBUG == 0 ]]; then
3cd156
	echo
3cd156
	echo "Debug mode: enabled"
3cd156
	echo
3cd156
	DEBUG='--enable-debug --enable-optimization=0'
3cd156
	export BUILDDIR=${BUILDDIR}.debug
3cd156
else
3cd156
	DEBUG=''
3cd156
fi
3cd156
d31a03
LNKDIR=/tmp/skl/SynfigStudio
7a8797
MACPORTS=$LNKDIR/Contents/Resources
e8baa6
MPSRC=MacPorts-2.3.3
301617
301617
301617
export SYNFIG_PREFIX=${MACPORTS}/synfig/
a5abb5
export PATH="$MACPORTS/bin:${SYNFIG_PREFIX}/bin:$MACPORTS/sbin:$PATH"
a5abb5
export SYNFIG_MODULE_LIST=${SYNFIG_PREFIX}/etc/synfig_modules.cfg
301617
export PKG_CONFIG_PATH=${MACPORTS}/lib/pkgconfig:${SYNFIG_PREFIX}/lib/pkgconfig$PKG_CONFIG_PATH
a5abb5
export LD_LIBRARY_PATH=${MACPORTS}/lib:${SYNFIG_PREFIX}/lib:${SYNFIG_PREFIX}/lib64:$LD_LIBRARY_PATH
a5abb5
a5abb5
#export ACLOCAL_FLAGS="-I ${SYNFIG_PREFIX}/share/aclocal -I ${MACPORTS}/share/aclocal"
Carlos Lopez ac6eb5
#export CPPFLAGS="-fpermissive -I${MACPORTS}/include -I${SYNFIG_PREFIX}/include"
Carlos Lopez ac6eb5
export CPPFLAGS="-I${MACPORTS}/include -I${SYNFIG_PREFIX}/include"
822cb2
export LDFLAGS="-L${MACPORTS}/lib -L${SYNFIG_PREFIX}/lib"
4120fe
if [[ ! $UNIVERSAL == 0 ]]; then
3f5336
export CFLAGS="-arch i386 -arch x86_64"
3f5336
export CXXFLAGS="-arch i386 -arch x86_64"
3f5336
export LDFLAGS="$LDFLAGS -arch i386 -arch x86_64"
822cb2
fi
301617
301617
#======= HEADER END ===========
301617
301617
301617
301617
prepare()
301617
{
301617
	# == workarounds ==
BobSynfig c01942
301617
	#We should do that, otherwise python won't build:
656c5c
	if [ -e $MACPORTS/tmp/app ]; then
656c5c
		[ ! -e $MACPORTS/tmp/app.bak ] || rm -rf $MACPORTS/tmp/app.bak
656c5c
		echo "Backing up custom /Applications/MacPorts dir..."
656c5c
		mv $MACPORTS/tmp/app $MACPORTS/tmp/app.bak || true
301617
	fi
BobSynfig c01942
6d308d
	# Cleanup some stuff, remaining from older installations
6d308d
	rm /Library/LaunchDaemons/org.macports.rsyncd.plist || true
BobSynfig c01942
301617
	# == symlinks ==
BobSynfig c01942
301617
	if [ ! -e "$BUILDDIR" ]; then
301617
	  mkdir -p "$BUILDDIR"
301617
	fi
301617
301617
	echo -n setting symlink to build directory...
301617
	test -d /tmp/skl || mkdir -p /tmp/skl
d7a7cb
	chmod a+w /tmp/skl
7a8797
	test -L $LNKDIR && rm $LNKDIR
3f5336
	test -L $MACPORTS && rm $MACPORTS
3f5336
	mkdir -p `dirname $MACPORTS`
3f5336
	ln -s "$BUILDDIR" $MACPORTS
3f5336
	chmod a+w $MACPORTS
301617
	echo
301617
}
301617
301617
mkmacports()
301617
{
301617
301617
# cleanup previous installation
e8baa6
if [ -e "$BUILDDIR/" ]; then
e8baa6
  rm -rf "$BUILDDIR/"
301617
fi
301617
e8baa6
mkdir -p "$BUILDDIR/"
cff4fc
mkdir -p ~/src
e8baa6
cd ~/src
301617
301617
# compile MacPorts and do a selfupdate
301617
if [ ! -d "$MPSRC" ]; then
301617
  #curl -LO http://svn.macports.org/repository/macports/downloads/$MPSRC/$MPSRC.tar.bz2
301617
  curl -LO http://distfiles.macports.org/MacPorts/$MPSRC.tar.bz2
301617
  echo -n extracting MacPorts sources ...
301617
  bunzip2 $MPSRC.tar.bz2
301617
  tar -xf $MPSRC.tar
301617
  rm $MPSRC.tar
301617
  echo done.
301617
fi
301617
301617
# this is the main part on which this building and packaging process relies on
301617
echo Compiling and updating MacPorts...
301617
cd $MPSRC
80db0b
./configure --prefix $MACPORTS --with-tclpackage=$MACPORTS/share/macports/Tcl \
80db0b
	--with-install-user=`id -un` \
80db0b
	--with-install-group=`id -gn`
301617
make clean
a9d02c
make -j$JOBS
301617
#sudo make install
301617
make install
301617
cd - > /dev/null
301617
export PATH="$MACPORTS/bin:$MACPORTS/sbin:$PATH"
301617
301617
# give our build directory user perms so we don't need sudo in further steps. Avoid sudo whenever it's possible!
301617
#sudo chown -R $UID "$BUILDDIR"
301617
301617
# do a selfupdate
301617
echo Now selfupdating MacPorts. Please wait ...
301617
port -d selfupdate
301617
301617
# now give some hints
301617
echo
301617
echo "Yor MacPorts installation is now ready to build SynfigStudio for Mac OS X."
301617
}
301617
301617
mkdeps()
301617
{
301617
	# test if we have MacPorts  installed
301617
	if [ ! -e "$MACPORTS/bin/port" ]; then
301617
		mkmacports
301617
	fi
301617
301617
	if [ -e "$MACPORTS/bin/synfig" ]; then
301617
		echo "=========================== !!! =========================="
301617
		echo "   Macports installation is outdated. Force rebuild..."
301617
		echo "=========================== !!! =========================="
301617
		sleep 10
d43f8b
		rm -rf "$MACPORTS"
d43f8b
		mkmacports
301617
	fi
301617
301617
	echo $BUILDROOT_VERSION > "$MACPORTS/etc/buildroot-id"
301617
	if [[ `cat "$MACPORTS/etc/buildroot-id"` != "${BUILDROOT_VERSION}" ]]; then
301617
		echo "======================= !!! ======================"
301617
		echo "   Buildroot version changed. Force rebuild..."
301617
		echo "======================= !!! ======================"
301617
		sleep 10
d43f8b
		rm -rf "$MACPORTS"
d43f8b
		mkmacports
301617
	fi
BobSynfig c01942
91a599
	# Don't write into /Applications/MacPorts
91a599
	[ -d $MACPORTS/tmp/app ] || mkdir -p $MACPORTS/tmp/app
91a599
	sed -i "" -e "s|/Applications/MacPorts|$MACPORTS/tmp/app|g" "$MACPORTS/etc/macports/macports.conf" || true
BobSynfig c01942
4120fe
	if [[ ! $UNIVERSAL == 0 ]]; then
bc65a7
		if [[ $X11 == 1 ]]; then
3cd156
			echo "+universal +x11 +nonfree" > $MACPORTS/etc/macports/variants.conf
3cd156
		else
3cd156
			echo "+universal +no_x11 +quartz -x11 +nonfree" > $MACPORTS/etc/macports/variants.conf
3cd156
		fi
822cb2
	else
bc65a7
		if [[ $X11 == 1 ]]; then
3cd156
			echo "+x11 +nonfree" > $MACPORTS/etc/macports/variants.conf
3cd156
		else
3cd156
			echo "+no_x11 +quartz -x11 +nonfree" > $MACPORTS/etc/macports/variants.conf
3cd156
		fi
9001d0
	fi
BobSynfig c01942
6d308d
	pushd ${SCRIPTPATH}/macports
6d308d
	portindex
6d308d
	popd
6d308d
	echo "file://${SCRIPTPATH}/macports [nosync]" > $MACPORTS/etc/macports/sources.conf
6d308d
	echo "rsync://rsync.macports.org/release/tarballs/ports.tar [default]" >> $MACPORTS/etc/macports/sources.conf
BobSynfig c01942
55ae83
	# workaround the bug introduced in MacPorts 2.2.0 - https://trac.macports.org/ticket/39850
55ae83
	cp -rf $MACPORTS/etc/macports/macports.conf $MACPORTS/etc/macports/macports.conf.bak
55ae83
	sed '/sandbox_enable/d' $MACPORTS/etc/macports/macports.conf.bak > $MACPORTS/etc/macports/macports.conf
55ae83
	echo "sandbox_enable no" >> $MACPORTS/etc/macports/macports.conf
301617
301617
	port selfupdate
BobSynfig c01942
c30b1f
	# We have to make sure python 2 is default, because some packages won't build with python 3
c30b1f
	port select --set python python27 || true
BobSynfig c01942
301617
	port upgrade outdated || true
301617
301617
	CORE_DEPS=" \
301617
		fontconfig \
301617
		freetype \
301617
		gettext \
301617
		ImageMagick \
301617
		libmng \
301617
		libpng \
301617
		libsigcxx2 \
301617
		libtool \
301617
		libxmlxx2 \
2d249b
		mlt \
301617
		openexr \
301617
		pkgconfig \
301617
		ffmpeg \
301617
		boost \
301617
		cairo \
BobSynfig c01942
		libtool \
BobSynfig c01942
    libsdl2 \
BobSynfig c01942
    libsdl2_mixer"
301617
	STUDIO_DEPS=" \
c8e905
		gtkmm3 \
301617
		python33 \
0d1e40
		gnome-themes-standard \
301617
		intltool"
6bf19c
	port install -f $CORE_DEPS $STUDIO_DEPS
BobSynfig c01942
c30b1f
	# We have to make sure python 2 is default, because some packages won't build with python 3
c30b1f
	port select --set python python27
3f493a
3f493a
	# ...but we still need python3 binary available
3f493a
	pushd $MACPORTS/bin/ > /dev/null
3f493a
	ln -sf python3.3 python3
3f493a
	popd > /dev/null
BobSynfig c01942
150b3d
	cp ${SCRIPTPATH}/gtk-3.0/settings.ini ${MACPORTS}/etc/gtk-3.0/
34920f
301617
}
301617
301617
mketl()
301617
{
301617
	# building ETL
301617
	pushd ${SYNFIG_REPO_DIR}/ETL
301617
	rm -f aclocal.m4
301617
	autoreconf --install --force
301617
	make clean || true
301617
	./configure --prefix=${SYNFIG_PREFIX}  --includedir=${SYNFIG_PREFIX}/include
a9d02c
	make -j$JOBS install
301617
	popd
301617
}
301617
301617
mksynfig()
301617
{
301617
	# building synfig-core
301617
	pushd ${SYNFIG_REPO_DIR}/synfig-core
3f5336
	export CXXFLAGS="$CXXFLAGS -I${SYNFIG_PREFIX}/include/ImageMagick"
301617
	make clean || true
a47f5d
    	bash ./bootstrap.sh
4120fe
	if [[ ! $UNIVERSAL == 0 ]]; then
822cb2
	export DEPTRACK="--disable-dependency-tracking"
822cb2
	fi
534404
	/bin/sh ./configure ${DEPTRACK} --prefix=${SYNFIG_PREFIX} --includedir=${SYNFIG_PREFIX}/include --disable-static --enable-shared --with-magickpp --without-libavcodec --with-boost=${MACPORTS} ${DEBUG}
d43f8b
	make -j$JOBS install
301617
	popd
301617
}
301617
301617
mksynfigstudio()
301617
{
29cbe4
	# Copy launch script, so we can test synfigstudio without building an app package
5682d9
	[ ! -e "${MACPORTS}/../MacOS" ] || rm -rf "${MACPORTS}/../MacOS"
29cbe4
	cp -rf $SCRIPTPATH/app-template/Contents/MacOS ${MACPORTS}/../MacOS
BobSynfig c01942
301617
	# building synfig-studio
301617
	pushd ${SYNFIG_REPO_DIR}/synfig-studio
301617
301617
	make clean || true
301617
	CONFIGURE_PACKAGE_OPTIONS='--disable-update-mimedb'
301617
	/bin/sh ./bootstrap.sh
4120fe
	if [[ ! $UNIVERSAL == 0 ]]; then
822cb2
	export DEPTRACK="--disable-dependency-tracking"
822cb2
	fi
822cb2
	/bin/sh ./configure ${DEPTRACK}  --prefix=${SYNFIG_PREFIX} --includedir=${SYNFIG_PREFIX}/include --disable-static --enable-shared $DEBUG $CONFIGURE_PACKAGE_OPTIONS
d43f8b
	make -j$JOBS install
301617
10aa10
	for n in AUTHORS COPYING NEWS README
10aa10
	do
10aa10
	  	cp -f $n ${MACPORTS}
10aa10
	done
BobSynfig c01942
301617
	popd
301617
}
301617
301617
mkapp()
301617
{
301617
	VERSION=`get_version_release_string`
301617
	echo Now trying to build your new SynfigStudio app ...
BobSynfig c01942
301617
	DIR=`dirname "$BUILDDIR"`
47e223
	APPDIR="$DIR/SynfigStudio-new-app"
47e223
	APPCONTENTS="$APPDIR/Contents/Resources"
BobSynfig c01942
301617
	# initial cleanup
301617
	[ ! -e $DIR/SynfigStudio-new-app ] || rm -rf $DIR/SynfigStudio-new-app
301617
	[ ! -e $DIR/SynfigStudio.app ] || rm -rf $DIR/SynfigStudio.app
301617
47e223
	cp -R "$SCRIPTPATH/app-template" "$APPDIR"
47e223
	mv $APPDIR/Contents/MacOS/synfigstudio $APPDIR/Contents/MacOS/SynfigStudio || true
301617
47e223
	#mkdir -p "$APPCONTENTS/bin"
47e223
	#cp -R "$MACPORTS/bin/ffmpeg" "$APPCONTENTS/bin"
47e223
	#"$SCRIPTPATH/macos-gather-deps.sh" 	"$APPCONTENTS/bin/ffmpeg"
47e223
	#exit 0
BobSynfig c01942
47e223
	#cp -R "$MACPORTS/synfig/bin/synfig" "$APPCONTENTS/bin"
47e223
	mkdir -p "$APPCONTENTS/etc"
47e223
	mkdir -p "$APPCONTENTS/share"
BobSynfig c01942
47e223
	# Synfig
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/synfig/bin/synfig" "$MACPORTS" "$APPCONTENTS"
BobSynfig c01942
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/synfig/bin/synfigstudio" "$MACPORTS" "$APPCONTENTS"
47e223
	pushd "$MACPORTS/synfig/lib/synfig/modules/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/synfig/lib/synfig/modules/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	cp -R $MACPORTS/synfig/lib/synfig/modules/*.la  "$APPCONTENTS/synfig/lib/synfig/modules/"
47e223
	popd
47e223
	cp -R "$MACPORTS/synfig/etc" "$APPCONTENTS/synfig/"
47e223
	cp -R "$MACPORTS/synfig/share" "$APPCONTENTS/synfig/"
BobSynfig c01942
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/ffmpeg" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/ffprobe" "$MACPORTS" "$APPCONTENTS"
BobSynfig c01942
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/encodedv" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/sox" "$MACPORTS" "$APPCONTENTS"
BobSynfig c01942
47e223
	# Gtk3
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/gdk-pixbuf-query-loaders" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/gdk-pixbuf-pixdata" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/gtk3-demo" "$MACPORTS" "$APPCONTENTS"
47e223
	pushd "$MACPORTS/lib/gdk-pixbuf-2.0/2.10.0/loaders/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/gdk-pixbuf-2.0/2.10.0/loaders/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	popd
47e223
	pushd "$MACPORTS/lib/gtk-3.0/3.0.0/immodules/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/gtk-3.0/3.0.0/immodules/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	popd
47e223
	pushd "$MACPORTS/lib/gtk-3.0/3.0.0/printbackends/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/gtk-3.0/3.0.0/printbackends/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	popd
47e223
	pushd "$MACPORTS/lib/cairo/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/cairo/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	cp -R $MACPORTS/lib/cairo/*.la  "$APPCONTENTS/lib/cairo/"
47e223
	popd
47e223
	#pushd "$MACPORTS/lib/engines/"
47e223
	#for FILE in `ls -1 *.so`; do
47e223
	#	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/engines/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	#done
47e223
	#popd
47e223
	cp -R "$MACPORTS/etc/gtk-3.0"  "$APPCONTENTS/etc/"
47e223
	cp -R "$MACPORTS/lib/girepository-1.0"  "$APPCONTENTS/lib/"
47e223
	mkdir -p "$APPCONTENTS/share/glib-2.0/"
47e223
	cp -R "$MACPORTS/share/glib-2.0/schemas"  "$APPCONTENTS/share/glib-2.0"
BobSynfig c01942
47e223
	# Python 3
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/python3" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/Library/Frameworks/Python.framework/Versions/3.3/Resources/Python.app/Contents/MacOS/Python" "$MACPORTS" "$APPCONTENTS"
47e223
	mkdir -p "$APPCONTENTS/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/"
47e223
	rsync -av --exclude "__pycache__" "$MACPORTS/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/" "$APPCONTENTS/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/"
47e223
	#cp -R "$MACPORTS/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3" "$APPCONTENTS/Library/Frameworks/Python.framework/Versions/3.3/lib/"
47e223
	#find $APPCONTENTS/Library/Frameworks/Python.framework/Versions/3.3/lib -name "__pycache__" -exec rm -rf {} \;
BobSynfig c01942
47e223
	# MLT
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/melt" "$MACPORTS" "$APPCONTENTS"
47e223
	pushd "$MACPORTS/lib/mlt/"
47e223
	for FILE in `ls -1 *.dylib`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/mlt/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	popd
47e223
	cp -R "$MACPORTS/share/mlt"  "$APPCONTENTS/share/"
BobSynfig c01942
47e223
	# ImageMagick
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/animate" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/composite" "$MACPORTS" "$APPCONTENTS"
47e223
	"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/bin/convert" "$MACPORTS" "$APPCONTENTS"
47e223
	pushd "$MACPORTS/lib/ImageMagick-6.9.2/modules-Q16/coders/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/ImageMagick-6.9.2/modules-Q16/coders/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	cp -R $MACPORTS/lib/ImageMagick-6.9.2/modules-Q16/coders/*.la  "$APPCONTENTS/lib/ImageMagick-6.9.2/modules-Q16/coders/"
47e223
	popd
47e223
	pushd "$MACPORTS/lib/ImageMagick-6.9.2/modules-Q16/filters/"
47e223
	for FILE in `ls -1 *.so`; do
47e223
		"$SCRIPTPATH/osx-relocate-binary.sh" "$MACPORTS/lib/ImageMagick-6.9.2/modules-Q16/filters/$FILE" "$MACPORTS" "$APPCONTENTS"
47e223
	done
47e223
	cp -R $MACPORTS/lib/ImageMagick-6.9.2/modules-Q16/filters/*.la  "$APPCONTENTS/lib/ImageMagick-6.9.2/modules-Q16/filters/"
47e223
	popd
47e223
	cp -R "$MACPORTS/lib/ImageMagick-6.9.2/config-Q16"  "$APPCONTENTS/lib/ImageMagick-6.9.2/"
47e223
	cp -R "$MACPORTS/etc/ImageMagick-6"  "$APPCONTENTS/etc/"
BobSynfig c01942
47e223
	cp -R "$MACPORTS/share/icons"  "$APPCONTENTS/share/"
47e223
	cp -R "$MACPORTS/share/themes"  "$APPCONTENTS/share/"
47e223
	cp -R "$MACPORTS/share/mime"  "$APPCONTENTS/share/"
BobSynfig c01942
301617
	# app bundle files
47e223
	echo "*** Please do _NOT_ delete this file. The file script depends on it. ***" > "$APPCONTENTS/v$VERSION"
BobSynfig c01942
	sed -i "" -e "s/_VERSION_/$VERSION/g" "$APPDIR/Contents/MacOS/SynfigStudio"
BobSynfig c01942
	sed -i "" -e "s/_VERSION_/$VERSION/g" "$APPDIR/Contents/Info.plist"
301617
301617
	# save information about the ports which make up this build
47e223
	echo "Synfig Studio $VERSION for Mac OS X $OSNAME" > "$APPCONTENTS/build-info.txt"
47e223
	date >> "$APPCONTENTS/build-info.txt"
47e223
	port installed >> "$APPCONTENTS/build-info.txt"
47e223
	sed -i "" -e "s/are currently installed:/were used to build this package:/g" "$APPCONTENTS/build-info.txt"
301617
47e223
	mv "$APPDIR" "$DIR/SynfigStudio.app"
301617
301617
	echo
301617
	echo "Your new Synfig Studio app bundle should now be ready to run."
301617
	echo
301617
}
301617
301617
mkdmg()
301617
{
6aeeb3
	cd ~
BobSynfig c01942
301617
	# get OS major version
301617
	OSXVER=`uname -r | cut -f 1 -d '.'`
301617
301617
	#VERSION=`synfig --version 2>&1 | cut -d " " -f 2`
301617
	VERSION=`get_version_release_string`
301617
	#echo Synfig version is: $VERSION
301617
2eb8f5
	ARCH=`uname -m`
4120fe
	if [[ ! $UNIVERSAL == 0 ]]; then
8ca6c1
	export FINAL_FILENAME=SynfigStudio-"$VERSION"
822cb2
	else
8ca6c1
	export FINAL_FILENAME=SynfigStudio-"$VERSION"."$ARCH"
822cb2
	fi
BobSynfig c01942
301617
301617
	VOLNAME="SynfigStudio"
33fd37
	TRANSITORY_FILENAME="synfig-wla.sparseimage"
BobSynfig c01942
079036
	APPDIR=`dirname "$BUILDDIR"`/SynfigStudio.app
BobSynfig c01942
079036
	/usr/bin/hdiutil detach /Volumes/"$VOLNAME" || true
301617
301617
	echo "Creating and attaching disk image..."
6b83a9
	[ ! -e "$TRANSITORY_FILENAME" ] || rm -rf "$TRANSITORY_FILENAME"
47e223
	/usr/bin/hdiutil create -type SPARSE -size 700m -fs "HFS+" -volname "$VOLNAME" -attach "$TRANSITORY_FILENAME"
301617
301617
	echo "Copying files to disk image..."
079036
	cp -R $APPDIR /Volumes/"$VOLNAME"/SynfigStudio.app
0aa989
	cp -R ${SYNFIG_REPO_DIR}/synfig-studio/COPYING /Volumes/"$VOLNAME"/LICENSE.txt
1f74cc
	mv /Volumes/"$VOLNAME"/SynfigStudio.app/Contents/MacOS/synfigstudio /Volumes/"$VOLNAME"/SynfigStudio.app/Contents/MacOS/SynfigStudio || true
301617
301617
	# open the window so that the icon database is generated
a31a06
	open /Volumes/"$VOLNAME" || true
301617
	sleep 3
301617
301617
	echo "Detaching disk image..."
301617
	/usr/bin/hdiutil detach /Volumes/"$VOLNAME"
301617
301617
	echo "Compressing disk image..."
6b83a9
	[ ! -e "$FINAL_FILENAME" ] || rm -rf "$FINAL_FILENAME"
5ac3c9
	/usr/bin/hdiutil convert -imagekey zlib-level=9 -format UDBZ "$TRANSITORY_FILENAME" -o ./"$FINAL_FILENAME"
301617
301617
	echo "Removing uncompressed transitory dmg..."
5ac3c9
	/bin/rm -f "$TRANSITORY_FILENAME"
301617
301617
	echo "Done!"
301617
}
301617
301617
get_version_release_string()
301617
{
fe9bcd
	pushd "$SYNFIG_REPO_DIR" > /dev/null
301617
	VERSION=`cat synfig-core/configure.ac |egrep "AC_INIT\(\[Synfig Core\],"| sed "s|.*Core\],\[||" | sed "s|\],\[.*||"`
822cb2
	#if [ -z $BREED ]; then
822cb2
	#	BREED="`git branch -a --no-color --contains HEAD | sed -e s/\*\ // | sed -e s/\(no\ branch\)// | tr '\n' ' ' | tr -s ' ' | sed s/^' '//`"
822cb2
	#	if ( echo $BREED | egrep origin/master > /dev/null ); then
822cb2
	#		#give a priority to master branch
822cb2
	#		BREED='master'
822cb2
	#	else
822cb2
	#		BREED=`echo $BREED | cut -d ' ' -f 1`
822cb2
	#		BREED=${BREED##*/}
822cb2
	#	fi
822cb2
	#	BREED=${BREED%_master}
822cb2
	#fi
301617
	if [[ ${VERSION##*-RC} != ${VERSION} ]]; then
c730ee
		#if [[ $BREED == 'master' ]]; then
301617
			BREED=rc${VERSION##*-RC}
c730ee
		#else
c730ee
		#	BREED=rc${VERSION##*-RC}.$BREED
c730ee
		#fi
301617
		VERSION=${VERSION%%-*}
301617
	fi
BobSynfig c01942
	if [ ! -z $BREED ]; then
9001d0
		BREED=`echo $BREED | tr _ . | tr - .`	# No "-" or "_" characters, becuse RPM and DEB complain
9001d0
		BREED=.$BREED
9001d0
	fi
301617
	REVISION=`git show --pretty=format:%ci HEAD |  head -c 10 | tr -d '-'`
d9eed6
	echo "$VERSION-$REVISION$BREED"
d9eed6
	#echo "$VERSION-$REVISION$BREED.$RELEASE"
fe9bcd
	popd >/dev/null
301617
}
301617
301617
mkall()
301617
{
301617
	mkdeps
301617
301617
	# cleanup previous synfig installation if any
d43f8b
	[ ! -d "$SYNFIG_PREFIX" ] || rm -rf "$SYNFIG_PREFIX"
301617
301617
	mketl
301617
	mksynfig
301617
	mksynfigstudio
301617
301617
	#port install synfigstudio || true
301617
301617
	#synfig -q installer_logo.sif -o installer_logo.png --time 0
301617
	#synfig(294) [23:51:01] info: Loading modules from /tmp/skl/#SynfigStudio.app/Contents/Resources/etc/synfig_modules.cfg
301617
	#synfig: warning: Unable to find module "mod_magickpp" (file not found)
301617
	#synfig: warning: Unable to find module "mod_libavcodec" (file not found)
301617
	#synfig(294) [23:51:01] error: Standard Exception: basic_string::_S_construct NULL not valid
301617
	#Unable to load 'installer_logo.sif'.
301617
	#Throwing out job...
301617
	#Nothing to do!
301617
301617
	#Workaround:
301617
	#[ ! -e ~/src/macports/synfig-build ] || rm -rf ~/src/macports/synfig-build
7a8797
	#cd $MACPORTS/var/macports/build/
301617
	#DIRPATH=`ls`
301617
	#cd -
301617
	#VERSION=`synfig --version 2>&1 | cut -d " " -f 2`
7a8797
	#cp -R "$MACPORTS/var/macports/build/$DIRPATH/synfigstudio/work/synfigstudio-$VERSION" ~/src/macports/synfig-build
301617
	#cd ~/src/macports/synfig-build/images
301617
	#make
301617
	#cd -
7a8797
	#cp -R ~/src/macports/synfig-build/images/* #"$MACPORTS/var/macports/build/$DIRPATH/synfigstudio/work/synfigstudio-$VERSION/images"
301617
	#Workaround end
301617
301617
	#port install synfigstudio
301617
301617
	mkapp
301617
	mkdmg
301617
301617
}
301617
301617
do_cleanup()
301617
{
301617
	#restore Applications/MacPorts dir
656c5c
	if [ -e $MACPORTS/tmp/app.bak ]; then
656c5c
		echo "Restoring custom /Applications/MacPorts dir."
656c5c
		rm -rf $MACPORTS/tmp/app || true
656c5c
		mv $MACPORTS/tmp/app.bak $MACPORTS/tmp/app
301617
	fi
7a8797
	rm -rf $LNKDIR || true
301617
}
301617
301617
###=================================== MAIN ======================================
301617
301617
main()  # dummy for navigation
BobSynfig c01942
{
301617
	true
301617
}
301617
301617
#Init traps
301617
trap do_cleanup INT
301617
a9d02c
# number of jobs
a9d02c
export JOBS=`sysctl hw.ncpu | cut -f 2 -d " "`
a9d02c
echo "Detected processors count: $JOBS"
a9d02c
301617
# get OS X version. 8=Tiger, 9=Leopard, 10=Snowleopard
301617
export OS=`uname -r | cut -d "." -f1`
301617
if [ $OS -eq 9 -o $OS -eq 10 ]; then
301617
	GTKFONT=9.8
301617
	THEME=Leopard
301617
else
301617
	GTKFONT=12.5
301617
	THEME=Tiger
301617
fi
301617
301617
# set OS code name
301617
OSNAME=$THEME
301617
if [ $OS -eq 10 ]; then
301617
	OSNAME=Snowleopard
301617
fi
301617
0800ae
if [ ! $OS -eq 13 ]; then # if not Mountain Lion then set compatibility mode
241320
export MACOSX_DEPLOYMENT_TARGET=10.5
241320
echo "Enabling binary compatibility mode: MACOSX_DEPLOYMENT_TARGET=10.5"
0800ae
fi
312ed0
301617
prepare
301617
fe9bcd
# Fetch sources
fe9bcd
#port install python33
fe9bcd
#port select --set python python33
fe9bcd
#port install git-core
fe9bcd
if ! ( which git ); then
fe9bcd
	echo "ERROR: No git found. Please install git from http://code.google.com/p/git-osx-installer/"
fe9bcd
	exit 1
fe9bcd
fi
fe9bcd
fe9bcd
#detecting repo
fe9bcd
pushd $SCRIPTPATH >/dev/null
fe9bcd
if git rev-parse --git-dir >/dev/null; then
fe9bcd
	SYNFIG_REPO_DIR=$(dirname `git rev-parse --git-dir`)
fe9bcd
	SCRIPTDIR_IS_REPO=1
fe9bcd
fi
fe9bcd
popd >/dev/null
fe9bcd
fe9bcd
if [ ! -e ${SYNFIG_REPO_DIR} ]; then
fe9bcd
	pushd `dirname "${SYNFIG_REPO_DIR}"`
fe9bcd
	git clone git://github.com/synfig/synfig.git
fe9bcd
	popd
fe9bcd
fi
fe9bcd
fe9bcd
VERSION=`get_version_release_string`
fe9bcd
fe9bcd
pushd ${SYNFIG_REPO_DIR} >/dev/null
Androbin 39dbab
if [[ $WORKDIR_IS_REPO == 0 ]]; then
fe9bcd
	git fetch
fe9bcd
	git reset --hard HEAD
fe9bcd
	SELECTEDREVISION=origin/master
fe9bcd
	git checkout $SELECTEDREVISION
fe9bcd
fi
fe9bcd
fe9bcd
fe9bcd
echo
fe9bcd
echo
fe9bcd
echo "BUILDING synfigstudio-$VERSION"
fe9bcd
echo
fe9bcd
echo
47e223
#sleep 5
fe9bcd
fe9bcd
popd > /dev/null
fe9bcd
301617
if [ -z $1 ]; then
301617
	mkall
301617
else
301617
	echo "Executing custom user command..."
301617
	$@
301617
fi
301617
301617
do_cleanup