#! /usr/bin/perl


my ($prefix, $globus_prefix, $exec_prefix, $bindir, $sbindir, $libdir);
my ($datarootdir, $datadir, $perlmoduledir, $gptdatadir);
my ($gptexecsharedir, $amdir, $pkg_confdir, $aclocaldir);

if (exists $ENV{GPT_LOCATION})
{
    $prefix = $ENV{GPT_LOCATION};
}
else
{
    $prefix = "/usr";
}

if (exists $ENV{GLOBUS_LOCATION})
{
    $globus_prefix = $ENV{GLOBUS_LOCATION};
}
else
{
    $globus_prefix = "/usr";
}

$exec_prefix = "${prefix}";
$bindir = "${exec_prefix}/bin";
$sbindir = "${exec_prefix}/sbin";
$libdir = "${exec_prefix}/lib";
$datarootdir = "${prefix}/share";
$datadir = "${prefix}/share";
$perlmoduledir = "/usr/share/perl5";
$gptdatadir = "${datadir}/globus/gpt";
$gptexecsharedir = "${datadir}/globus/gpt";
$amdir = "${datadir}/globus/amdir";
$pkg_confdir = "${datadir}/globus/gpt";
$aclocaldir = "${datadir}/globus/aclocal";

unshift(@INC, "${perlmoduledir}");

use strict;
use Getopt::Long;
use Config;

#
# Do a perl check for version >= 5.005.
#

if ( ! ( defined eval "require 5.005" ) )
{
    die "GPT requires at least Perl version 5.005";
}

if ( ! ( defined eval "require Grid::GPT::GPTObject" ) )
{
    die("$prefix does not appear to hold a valid GPT installation\n");
}

require Pod::Usage;

use Cwd;

my $VERSION = 0.01;
my $srcdir = cwd();
my $flavor = "noflavor";
my $verbose = 0;
my ($help, $man);

# sub pod2usage {
#   my $ex = shift;
#   print "gpt_save_flavor [-verbose -help] -flavor=flavor <build-parameters file>";
#   exit $ex;
# }

GetOptions( 'flavor=s' => \$flavor, 'verbose=i' => \$verbose, 'help' => \$help)
  or Pod::Usage::pod2usage(1);

Pod::Usage::pod2usage(0) if $help;
Pod::Usage::pod2usage(-verbose => 2) if $man;

my $file = shift;

if (!defined $flavor or ! defined $file) {
  Pod::Usage::pod2usage(1);
}

require Grid::GPT::V1::FlavorDefinition;

my $obj = new Grid::GPT::V1::FlavorDefinition(name => $flavor, 
                                        build_parameters => $file);

die "ERROR: vendorcc not supported\n" 
  if $flavor =~ m!vendorcc! and ! defined $obj->{'vendorcc'};

die "ERROR: gcc not supported\n" 
  if $flavor =~ m!gcc! and ! defined $obj->{'gcc'};

$obj->write_xml(filename => "flavor_$flavor.gpt");


__END__
