#!/bin/sh
# .gps_wrapper
#
# Copyright 2002-2010 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
GPS_STARTUP_PATH=$PATH
export GPS_STARTUP_LD_LIBRARY_PATH GPS_STARTUP_PATH

LD_LIBRARY_PATH=$root/lib/gps:$root/lib:$LD_LIBRARY_PATH
GTK_DATA_PREFIX=$root
GTK_EXE_PREFIX=$root

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 /etc/fonts/fonts.conf ]; then
  if grep '<cachedir>' /etc/fonts/fonts.conf > /dev/null 2>&1; then
    FONTCONFIG_FILE=/etc/fonts/fonts.conf
    export FONTCONFIG_FILE
    FONTCONFIG_PATH=/etc/fonts
    export FONTCONFIG_PATH
  fi
fi

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

if [ -f $root/etc/gtk-2.0/gdk-pixbuf.loaders ]; then
  GDK_PIXBUF_MODULE_FILE=$root/etc/gtk-2.0/gdk-pixbuf.loaders
  export GDK_PIXBUF_MODULE_FILE
fi

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

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