2017-05-07 15:25:26 -06:00
|
|
|
#! /usr/bin/env perl
|
2005-04-16 16:20:36 -06:00
|
|
|
#
|
2006-07-03 15:30:54 -06:00
|
|
|
# checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION
|
|
|
|
# without including <linux/version.h>, or cases of
|
2005-04-16 16:20:36 -06:00
|
|
|
# including <linux/version.h> that don't need it.
|
2006-01-03 05:37:51 -07:00
|
|
|
# Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-22 16:17:14 -07:00
|
|
|
use strict;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
$| = 1;
|
|
|
|
|
2010-02-22 16:17:14 -07:00
|
|
|
my $debugging;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-22 16:17:14 -07:00
|
|
|
foreach my $file (@ARGV) {
|
2011-04-26 17:07:56 -06:00
|
|
|
next if $file =~ "include/linux/version\.h";
|
2005-04-16 16:20:36 -06:00
|
|
|
# Open this file.
|
2010-02-22 16:17:14 -07:00
|
|
|
open( my $f, '<', $file )
|
|
|
|
or die "Can't open $file: $!\n";
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
# Initialize variables.
|
2010-02-22 16:17:14 -07:00
|
|
|
my ($fInComment, $fInString, $fUseVersion);
|
2005-04-16 16:20:36 -06:00
|
|
|
my $iLinuxVersion = 0;
|
|
|
|
|
2010-02-22 16:17:14 -07:00
|
|
|
while (<$f>) {
|
2005-04-16 16:20:36 -06: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 15:30:54 -06:00
|
|
|
if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
$fUseVersion = 1;
|
2010-02-22 16:17:14 -07:00
|
|
|
last if $iLinuxVersion;
|
|
|
|
}
|
2005-04-16 16:20:36 -06: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 16:17:14 -07:00
|
|
|
close($f);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|