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