use fields
qw(ofile args fullsource);
###############################################################################
my $this = fields
::new
($class);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
###############################################################################
###############################################################################
sub get_full_source_file
{
return $this->{fullsource
};
###############################################################################
return basename
$this->get_full_source_file();
###############################################################################
###############################################################################
###############################################################################
###############################################################################
fatal
"Cannot copy_to_build_dir of file generated from diag source\n", M_FILE
if $this->from_diag_source();
my @search = $this->get_search_paths();
my $full_source = $this->get_full_source_file();
my $local_source = path_to_build_file
($this->get_source_file(), $STATE);
foreach my $testdir (@search) {
my $testfile = File
::Spec
->catfile($testdir, $full_source);
chat
"Copying $testfile to $local_source\n";
copy
($testfile, $local_source);
if(not -e
$local_source) {
fatal
"Could not find \"$full_source\" in search path: @search\n", M_FILE
;
###############################################################################
fatal
"Cannot get_search_paths of abstract superclass\n", M_CODE
;
###############################################################################
###############################################################################
fatal
"Cannot build source file in abstract superclass\n", M_CODE
;
###############################################################################
my $str = "O=$this->{ofile} ";
$str .= "ARGS=\"$this->{args}\" " if defined $this->{args
};
###############################################################################
###############################################################################
package Midas
::Source
::Assembly
;
use base
'Midas::Source';
###############################################################################
my $this = fields
::new
($class);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
###############################################################################
$this->SUPER::set_defaults
();
###############################################################################
###############################################################################
###############################################################################
my $str = "ASM: S=$this->{sfile} ";
$str .= $this->SUPER::debug_string
();
###############################################################################
# This function may be called from a child thread, sot it is important
# that it doesn't write any state (i.e., have any side-effects)
my $pushd = Midas
::Paths
->pushd($STATE->get_build_dir);
my $source = $this->get_source_file();
my $cmd = "$CONFIG{as_cmd} ";
$cmd .= "$this->{args} " if defined $this->{args
};
$cmd .= join ' ', @
{$CONFIG{as_opt
}};
$cmd .= " $source -o $this->{ofile}";
run_command
($cmd, -errcode
=> M_ASMFAIL
);
###############################################################################
###############################################################################
package Midas
::Source
::C
;
use Midas
::Preprocess
':all';
use base
'Midas::Source';
use fields
qw(cfile sfile);
###############################################################################
my $this = fields
::new
($class);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
###############################################################################
$this->SUPER::set_defaults
();
###############################################################################
return get_includes
($CONFIG{csrc_includes
});
###############################################################################
if(defined $this->{sfile
}) {
my $cmd = $CONFIG{gcc_cmd
};
my $gccopt = join ' ', @
{$CONFIG{gcc_opt
}};
my @incs = map { "-I$_" } get_includes
($CONFIG{c_includes
});
# Don't use cfile directly, since it may contain path seperator.
my $c_file = $this->get_source_file();
$cmd .= " $gccopt @incs " if defined $gccopt;
$cmd .= " $this->{args} " if defined $this->{args
};
$cmd .= " $c_file -o $this->{sfile}";
chat
"Compiling C code $c_file to generate $this->{sfile}\n";
run_command
($cmd, -errcode
=> M_CCFAIL
);
###############################################################################
# This function may be called from a child thread, sot it is important
# that it doesn't write any state (i.e., have any side-effects)
my $pushd = Midas
::Paths
->pushd($STATE->get_build_dir);
if(defined $this->{sfile
}) {
# Already compiled to assembly - now just assemble
my $args = join ' ', @
{$CONFIG{as_opt
}};
run_command
("$CONFIG{as_cmd} $args $this->{sfile} -o $this->{ofile}",
# Need to compile from .c
my $cfile = $this->get_source_file();
my $cmd = $CONFIG{gcc_cmd
};
my $gccopt = join ' ', @
{$CONFIG{gcc_opt
}};
my @incs = map { "-I$_" } get_includes
($CONFIG{c_includes
});
$cmd .= " $gccopt @incs " if defined $gccopt;
$cmd .= " -c $cfile -o $this->{ofile}";
run_command
($cmd, -errcode
=> M_CCFAIL
);
###############################################################################
my $str = "C: C=$this->{cfile} ";
$str .= "S=$this->{sfile} " if defined $this->{sfile
};
$str .= $this->SUPER::debug_string
();
###############################################################################
###############################################################################
package Midas
::Source
::Object
;
use Midas
::Preprocess
':all';
use base
'Midas::Source';
###############################################################################
my $this = fields
::new
($class);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
###############################################################################
$this->SUPER::set_defaults
();
###############################################################################
###############################################################################
return get_includes
($CONFIG{link_paths
});
###############################################################################
$str .= $this->SUPER::debug_string
();
###############################################################################
###############################################################################
package Midas
::Source
::Library
;
use Midas
::Preprocess
':all';
use base
'Midas::Source';
###############################################################################
my $this = fields
::new
($class);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
###############################################################################
$this->SUPER::set_defaults
();
###############################################################################
###############################################################################
return get_includes
($CONFIG{link_paths
});
###############################################################################
$str .= $this->SUPER::debug_string
();
###############################################################################
return 1; # libraries need to link after everything else
###############################################################################
###############################################################################