package Midas
::Application
;
use Midas
::Preprocess
':all';
use fields
qw(name filetag sections srcfile srcline args
is_linked external_path goldfinger_cmds
##############################################################################
$this = fields
::new
($this);
foreach my $key (keys %args) {
$this->{$key} = $args{$key};
$this->parse_args() if defined $this->{args
};
##############################################################################
$this->{sections
} = [] unless defined $this->{sections
};
$this->{goldfinger_cmds
} = [] unless defined $this->{goldfinger_cmds
};
##############################################################################
##############################################################################
my $args = $this->{args
};
my @args = split /,/, $args;
foreach my $arg (@args) {
if($args =~ /FILE\=(\S+)/i) {
$this->{external_path
} = $1;
$this->copy_external_to_build_dir();
##############################################################################
return 0 if @
{$this->{sections
}};
return 0 if $this->{is_linked
};
##############################################################################
sub copy_external_to_build_dir
{
my @search = get_includes
($CONFIG{link_paths
});
my $local_exe = path_to_build_file
($this->exe_name(), $STATE);
foreach my $testdir (@search) {
my $testfile = File
::Spec
->catfile($testdir, $this->{external_path
});
chat
"Copying $testfile to $local_exe\n";
copy
($testfile, $local_exe);
fatal
"Couldn't find \"$this->{external_path}\" in search path: @search\n",
##############################################################################
return '' if($this->name() eq 'default');
my $tag = lc $this->{name
};
##############################################################################
return $this->{is_linked
};
##############################################################################
return $this->expand_file($CONFIG{local_exe
});
##############################################################################
return $this->expand_file($CONFIG{local_ldscr
});
##############################################################################
my $name = $this->{name
};
my $filetag = $this->filetag();
$filetag = '.' . $filetag unless ($filetag =~ /^\./ or $filetag eq '');
$file =~ s/\*/${filetag}/;
##############################################################################
my $appname = $this->{name
};
my $secname = $section->{name
};
my $srcfile = $section->{srcfile
};
my $srcline = $section->{srcline
};
fatal
"Application $appname cannot contain SECTIONs\n" .
"($secname at file=$srcfile, line=$srcline\n", M_SECSYNTAX
;
push @
{$this->{sections
}}, $section;
##############################################################################
push @
{$this->{goldfinger_cmds
}}, $cmdstring;
##############################################################################
return @
{ $this->{sections
} };
##############################################################################
sub write_to_goldfinger
{
my $app_name = $this->name();
my $exe_name = $this->exe_name();
my $exe = path_to_build_file
($exe_name, $STATE);
my $srcfile = $this->{srcfile
};
my $srcline = $this->{srcline
};
print $fh "APP $app_name\n";
print $fh " ELF_FILE = \"$exe\";\n";
print $fh " SRC_FILE = \"$srcfile\";\n" if defined $srcfile;
print $fh " SRC_LINE = $srcline;\n" if defined $srcline;
my @sections = $this->get_sec_list();
foreach my $section (@sections) {
foreach my $seg (Midas
::Segment
->all_names()) {
my @attrs = $section->get_segment_attrs($seg);
my $linkname = $section->get_segment_link_name($seg);
foreach my $attr (@attrs) {
$attr->write_to_goldfinger($seg, $linkname, $fh);
foreach my $cmd (@
{$this->{goldfinger_cmds
}}) {
##############################################################################
chat
"App: $this->{name}\n", 3;
foreach my $sec (@
{$this->{sections
}}) {
$str .= " Section: \"$sec->{name}\" ";
my @link_attrs = $sec->get_link_attrs();
foreach my $seg (Midas
::Segment
->all_names()) {
my $va = $link_attrs[0]->get_segment_va($seg);
$str .= "${seg}_va=$va " if defined $va;
chat
"$str\n", 3 if $str =~ /\S/;
##############################################################################