#!/usr/bin/perl
#
# (C) Copyright IBM Corp. 2001
#
# $Id: jrun,v 1.4 2003/03/28 23:49:34 perry-oss Exp $
#
# Invoke Jikes RVM virtual machine that was created by "jcreate"
#
# @author Perry Cheng
# @date 


# Who we are.
#
$ME=`basename $0`;
$ME=~s/\n//;

# Extract the "-v config" option from arg list
while (($cur = shift @ARGV) ne "") {
  if ($cur eq "-v") { 
    $config = shift @ARGV; 
    if ($config eq "") { 
       print "Usage: $ME -v config <more VM options> class-name args ...\n";
       exit 1;
    }
    next;
  }
  push @ARGV_COPY, $cur;
}
@ARGV = @ARGV_COPY;

# Figure out the directory the image resides in; define $RVM_BUILD if necessary
#
if ($config ne "") {
   if ($ENV{RVM_IMAGES} eq "") {
     print "$ME: please set your RVM_IMAGES environment variable (eg. $RVM_ROOT/rvmImages) when using -v\n";
     exit 1;
   }
   $ENV{RVM_BUILD} = $ENV{RVM_IMAGES} . "/" . $config;
}
else {
   if ($ENV{RVM_BUILD} eq "") {
     print "$ME: please set your RVM_BUILD environment variable (eg. $HOME/rvmBuild) when not using -v\n";
     exit 1;
    }
}

if (!(-e "$ENV{RVM_BUILD}/JikesRVM")) {
  print "$ME: missing image file \"$ENV{RVM_BUILD}/JikesRVM\"\n";
  exit 1;
}

$RVM_ROOT = $ENV{RVM_ROOT};
$rvm = "$RVM_ROOT/rvm/bin/rvm";

exec $rvm, @ARGV;


