#!/bin/sh
# .gps_wrapper
#
# Copyright 2002-2013 AdaCore

prog=`basename $0`
root=`dirname $0`

## Run with "gps debug ..." to run under the debugger
debug=${1:-false}
if [ $debug = debug ]; then
   shift;
fi

# Get absolute directory and strip 'bin' directory to retrieve real root
root=`cd $root/..; pwd`

GPS_STARTUP_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
export GPS_STARTUP_LD_LIBRARY_PATH

LD_LIBRARY_PATH=$root/lib/gps:$root/lib:$LD_LIBRARY_PATH
XDG_DATA_DIRS=$root/share
XDG_CONFIG_HOME=$root/etc
GTK_DATA_PREFIX=$root
GTK_EXE_PREFIX=$root
GI_TYPELIB_PATH=$root/lib/girepository-1.0

if [ -d $root/lib/gps ]; then
  unset GTK2_RC_FILES
fi

if [ -f $root/etc/fonts/fonts.conf ]; then
  FONTCONFIG_FILE=$root/etc/fonts/fonts.conf
  export FONTCONFIG_FILE
fi

if [ -f $root/etc/pango/pangorc ]; then
  PANGO_RC_FILE=$root/etc/pango/pangorc
  export PANGO_RC_FILE
fi

pixbuf_base=$root/lib/gps/gdk-pixbuf-2.0/2.10.0/
if [ -f $pixbuf_base/loaders.cache ]; then
  GDK_PIXBUF_MODULE_FILE=$pixbuf_base/loaders.cache
  GDK_PIXBUF_MODULEDIR=$pixbuf_base/loaders
  export GDK_PIXBUF_MODULE_FILE GDK_PIXBUF_MODULEDIR
fi

if [ "$CHARSET" = "" ]; then
  CHARSET=ISO-8859-1
  export CHARSET
fi

export LD_LIBRARY_PATH XDG_DATA_DIRS XDG_CONFIG_HOME GTK_DATA_PREFIX GTK_EXE_PREFIX GI_TYPELIB_PATH

GSETTINGS_BACKEND=memory
export GSETTINGS_BACKEND

if [ $debug = debug ]; then
   gdb -args $root/bin/${prog}_exe "$@"
else
   exec $root/bin/${prog}_exe "$@"
fi
