Addition to the configure script
Hello,
today while I was in #linux-cluster I found that the configure script doesn't check for the kernel version.
I wrote a little function which checks the kernel version and returns 0 or 1.
Here is the code:
sub kernel_version {
? my $makefile = shift;
? my $build_version_min = shift;
? my $build_patchlevel_min = shift;
? my $build_sublevel_min = shift;
? my $build_version_max = shift;
? my $build_patchlevel_max = shift;
? my $build_sublevel_max = shift;
? # add the Makefile to the path
? $makefile .= 'Makefile';
? my $version=0;
? my $patchlevel=0;
? my $sublevel=0;
? if ( -f $makefile ) {
? ? # open the Makefile to feth VERSION, PATCHLEVEL and SUBLEVEL, if needed I can add EXTRAVERSION too
? ? open MAKEFILE, '<', $makefile;
? ? while (<MAKEFILE>) {
? ? ? if ($_ =~ /^VERSION/) {
? ? ? ? $version = $_;
? ? ? }
? ? ? if ($_ =~ /^PATCHLEVEL/) {
? ? ? ? $patchlevel = $_;
? ? ? }
? ? ? if ($_ =~ /^SUBLEVEL/) {
? ? ? ? $sublevel = $_;
? ? ? ? # we don't need to check any thing else in this file so we are stopping the read
? ? ? ? last;
? ? ? }
? ? }
? ? close MAKEFILE;
? ? # leaving only the numbers from the lines
? ? # this is faster then split and doesn't alocate useless arrays ? ? $version =~ s/.*\s([0-9]+)[\n|\r]/$1/;
? ? $patchlevel =~ s/.*\s([0-9]+)[\n|\r]/$1/;
? ? $sublevel =~ s/.*\s([0-9]+)[\n|\r]/$1/;
? ? # checking VERSION, PATCHLEVEL and SUBLEVEL for a kernel
? ? # if needed I can add also EXTRAVERSION to the check
? ? if ($version >= $build_version_min &&
? ? ? ? $version <= $build_version_max &&
? ? ? ? $patchlevel >= $build_patchlevel_min &&
? ? ? ? $patchlevel <= $build_patchlevel_max &&
? ? ? ? $sublevel >= $build_sublevel_min &&
? ? ? ? $sublevel <= $build_sublevel_max) {
? ? ? print 'Current kernel version is OK',"\n";
? ? ? return 1;
? ? } else {
? ? ? print 'Current kernel version: ',$version.'.'.$patchlevel.'.'. $sublevel,"\nMinimum version: ".$build_version_min.'.'. $build_patchlevel_min.'.'.$build_sublevel_min,"\nMaximum version: ". $build_version_max.'.'.$build_patchlevel_max.'.'.$build_sublevel_max,"\n"; ? ? ? return 0;
? ? }
? } else {
? ? print "Unable to find kernel Makefile!\n";
? ? return 0;
? }
}
# the options to this function are:
# ? source path
# ? minimum kernel version
# ? minimum kernel patchlevel
# ? minimum kernel sublevel
# ? maximum kernel version
# ? maximum kernel patchlevel
# ? maximum kernel sublevel
kernel_version('/usr/src/linux/',2,6,24,2,6,25);The function can be used to check the makefile from $kernel_build or $kernel_src.
I hope that this will be useful to you guys.
Best regards
? Marian Marinov