 #!/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
}

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=/home/kfcs/download/glibc-2.28/build/iconvdata  -ELOCPATH=/home/kfcs/download/glibc-2.28/build/localedata  -ELC_ALL=C  /home/kfcs/download/glibc-2.28/build/elf/ld-linux-x86-64.so.2 --library-path /home/kfcs/download/glibc-2.28/build:/home/kfcs/download/glibc-2.28/build/math:/home/kfcs/download/glibc-2.28/build/elf:/home/kfcs/download/glibc-2.28/build/dlfcn:/home/kfcs/download/glibc-2.28/build/nss:/home/kfcs/download/glibc-2.28/build/nis:/home/kfcs/download/glibc-2.28/build/rt:/home/kfcs/download/glibc-2.28/build/resolv:/home/kfcs/download/glibc-2.28/build/mathvec:/home/kfcs/download/glibc-2.28/build/support:/home/kfcs/download/glibc-2.28/build/crypt:/home/kfcs/download/glibc-2.28/build/nptl ${1+"$@"}
    ;;
  valgrind)
    exec env GCONV_PATH=/home/kfcs/download/glibc-2.28/build/iconvdata LOCPATH=/home/kfcs/download/glibc-2.28/build/localedata LC_ALL=C valgrind  /home/kfcs/download/glibc-2.28/build/elf/ld-linux-x86-64.so.2 --library-path /home/kfcs/download/glibc-2.28/build:/home/kfcs/download/glibc-2.28/build/math:/home/kfcs/download/glibc-2.28/build/elf:/home/kfcs/download/glibc-2.28/build/dlfcn:/home/kfcs/download/glibc-2.28/build/nss:/home/kfcs/download/glibc-2.28/build/nis:/home/kfcs/download/glibc-2.28/build/rt:/home/kfcs/download/glibc-2.28/build/resolv:/home/kfcs/download/glibc-2.28/build/mathvec:/home/kfcs/download/glibc-2.28/build/support:/home/kfcs/download/glibc-2.28/build/crypt:/home/kfcs/download/glibc-2.28/build/nptl ${1+"$@"}
    ;;
  *)
    usage
    ;;
esac
