#!/usr/bin/perl
#
# (C) Copyright IBM Corp. 2001
#
# $Id: jcreate,v 1.2 2002/02/05 14:57:29 pfs-oss Exp $
#
# Generate control files necessary to build a particular "configuration"
# of the Research Virtual Machine and invoke the builder.
#
# Invocation:  jcreate [-help] [-clean] [-trace] [-recompile] [-nolink] [-nobooter] [-booter] configuration-name
#
#   -help: a usage message is printed
#   -clean: the build directory is recursively deleted and repopulated with jconfigure
#   all other options: passed on to jbuild
#
# @author Perry Cheng
# @date   12 Nov 2001
#

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

sub doUsage() {
  print "Usage: $me [-help] [-clean] [-trace] [-recompile] [-nolink] [-nobooter] [-booter] configuration-name\n";
  exit 1;
}

# Get arguments
while (($cur = shift @ARGV) ne "") {
  if ($cur eq "-help") { doUsage(); }
  if ($cur eq "-clean") { $clean = 1; next; }
  if (!($cur =~ /-/)) { 
    if ($config eq "") { $config = $cur; next; }
    doUsage();
  }
  push @ARGV_COPY, $cur;
}
@ARGV = @ARGV_COPY;


# Place where source files reside.
#
if ($ENV{RVM_ROOT} eq "") {
   print "$ME: please set your RVM_ROOT environment variable (eg. $HOME/rvmRoot)\n";
   exit 1;
}

# Place where RVM bootimage, booter, and runtime support files will be placed.
#
if ($ENV{RVM_IMAGES} eq "") {
   print "$ME: please set your RVM_IMAGES environment variable if using 'jcreate'\n";
   exit 1;
}

# Set up RVM_BUILD for inferior processes to use
#
$ENV{RVM_BUILD} = "$ENV{RVM_IMAGES}/$config";

# Remove old build directory for complete rebuild.
#
if ($clean) { system "rm -rf $ENV{RVM_BUILD}"; }
if (!(-e $ENV{RVM_BUILD})) {system "jconfigure -quiet $config"; }
chdir $ENV{RVM_BUILD};
system "./jbuild", @ARGV;
