Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / scripts / checkversion.pl
blob94cd49eff6054fe3190fc7665c47df9dac9d6abb
1 #! /usr/bin/env perl
2 # SPDX-License-Identifier: GPL-2.0
4 # checkversion finds uses of all macros in <linux/version.h>
5 # where the source files do not #include <linux/version.h>; or cases
6 # of including <linux/version.h> where it is not needed.
7 # Copyright (C) 2003, Randy Dunlap <rdunlap@infradead.org>
9 use strict;
11 $| = 1;
13 my $debugging;
15 foreach my $file (@ARGV) {
16 next if $file =~ "include/generated/uapi/linux/version\.h";
17 next if $file =~ "usr/include/linux/version\.h";
18 # Open this file.
19 open( my $f, '<', $file )
20 or die "Can't open $file: $!\n";
22 # Initialize variables.
23 my ($fInComment, $fInString, $fUseVersion);
24 my $iLinuxVersion = 0;
26 while (<$f>) {
27 # Strip comments.
28 $fInComment && (s+^.*?\*/+ +o ? ($fInComment = 0) : next);
29 m+/\*+o && (s+/\*.*?\*/+ +go, (s+/\*.*$+ +o && ($fInComment = 1)));
31 # Pick up definitions.
32 if ( m/^\s*#/o ) {
33 $iLinuxVersion = $. if m/^\s*#\s*include\s*"linux\/version\.h"/o;
36 # Strip strings.
37 $fInString && (s+^.*?"+ +o ? ($fInString = 0) : next);
38 m+"+o && (s+".*?"+ +go, (s+".*$+ +o && ($fInString = 1)));
40 # Pick up definitions.
41 if ( m/^\s*#/o ) {
42 $iLinuxVersion = $. if m/^\s*#\s*include\s*<linux\/version\.h>/o;
45 # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION,
46 # LINUX_VERSION_MAJOR, LINUX_VERSION_PATCHLEVEL, LINUX_VERSION_SUBLEVEL
47 if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/) ||
48 ($_ =~ /LINUX_VERSION_MAJOR/) || ($_ =~ /LINUX_VERSION_PATCHLEVEL/) ||
49 ($_ =~ /LINUX_VERSION_SUBLEVEL/)) {
50 $fUseVersion = 1;
51 last if $iLinuxVersion;
55 # Report used version IDs without include?
56 if ($fUseVersion && ! $iLinuxVersion) {
57 print "$file: $.: need linux/version.h\n";
60 # Report superfluous includes.
61 if ($iLinuxVersion && ! $fUseVersion) {
62 print "$file: $iLinuxVersion linux/version.h not needed.\n";
65 # debug: report OK results:
66 if ($debugging) {
67 if ($iLinuxVersion && $fUseVersion) {
68 print "$file: version use is OK ($iLinuxVersion)\n";
70 if (! $iLinuxVersion && ! $fUseVersion) {
71 print "$file: version use is OK (none)\n";
75 close($f);