#!/bin/bash
builddir=`dirname "$0"`
GCONV_PATH="${builddir}/iconvdata"

usage () {
  echo "usage: $0 [--tool=strace] PROGRAM [ARGUMENTS...]" 2>&1
  echo "       $0 --tool=valgrind PROGRAM [ARGUMENTS...]" 2>&1
  exit 1
}

toolname=default
while test $# -gt 0 ; do
  case "$1" in
    --tool=*)
      toolname="${1:7}"
      shift
      ;;
    --*)
      usage
      ;;
    *)
      break
      ;;
  esac
done

if test $# -eq 0 ; then
  usage
fi

case "$toolname" in
  default)
    exec   env GCONV_PATH="${builddir}"/iconvdata LOCPATH="${builddir}"/localedata LC_ALL=C  "${builddir}"/elf/ld-linux-x86-64.so.2 --library-path "${builddir}":"${builddir}"/math:"${builddir}"/elf:"${builddir}"/dlfcn:"${builddir}"/nss:"${builddir}"/nis:"${builddir}"/rt:"${builddir}"/resolv:"${builddir}"/mathvec:"${builddir}"/support:"${builddir}"/crypt:"${builddir}"/nptl ${1+"$@"}
    ;;
  strace)
    exec strace  -EGCONV_PATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/iconvdata  -ELOCPATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/localedata  -ELC_ALL=C  /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf/ld-linux-x86-64.so.2 --library-path /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/math:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/dlfcn:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nss:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nis:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/rt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/resolv:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/mathvec:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/support:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/crypt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nptl ${1+"$@"}
    ;;
  valgrind)
    exec env GCONV_PATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/iconvdata LOCPATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/localedata LC_ALL=C valgrind  /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf/ld-linux-x86-64.so.2 --library-path /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/math:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/dlfcn:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nss:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nis:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/rt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/resolv:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/mathvec:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/support:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/crypt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nptl ${1+"$@"}
    ;;
  container)
    exec env GCONV_PATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/iconvdata LOCPATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/localedata LC_ALL=C  /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf/ld-linux-x86-64.so.2 --library-path /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/math:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/dlfcn:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nss:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nis:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/rt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/resolv:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/mathvec:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/support:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/crypt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nptl /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/support/test-container env GCONV_PATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/iconvdata LOCPATH=/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/localedata LC_ALL=C  /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf/ld-linux-x86-64.so.2 --library-path /var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/math:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/elf:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/dlfcn:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nss:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nis:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/rt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/resolv:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/mathvec:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/support:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/crypt:/var/www/debian/malloc-benchmarks/malloc-benchmarks/glibc-build/nptl ${1+"$@"}
    ;;
  *)
    usage
    ;;
esac
