#!/bin/sh
#
# Copyright (c) 2004, Hewlett-Packard.
# Contributed by Al Stone <ahs3@debian.org>
#
# This file is part of pfmon, a sample tool to measure performance 
# of applications on Linux/ia64.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
#

#-- determine which kernel we're running, then execute the proper
#   version of pfmon

KVERS=`uname -r | cut -d- -f1`
KMAJOR=`echo $KVERS | cut -d. -f1`
KMINOR=`echo $KVERS | cut -d. -f2`

#-- set a default, just in case
PFMON=pfmon3

#-- see what pfmon to really use
if test $KMAJOR -lt 2; then
   echo "pfmon: kernel version \"$KVERS\" is unsupported (pre-2.x)"
   exit 1
else
   if test $KMINOR -lt 4; then
      echo "pfmon: kernel version \"$KVERS\" is unsupported (pre-2.4.x)"
      exit 1
   else
      if test $KMINOR -lt 5; then
         PFMON=pfmon2
      else
         PFMON=pfmon3
      fi
   fi
fi

#-- make sure the argument list gets passed on properly
#   by surrounding any arg containing blanks with ""
ARGS=""
while test $# -gt 0
do
   CNT=`echo $1 | wc -w`
   if test $CNT -gt 1; then
      ARGS="$ARGS \"$1\""
   else
      ARGS="$ARGS $1"
   fi
   shift
done

exec $PFMON $ARGS

exit 0
