Blame view

scripts/checkversion.pl 1.9 KB
cb77f0d62   Kamil Rytarowski   scripts: Switch t...
1
  #! /usr/bin/env perl
b24413180   Greg Kroah-Hartman   License cleanup: ...
2
  # SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
  #
63104eec2   Sam Ravnborg   kbuild: introduce...
4
5
  # checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION
  # without including <linux/version.h>, or cases of
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
  # including <linux/version.h> that don't need it.
f4b09ebc8   Adrian Bunk   update the email ...
7
  # Copyright (C) 2003, Randy Dunlap <rdunlap@xenotime.net>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8

a208868fc   Stephen Hemminger   checkversion: per...
9
  use strict;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  $| = 1;
a208868fc   Stephen Hemminger   checkversion: per...
11
  my $debugging;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12

a208868fc   Stephen Hemminger   checkversion: per...
13
  foreach my $file (@ARGV) {
6088e9ffa   Peter Foley   kbuild: don't war...
14
      next if $file =~ "include/linux/version\.h";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
      # Open this file.
a208868fc   Stephen Hemminger   checkversion: per...
16
17
18
      open( my $f, '<', $file )
        or die "Can't open $file: $!
  ";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
  
      # Initialize variables.
a208868fc   Stephen Hemminger   checkversion: per...
21
      my ($fInComment, $fInString, $fUseVersion);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
      my $iLinuxVersion = 0;
a208868fc   Stephen Hemminger   checkversion: per...
23
      while (<$f>) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  	# 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
63104eec2   Sam Ravnborg   kbuild: introduce...
43
  	if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  	    $fUseVersion = 1;
a208868fc   Stephen Hemminger   checkversion: per...
45
46
              last if $iLinuxVersion;
          }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
      }
  
      # Report used version IDs without include?
      if ($fUseVersion && ! $iLinuxVersion) {
  	print "$file: $.: need linux/version.h
  ";
      }
  
      # Report superfluous includes.
      if ($iLinuxVersion && ! $fUseVersion) {
  	print "$file: $iLinuxVersion linux/version.h not needed.
  ";
      }
  
      # debug: report OK results:
      if ($debugging) {
          if ($iLinuxVersion && $fUseVersion) {
  	    print "$file: version use is OK ($iLinuxVersion)
  ";
          }
          if (! $iLinuxVersion && ! $fUseVersion) {
  	    print "$file: version use is OK (none)
  ";
          }
      }
a208868fc   Stephen Hemminger   checkversion: per...
72
      close($f);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  }