-
Notifications
You must be signed in to change notification settings - Fork 1
/
kernel_build_modules_store
executable file
·151 lines (115 loc) · 2.9 KB
/
kernel_build_modules_store
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl
## hyphop ##
our $PWD = $ENV{PWD};
our $VAR = {};
env::load(',config' => $VAR);
-d $_ or `mkdir -p "$_"` for (
$VAR->{mod_out},
$VAR->{mod_out_links}
);
our ( $modname, $rmod, $mod );
open MODULES, ">$VAR->{kernel_out}/modules.list";
open MODNAME, ">$VAR->{kernel_out}/modnames.list";
open MODDEP, ">$VAR->{kernel_out}/modules.dep";
open MODORD, ">$VAR->{kernel_out}/modules.order";
open MODBIN, ">$VAR->{kernel_out}/modules.builtin";
our @MODULES;
our @MODNAMES;
our ($dep_file) = glob "$VAR->{mod_rpath}/lib/modules/*/modules.dep";
open D, $dep_file;
our ($order_file) = glob "$VAR->{mod_rpath}/lib/modules/*/modules.order";
open O, $order_file;
our ($buildin_file) = glob "$VAR->{mod_rpath}/lib/modules/*/modules.builtin";
open B, $buildin_file;
while (<D>) {
s{\S+/}{}sg;
#warn $_;
print MODDEP $_;
}
while (<O>) {
s{\S+/}{}sg;
#warn $_;
print MODORD $_;
}
while (<B>) {
s{\S+/}{}sg;
#warn $_;
print MODBIN $_;
}
#exit;
#while (<STDIN>) {
for ( split /\n/ => `find $VAR->{mod_rpath} -name \*.ko` ) {
# chomp;
$modname = $rmod = $mod = $_;
$rmod =~ s{$PWD/}{};
$modname =~ s{.+/}{};
# warn "$rmod => $mod_out/$modname";
my $l1 = "$VAR->{mod_out}/$modname";
my $l2 = "$VAR->{mod_out_links}/$modname";
# warn $l1 if -f $l1;
# warn $l2 if -f $l2;
my $npath = $rmod;
$npath =~ s{^$VAR->{kernel_out}/}{};
push @MODULES, $npath;
push @MODNAMES, $modname;
$npath = "../$npath";
unlink $l1 if -f $l1;
unlink $l2 if -f $l2;
link $mod, $l1 or
warn "[e] link $mod, $l1\n" and
exit 0;
symlink $npath, $l2 or
warn "[e] symlink $mod, $l2\n" and
exit 0;
}
print MODULES join "\n" => sort @MODULES;
print MODNAME join "\n" => sort @MODNAMES;
package env;
#~ sub import {
#~ my $pkg = caller;
#~ my $n = shift;
#~ my $to = pop;
#~ $to // $pkg::ENV //= {};
#~ for (@_) {
#~ load( $_, $pkg::ENV );
#~ }
#~ return;
#~ }
sub load {
my $in = shift;
my $c = shift;
my $CFG;
$in =~ /([^\/]+)$/;
my $dir = $`;
unless ( $r = open $CFG, $in ) {
# warn "[w] load config $! $in $\n";
warn "[w] not load config $dir / $in\n";
return undef;
}
local $_;
my $found = 0;
while ( $_ = <$CFG> ) {
load( "$dir$1",$c ) if /^\#include\s+(.+)\n/;
next if /^\s*\#/;
if (/^\s*(export)?\s*(\w+)\s*\=?\s*/) {
my $n = $2;
my $v = $';
$v =~ s/^(\"|\')//;
my $q = $1;
$v =~ s/\s+$//;
$v =~ s/$q$//;
$v =~ s/\$\{(\w+)\}/$c->{$1}/eg;
$v =~ s/\$(\w+)/$c->{$1}/eg;
if ( $v eq '' ) {
next;
}
$v =~ s/\\n/\n/sg;
$found++;
# warn "[$n = $v]\n";
$c->{$n} = $v;
}
}
close $CFG;
return $found;
}
1;