#! /bin/sh

# Modified for program "guild" by Tommi Höynälänmaa, 2019.

# Copyright (C) 2004 Free Software Foundation, Inc.
# Public domain.
# Written by Andy Wingo for guile-gnome.

# The purpose of this script is twofold. First, it serves to find
# `guile' in the load path instead of statically "linking" to
# /usr/bin/guile. Second, it will set up the guile load path and the
# library path such that using guile-gnome modules will Just Work. This
# is necessary because we might choose to break the application
# interfaces in the future, so we need to allow for parallel installs.

# Note that the proper way to make a script that will use this as the
# interpreter is as follows, removing `# ' on each line:

# #! /bin/sh
# exec guile-gnome -s $0 "$@"
# !#

# This will allow the shell to find `guile-gnome' in the path.

# Hack around guile-1.6's lack of /usr/local paths in its load-dir.
# (Otherwise a user looking for g-wrap / guile-lib installed in
# /usr/local will be unpleasantly surprised.)
localpath=/usr/local/share/guile/site:/usr/local/share/guile/1.6:/usr/local/share/guile

if test "x$GUILE_LOAD_PATH" = "x"; then
  GUILE_LOAD_PATH="@guilegnomedir@":$localpath
else
  # Because GUILE_LOAD_PATH is essentially a user customization, allow
  # it to have precedence over $localpath.
  GUILE_LOAD_PATH="@guilegnomedir@":$GUILE_LOAD_PATH:$localpath
fi

# Probably will always be necessary to resolve libguile-gnome-gobject
# link.
if test @libdir@ != /usr/lib -a @libdir@ != /usr/local/lib; then
  if test "x$LD_LIBRARY_PATH" = "x"; then
    LD_LIBRARY_PATH=@libdir@
  else
    LD_LIBRARY_PATH=@libdir@:$LD_LIBRARY_PATH
  fi
fi

# Can be removed after g-wrap is fixed.
if test "x$LD_LIBRARY_PATH" = "x"; then
  LD_LIBRARY_PATH=@guilegnomelibdir@
else
  LD_LIBRARY_PATH=@guilegnomelibdir@:$LD_LIBRARY_PATH
fi

export GUILE_LOAD_PATH LD_LIBRARY_PATH

# Taken from autoconf.info, "Portable Shell"
case $# in
0) exec guile-@guile_version@;;
*) exec guile-@guile_version@ "$@";;
esac
