2005-04-16 22:20:36 +00:00
|
|
|
#! /usr/bin/perl
|
|
|
|
#
|
2006-07-03 21:30:54 +00:00
|
|
|
# checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION
|
|
|
|
# without including <linux/version.h>, or cases of
|
2005-04-16 22:20:36 +00:00
|
|
|
# including <linux/version.h> that don't need it.
|
2006-01-03 12:37:51 +00:00
|
|
|
# Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-02-22 23:17:14 +00:00
|
|
|
use strict;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
$| = 1;
|
|
|
|
|
2010-02-22 23:17:14 +00:00
|
|
|
my $debugging;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-02-22 23:17:14 +00:00
|
|
|
foreach my $file (@ARGV) {
|
2011-04-26 23:07:56 +00:00
|
|
|
next if $file =~ "include/linux/version\.h";
|
2005-04-16 22:20:36 +00:00
|
|
|
# Open this file.
|
2010-02-22 23:17:14 +00:00
|
|
|
open( my $f, '<', $file )
|
|
|
|
or die "Can't open $file: $!\n";
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
# Initialize variables.
|
2010-02-22 23:17:14 +00:00
|
|
|
my ($fInComment, $fInString, $fUseVersion);
|
2005-04-16 22:20:36 +00:00
|
|
|
my $iLinuxVersion = 0;
|
|
|
|
|
2010-02-22 23:17:14 +00:00
|
|
|
while (<$f>) {
|
2005-04-16 22:20:36 +00:00
|
|
|
# Strip comments.
|
|
|
|
$fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
|
|
|
|
m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
|
|
|
|
|
|
|
|
# Pick up definitions.
|
|
|
|
if ( m/^\s*#/o ) {
|
|
|
|
$iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Strip strings.
|
|
|
|
$fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
|
|
|
|
m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
|
|
|
|
|
|
|
|
# Pick up definitions.
|
|
|
|
if ( m/^\s*#/o ) {
|
|
|
|
$iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE
|
2006-07-03 21:30:54 +00:00
|
|
|
if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
$fUseVersion = 1;
|
2010-02-22 23:17:14 +00:00
|
|
|
last if $iLinuxVersion;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Report used version IDs without include?
|
|
|
|
if ($fUseVersion && ! $iLinuxVersion) {
|
|
|
|
print "$file: $.: need linux/version.h\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Report superfluous includes.
|
|
|
|
if ($iLinuxVersion && ! $fUseVersion) {
|
|
|
|
print "$file: $iLinuxVersion linux/version.h not needed.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# debug: report OK results:
|
|
|
|
if ($debugging) {
|
|
|
|
if ($iLinuxVersion && $fUseVersion) {
|
|
|
|
print "$file: version use is OK ($iLinuxVersion)\n";
|
|
|
|
}
|
|
|
|
if (! $iLinuxVersion && ! $fUseVersion) {
|
|
|
|
print "$file: version use is OK (none)\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-22 23:17:14 +00:00
|
|
|
close($f);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|