#!/usr/bin/perl
use warnings;
use strict;
use FindBin qw($RealBin);

# Check to see if they've mistakenly downloaded the source distribution
# since several people have made this mistake

if (-e "$RealBin/uk/ac/bbsrc/babraham/FastQC/FastQCApplication.java") {
	die "This is the source distribution of FastQC.  You need to get the compiled version if you want to run the program\n";
}


if ($ENV{CLASSPATH}) {
	$ENV{CLASSPATH} .= ":$RealBin:$RealBin/sam-1.32.jar";
}
else {
	$ENV{CLASSPATH} = "$RealBin:$RealBin/sam-1.32.jar";
}

my @java_args = '-Xmx250m';
my @files;

foreach (@ARGV) {
  if (/^\-/) {
    push @java_args,$_;
  }
  else {
    push @files,$_;
  }
}

# This is set internally as well, but on some JREs it doesn't
# pick up the internally set value properly, so we'll set it
# outside as well which should work.
if (@files) {
	push @java_args, "-Djava.awt.headless=true";
}


exec "java",@java_args, "uk.ac.bbsrc.babraham.FastQC.FastQCApplication", @files;
