#!/bin/sh
##
# VampirTrace
# http://www.tu-dresden.de/zih/vampirtrace
#
# Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
#
# Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
#                          Centre, Federal Republic of Germany
#
# See the file COPYING in the package base directory for details
##

# setup paths to VampirTrace installation
#
if test x"$VT_PREFIX" != x; then
  prefix=$VT_PREFIX
else
  prefix=/home/lius/intel-test/openmpi
fi
exec_prefix=${prefix}
libdir=${exec_prefix}/lib

agentpath=$libdir/

# parse command line options
#

java_args=
file_prefix=
show_helptext=0
show_version=0

while test $# -ne 0; do
  case $1 in
    -vt:help)
      show_helptext=1
      shift
      ;;
    -vt:version)
      show_version=1
      shift
      ;;
    -jar)
      java_args="$java_args $1"
      shift
      if test x"$file_prefix" = x -a x"$1" != x; then
        file_prefix=`echo $1 | sed -e "s/[.]jar\$//"`
        java_args="$java_args $1"
        shift
      fi
      ;;
    *.class)
      java_args="$java_args $1"
      if test x"$file_prefix" = x; then
        file_prefix=`echo $1 | sed -e "s/[.]class\$//"`
      fi
      shift
      ;;
    *)
      java_args="$java_args $1"
      shift
      ;;
  esac
done

# show help text, if desired
#
if test $show_helptext -eq 1; then
  echo ""
  echo " vtjava - Java application launcher wrapper for VampirTrace."
  echo ""
  echo " Syntax: vtjava [options] [java-options] <class|-jar jarfile> [arguments]"
  echo ""
  echo "   options:"
  echo "     -vt:help            Show this help message."
  echo ""
  echo "     -vt:version         Show VampirTrace version."
  echo ""
  exit 0;
fi

# show VampirTrace version, if desired
#
if test $show_version -eq 1; then
  echo "5.13.1openmpi"
  exit 0;
fi

# set VT_FILE_PREFIX env. variable to jar/class file name
#
if test x"$VT_FILE_PREFIX" = x -a x"$file_prefix" != x; then
  export VT_FILE_PREFIX=$file_prefix
fi

# run Java application launcher
#
java -agentpath:"$agentpath" $java_args
java_rc=$?

if test $java_rc -ne 0; then
  echo ""
  echo "The Java application launcher terminated abnormally (exit code $java_rc)."
  echo "If the agent library could not be found, one possible reason might be that the agent library has unresolved dependencies."
  echo "Please check that LD_LIBRARY_PATH environment variable includes $libdir."
fi

exit $java_rc

