Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6/mini2440.git] / scripts / checkversion.pl
blobdf10db662eb1d510c7811c8d31c29d398ca8da9c
1 #! /usr/bin/perl
3 # checkversion find uses of LINUX_VERSION_CODE, KERNEL_VERSION, or
4 # UTS_RELEASE without including <linux/version.h>, or cases of
5 # including <linux/version.h> that don't need it.
6 # Copyright (C) 2003, Randy Dunlap <rddunlap@osdl.org>
8 $| = 1;
10 my $debugging = 0;
12 foreach $file (@ARGV)
14 # Open this file.
15 open(FILE, $file) || die "Can't open $file: $!\n";
17 # Initialize variables.
18 my $fInComment = 0;
19 my $fInString = 0;
20 my $fUseVersion = 0;
21 my $iLinuxVersion = 0;
23 LINE: while ( <FILE> )
25 # Strip comments.
26 $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
27 m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
29 # Pick up definitions.
30 if ( m/^\s*#/o ) {
31 $iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
34 # Strip strings.
35 $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
36 m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
38 # Pick up definitions.
39 if ( m/^\s*#/o ) {
40 $iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
43 # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE
44 if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/) ||
45 ($_ =~ /UTS_RELEASE/)) {
46 $fUseVersion = 1;
47 last LINE if $iLinuxVersion;
51 # Report used version IDs without include?
52 if ($fUseVersion && ! $iLinuxVersion) {
53 print "$file: $.: need linux/version.h\n";
56 # Report superfluous includes.
57 if ($iLinuxVersion && ! $fUseVersion) {
58 print "$file: $iLinuxVersion linux/version.h not needed.\n";
61 # debug: report OK results:
62 if ($debugging) {
63 if ($iLinuxVersion && $fUseVersion) {
64 print "$file: version use is OK ($iLinuxVersion)\n";
66 if (! $iLinuxVersion && ! $fUseVersion) {
67 print "$file: version use is OK (none)\n";
71 close(FILE);