1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
sub load_module {
my ($modname,$cc,$os,$arch,$sub,%module) = @_;
# Check to see if everything is OK WRT system requirements
if(defined($module{'os'}) and !exists($module{'os'}{$os}) and
$os ne 'generic')
{ die "(error): Module '$modname' does not run on $REALNAME{$os}\n"; }
if(defined($module{'arch'}) and $arch ne 'generic' and
!exists($module{'arch'}{$arch}) and !exists($module{'arch'}{$sub}))
{ die "(error): Module '$modname' does not run on ".
"$REALNAME{$arch}/$sub\n"; }
if(defined($module{'cc'}) and !exists($module{'cc'}{$cc}))
{
die "(error): Module '$modname' does not work with $REALNAME{$cc}\n";
}
handle_files($modname, $module{'replace'}, \&replace_file);
handle_files($modname, $module{'ignore'}, \&ignore_file);
handle_files($modname, $module{'add'}, \&add_file);
if(defined($module{'notes'}))
{
my $realname = $module{'name'};
my $note = $module{'notes'};
print STDERR "(note): $modname (\"$realname\"): $note\n";
}
}
sub handle_files {
my($modname, $hash_scalar, $func) = @_;
return unless defined($hash_scalar);
my %hash = %{ $hash_scalar };
foreach (sort keys %hash) {
if(defined($hash{$_})) { &$func($modname, $_, $hash{$_}); }
else { &$func($modname, $_); }
}
}
sub full_path {
my ($file,$modname) = @_;
if(defined($modname))
{ return catfile ($MOD_DIR, $modname, $file); }
else {
if($file =~ /\.h$/)
{ return catfile ($INCLUDE_DIR, $file); }
elsif($file =~ /\.cpp$/ or $file =~ /\.s$/ or $file =~ /\.S$/)
{ return catfile ($SRC_DIR, $file); }
else { die "(internal error): Not sure where to put $file\n"; }
}
}
sub add_file {
my ($modname,$file) = @_;
check_for_file(full_path($file, $modname), $modname);
if($file =~ /\.cpp$/ or $file =~ /\.s$/ or $file =~ /\.S$/)
{ $added_src{$file} = catdir($MOD_DIR, $modname); }
elsif($file =~ /\.h$/)
{ $added_include{$file} = catdir($MOD_DIR, $modname); }
else { die "Not sure where to put $file\n"; }
}
sub ignore_file {
my ($modname,$file) = @_;
check_for_file(full_path($file), $modname);
if($file =~ /\.cpp$/ or $file =~ /\.s$/ or $file =~ /\.S$/)
{ $ignored_src{$file} = 1; }
elsif($file =~ /\.h$/) { $ignored_include{$file} = 1; }
else { die "Not sure where to put $file\n"; }
}
# This works because ignore file always runs on files in the main source tree,
# and add always works on the file in the modules directory.
sub replace_file {
my ($modname,$file) = @_;
ignore_file($modname, $file);
add_file($modname, $file);
}
|