#!/bin/bash -i
#
# Set up environment to use and develop with Pigment uninstalled.
#
# The script is registering several environment variables to run
# Pigment uninstalled. It also registers PYTHONPATH for Pigment
# Python, this one should be put in the parent directory of Pigment.
# It is how the packages are stored in the Subversion repository.
#
# Author(s): Thomas Vander Stichele <thomas at apestaart dot org>
#            Loïc Molinari <loic at fluendo dot com>

PROJECT='pigment'

# Find the script directory handling symlinks
self=$0
absolute=$self
if test -L $absolute
then
  absolute=`stat $absolute -c %N -t | sed 's/^.* -> .//g' | sed 's/.$//g'`
fi
MISCDIR=`dirname $absolute`
BASEDIR=`cd $MISCDIR/.. && pwd`

# Set up the paths needed to run uninstalled

# UNIX library path env var
LD_LIBRARY_PATH=$BASEDIR/../prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
LD_LIBRARY_PATH=$BASEDIR/pgm/.libs${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

# Mac OS library path env var
DYLD_LIBRARY_PATH=$BASEDIR/../prefix/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
DYLD_LIBRARY_PATH=$BASEDIR/pgm/.libs${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH

# Common env vars
export PGM_PLUGIN_PATH=$BASEDIR/plugins
export PKG_CONFIG_PATH=$BASEDIR/../prefix/lib/pkgconfig:$BASEDIR/pkgconfig:$PKG_CONFIG_PATH
export PYTHONPATH=$BASEDIR/../pigment-python:$BASEDIR/../pigment-python/pgm/.libs:$PYTHONPATH

# If we got a command, run it and exit
if test ! -z "$1";
then
  $@
  exit $?
fi

# Set up a prompt helping us remember we're in a subshell
tmp=`mktemp -t bashrc.XXXXXXXX`
echo source $HOME/.bashrc >> $tmp
echo PS1=\'[$PROJECT] $PS1\' >> $tmp
SHELL_OPTIONS="--init-file $tmp"

# Start the shell
echo Entering interactive $PROJECT shell $SHELL.
$SHELL $SHELL_OPTIONS

# Remove temporary file
if test ! -z "$tmp"
then
  rm $tmp
fi

echo Thank you for using $PROJECT.
