#!/bin/bash --
#
# wrap_ruby (shell script)
# by pts@fazekas.hu at Mon Dec 11 18:30:13 CET 2000
#

# RUBY_SRC=""
try_dirs() {
  [ -n "$RUBY_SRC" ] && return
  for D in "$@"; do
    [ -f "$D" ] && D="${D%/*}"
    if [ -x "$D/ruby" -a -f "$D/rbconfig.rb" \
         -a -f "$D/lib/mkmf.rb" ]; then
      RUBY_SRC="$D"
      break
    fi
  done
}

try_dirs "`type -p ruby 2>/dev/null`" . .. ../.. ../../.. ~/ruby /usr/src/ruby-1.6.1 /usr/local/src/ruby-1.6.1
if [ -z "$RUBY_SRC" ]; then
  echo "$0: Ruby source dir not found. Give it in \$RUBY_SRC"
  exit 2
fi

export WRAP_RUBY="$0"
export RUBY_SRC
if [ -z "$WRAP_RUBYLIB" ]; then
  export WRAP_RUBYLIB=".:./lib:$RUBYLIB:$RUBY_SRC:$RUBY_SRC/lib:$RUBY_SRC/ext"
  eval "`
  find "$RUBY_SRC/ext" -type f -and -name '*.so' | {
    while read LINE; do
      RUBYLIB="$RUBYLIB:${LINE%/*}"
    done
    echo "RUBYLIB='$RUBYLIB'"
  }`"
fi
export RUBYLIB="$WRAP_RUBYLIB"
# echo "$RUBYLIB"
# export RUBYLIB="$RUBYLIB:$WRAP_RUBYLIB"

"$RUBY_SRC/ruby" "$@"
