#!/bin/sh
# Runs Pike directly from the build directory.

if test "BASEDIR" = BASEDIR; then
  echo Run make in the parent directory to generate this script.
  exit 1
fi

OS=${OS:-`uname -srm|sed -e 's/ /-/g'|tr '[A-Z]' '[a-z]'|tr '/' '_'`}
BUILDDIR=${BUILDDIR:-"build/$OS"}

case "$BUILDDIR" in
  /*) :;;
  *) BUILDDIR="BASEDIR"/"$BUILDDIR";;
esac

if test x"$1" = x--gdb; then
  shift
  args="set args '-m$BUILDDIR/master.pike'"
  for arg do
    arg=`echo $arg | sed -e s/\'/\'\"\'\"\'/g`
    args="$args '$arg'"
  done
  if test -f .gdbinit; then
    mv .gdbinit .gdbinit.orig
    cp .gdbinit.orig .gdbinit
  fi
  echo $args >> .gdbinit
  gdb "$BUILDDIR/pike"
  rm .gdbinit
  test -f .gdbinit.orig && mv .gdbinit.orig .gdbinit
else
  exec "$BUILDDIR/pike" "-m$BUILDDIR/master.pike" "$@"
fi
