forked from dtrace4linux/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_kernels.pl
More file actions
executable file
·187 lines (153 loc) · 4.26 KB
/
make_kernels.pl
File metadata and controls
executable file
·187 lines (153 loc) · 4.26 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! /usr/bin/perl
# $Header:$
# Script to compile dtrace against kernels on the system.
use strict;
use warnings;
use File::Basename;
use FileHandle;
use Getopt::Long;
use IO::File;
use POSIX;
use Cwd;
my $modpost;
my $asmlnk;
my $warn_app = "";
#######################################################################
# Command line switches. #
#######################################################################
my %opts;
my $ctrl_c;
sub int_handler
{
print "Ctrl-C typed..aborting\n";
$ctrl_c = 1;
}
sub main
{
Getopt::Long::Configure('no_ignore_case');
usage() unless GetOptions(\%opts,
'help',
'no32',
'no64',
'path=s',
'v',
);
usage() if ($opts{help});
$ENV{TOPDIR} = Cwd::cwd();
###############################################
# Dont do a bug.sh when things fail. #
###############################################
$ENV{MAKE_KERNELS} = 1;
my $kernel = $ARGV[0];
$kernel = $ENV{KERNEL} if !$kernel;
$warn_app = "warn" if -f "$ENV{HOME}/bin/warn";
my $uname = `uname -m`;
chomp($uname);
$SIG{INT} = \&int_handler;
###############################################
# Iterate thru the available kernels. #
###############################################
$opts{path} = "/lib/modules/[23]*" if !defined($opts{path});
for my $f (glob($opts{path})) {
exit(1) if $ctrl_c;
my $dir = basename($f);
next if $kernel && $dir ne $kernel;
print "======= Building: $f ===============================\n";
$ENV{BUILD_KERNEL} = $dir;
if (!$opts{no64} && system("$warn_app make all")) {
exit(1);
}
exit(1) if $ctrl_c;
if (!$opts{no32} && $uname eq "x86_64") {
build_i386($f);
}
}
}
sub build_i386
{ my $f = shift;
my $dir = basename($f);
print "======= Building: $f (i386) =================\n";
###############################################
# Redirect the include/asm symlink so its #
# fine with us, but we need to be careful #
# to put it back, even on a ^C. #
###############################################
if (-d "$f/build/include/asm-i386") {
$asmlnk = readlink("$f/build/include/asm");
print "$f/build/include/asm -> $asmlnk\n";
if (!rename("$f/build/include/asm", "$f/build/include/asm.sav")) {
print "Error on rename: $f/build/include/asm - $!\n";
exit(1);
}
if (!symlink("asm-i386", "$f/build/include/asm")) {
print "symlink i386 -> $f/build/include/asm - error $!\n";
exit(1);
}
}
###############################################
# Replace scripts/mod/modpost because it #
# wont know what to do. #
###############################################
$modpost = "$f/build/scripts/mod/modpost";
if (!rename($modpost, "$modpost.sav")) {
print "Error rename: $modpost -- $!\n";
}
my $fh = new FileHandle(">$modpost");
if (!defined($fh)) {
print "ERROR: Cannot open $modpost - $!\n";
exit(1);
}
print $fh "touch $ENV{TOPDIR}/build/driver/dtracedrv.mod.c\n";
print $fh "exit 0\n";
$fh->close();
chmod(0755, $modpost);
$ENV{BUILD_KERNEL} = "$dir-i386";
$ENV{BUILD_ARCH} = "i386";
$ENV{BUILD_i386} = "1";
$ENV{BUILD_BITS} = "-m32";
my $ret = system("$warn_app make " . ($opts{v} ? "V=1" : "") . " all");
restore_asmlnk($f);
exit(1) if $ret;
$modpost = "";
delete($ENV{BUILD_ARCH});
delete($ENV{BUILD_BITS});
delete($ENV{BUILD_i386});
delete($ENV{BUILD_KERNEL});
}
sub restore_asmlnk
{ my $f = shift;
if ($asmlnk) {
unlink("$f/build/include/asm");
if (!rename("$f/build/include/asm.sav", "$f/build/include/asm")) {
print "Cannot restore $f/build/include/asm -- $!\n";
exit(1);
}
}
if ($modpost) {
unlink($modpost);
if (!rename("$modpost.sav", $modpost)) {
print "Error - cannot restore $modpost - $!\n";
}
}
}
#######################################################################
# Print out command line usage. #
#######################################################################
sub usage
{
print <<EOF;
make_kernels.pl -- tool to build against non-native kernels
Usage:
Simple script designed to allow cross compile/verification against
any other kernels on your system
Switches:
-path <dir> Use path to specifiy what to build.
-no32 Dont build i386 kernels
-no64 Dont build x86-64 kernels.
Example:
\$ tools/make_kernels.pl -path ~/linux/linux-2.6.18.8
EOF
exit(1);
}
main();
0;