#!/usr/bin/perl

if(@ARGV==0){
  print "\n Usage:  compile <perl_source.pl> <compilation options>\n";
  print "\n  e.g.  for Linux binary:  compile foo.pl -m486 \n\n";
  print chr(7); exit;

}

$perl_source=shift(@ARGV);

@compile_options=(@ARGV);
$base=${&get_base_names(\$perl_source)};

#  perl -MO=C,-ofoo.c foo.pl

$c_source="$base\.c";
system("perl -MO=C,-o$c_source  $perl_source");

#  perl cc_harness -O2 -o foo foo.c

system(" perl cc_harness @compile_options -o $base $c_source");




#________________________________________________________________________
# Title     : get_base_names
# Usage     : $base =${&get_base_names(\$file_name)};
#             :   or @bases = &get_base_names(\@files);  # <-- uses `pwd` for abs directory
# Function  : produces the file base name(eg, "evalign"  out of "evalign.pl" ).
# Example   : $base => 'test'  with 'test.txt' or '/home/dir/of/mine/text.txt'
# Warning   :
# Class     :
# Keywords  : get_base_name{, base_name, file_base_name ,  get_file_base_name
#             get_basename, basename
# Options   :
# Package   : Jong_Util
# Reference :
# Returns   :
# Tips      :
# Argument  : handles both ref and non-ref.
# Todo      :
# Author    : A Biomatic
# Version   : 1.1
# Used in   :
# Enclosed  :
#--------------------------------------------------------------------
sub get_base_names{
	my($x, @out_file, $file, @file, $base, @base);
	@file=@{$_[0]} if (ref($_[0]) eq 'ARRAY');
	@file=@_ if !(ref($_[0]) eq 'ARRAY');
	for($x=0; $x < @file; $x ++){
		if( ref($file[$x]) ){
			$file = ${$file[$x]};
			@out_file=split(/\./, $file);
			$base = $out_file[0];
		}else{
			$file = $file[$x];
			@out_file=split(/\./, $file);
			$base = $out_file[0];
		}
		push(@base, $base);
	}
	if(@base == 1 ){ \$base[0] }else{ @base }
}


